taskrambler  v0.1.8
Web server and task management solution.
utils/http.h File Reference
#include <time.h>
#include <sys/types.h>
#include "http/message.h"
+ Include dependency graph for utils/http.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

size_t rfc1123Gmt (char *, size_t, const time_t *)
 
size_t rfc1123GmtNow (char *, size_t)
 
size_t urldecode (char *, size_t)
 
char isHttpVersion (const char *, size_t)
 
HttpMessage httpGetMessage (const char *, size_t, const char *, size_t, const char *, size_t)
 

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 utils/http.h.

Function Documentation

HttpMessage httpGetMessage ( const char *  ,
size_t  ,
const char *  ,
size_t  ,
const char *  ,
size_t   
)

Definition at line 127 of file utils/http.c.

References isHttpVersion().

Referenced by httpParserNewMessage().

131 {
132  if (isHttpVersion(part1, len1)) {
133  return new(HttpResponse,
134  part1, len1,
135  strtoul(part2, NULL, 10),
136  part3, len3);
137  }
138 
139  if (isHttpVersion(part3, len3)) {
140  return new(HttpRequest,
141  part1, len1,
142  part2, len2,
143  part3, len3);
144  }
145 
146  return NULL;
147 }
char isHttpVersion(const char *str, size_t len)
Definition: utils/http.c:112

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

char isHttpVersion ( const char *  ,
size_t   
)

Definition at line 112 of file utils/http.c.

References FALSE, and TRUE.

Referenced by httpGetMessage(), and httpMessageHasValidVersion().

113 {
114  if (NULL == str)
115  return FALSE;
116 
117  if (8 > len)
118  return FALSE;
119 
120  if (0 != memcmp("HTTP/", str, sizeof("HTTP/")-1))
121  return FALSE;
122 
123  return TRUE;
124 }
#define FALSE
Definition: commons.h:28
#define TRUE
Definition: commons.h:27

+ Here is the caller graph for this function:

size_t rfc1123Gmt ( char *  ,
size_t  ,
const time_t *   
)

Definition at line 53 of file utils/http.c.

References DAY_NAMES, and MONTH_NAMES.

Referenced by assetCtor(), httpResponseAsset(), and rfc1123GmtNow().

54 {
55  struct tm * tmp = gmtime(t);
56  size_t nbuf;
57 
58  nbuf = strftime(buffer, _nbuf, "---, %d --- %Y %T GMT", tmp);
59  memcpy(buffer, DAY_NAMES[tmp->tm_wday], 3);
60  memcpy(buffer+8, MONTH_NAMES[tmp->tm_mon], 3);
61 
62  return nbuf;
63 }
static const char * MONTH_NAMES[]
Definition: utils/http.c:44
static const char * DAY_NAMES[]
Definition: utils/http.c:42

+ Here is the caller graph for this function:

size_t rfc1123GmtNow ( char *  ,
size_t   
)

Definition at line 69 of file utils/http.c.

References rfc1123Gmt().

Referenced by httpWorkerAddCommonHeader().

70 {
71  time_t t = time(NULL);
72 
73  return rfc1123Gmt(buffer, _nbuf, &t);
74 }
size_t rfc1123Gmt(char *buffer, size_t _nbuf, const time_t *t)
Definition: utils/http.c:53

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t urldecode ( char *  buffer,
size_t  nbuffer 
)

Decode an url encoded string. This expects a valid url encoded string and it size as arguments, else the behaviour of this function is undefined. This function modifies the data in buffer. No copy is made. The reason for this is only performance.

Definition at line 84 of file utils/http.c.

References ALNUMVAL.

Referenced by httpParserPostVars().

85 {
86  char * buf_ptr = buffer;
87  char * res_ptr = buffer;
88 
89  for(; 0 < nbuffer; nbuffer--, buf_ptr++, res_ptr++) {
90  switch(*buf_ptr) {
91  case '%':
92  *res_ptr = (ALNUMVAL(buf_ptr[1]) << 4) | ALNUMVAL(buf_ptr[2]);
93  buf_ptr += 2;
94  nbuffer -= 2;
95  break;
96 
97  case '+':
98  *buf_ptr = ' ';
99  /* intended drop through */
100 
101  default:
102  *res_ptr = *buf_ptr;
103  break;
104  }
105  }
106  *res_ptr = 0;
107 
108  return res_ptr - buffer;
109 }
#define ALNUMVAL(x)
Definition: utils/http.c:39

+ Here is the caller graph for this function: