taskrambler  0.1.9
Web server and task management solution.
p_header.c File Reference
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "class.h"
#include "http/header.h"
#include "http/parser.h"
#include "http/message.h"
#include "http/request.h"
#include "hash.h"
#include "utils/memory.h"
+ Include dependency graph for p_header.c:

Go to the source code of this file.

Functions

void httpParserHeader (HttpParser this, const char *line, const char *lend)
 

Detailed Description

Author
Georg Hopp

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file p_header.c.

Function Documentation

void httpParserHeader ( HttpParser  this,
const char *  line,
const char *  lend 
)

Definition at line 37 of file p_header.c.

References hashAdd(), memMalloc(), and interface::name.

Referenced by httpParserParse().

41 {
42  const char * name = line;
43  char * value = memchr(line, ':', lend - line);
44  size_t nname = (value++) - name;
45  HttpMessage current = this->current;
46 
47  if (NULL == value) {
48  return;
49  }
50 
51  for (; *value == ' ' && value < lend; value++);
52 
53  if (value == lend) {
54  return;
55  }
56 
57  if (0 == strncasecmp("content-length", name, nname-1)) {
58  current->nbody = strtoul(value, NULL, 10);
59  if (0 < this->current->nbody) {
60  current->body = memMalloc(current->nbody);
61  }
62  current->dbody = 0;
63  }
64 
65  if (0 == strncasecmp("cookie", name, nname-1)) {
66  HttpRequest request = (HttpRequest)this->current;
67  char * pair = value;
68  ssize_t togo = lend - value;
69 
70  while(NULL != pair && 0 < togo) {
71  char * key = pair;
72  char * eqsign;
73  char * val;
74  size_t nval;
75 
76  for (; *key == ' ' && key < lend; key++, togo--);
77  eqsign = memchr(key, '=', togo);
78 
79  if (NULL == eqsign) {
80  break;
81  }
82 
83  togo -= (eqsign - key);
84  pair = memchr(eqsign, ';', togo);
85 
86  if (NULL == pair) {
87  pair = (char *)lend;
88  }
89 
90  nval = pair-eqsign-1;
91  val = (0 != nval)? eqsign+1 : NULL;
92 
93  hashAdd(request->cookies,
94  new(HashValue, key, eqsign-key, val, nval));
95 
96  pair++;
97  togo -= (pair - eqsign);
98  }
99  }
100 
101  hashAdd(current->header,
102  new(HttpHeader, name, nname, value, lend - value));
103 }
void * memMalloc(size_t)
Definition: memory.c:783
void * hashAdd(Hash, void *)
Definition: add.c:48

+ Here is the call graph for this function:

+ Here is the caller graph for this function: