63 if (
NULL==(retval=malloc(
sizeof(
struct HTTP_s)))) {
69 perror(
"HTTP_new headers initialization");
76 if (
NULL==(retval->
body=malloc(1))) {
77 perror(
"HTTP_new empty body allocation");
93 perror(
"HTTP_addheader");
97 perror(
"HTTP_addheader name malloc");
101 if (
NULL==(headers->
value=malloc(strlen(value)+1))) {
102 perror(
"HTTP_addheader value malloc");
105 strcpy(headers->
value,value);
118 if (
NULL==(retval=malloc(1))) {
119 perror(
"HTTP_getheaders initial malloc");
123 for (headers=http->
headers; headers; headers=headers->
next) {
126 if (
NULL==(newretval=realloc(retval,strlen(retval)+strlen(headers->
name)+2+strlen(headers->
value)+2+1))) {
127 perror(
"HTTP_getheaders inner loop");
131 strcat(retval,headers->
name);
133 strcat(retval,headers->
value);
134 strcat(retval,
"\r\n");
148 if (headers_it->
name)
149 free(headers_it->
name);
150 if (headers_it->
value)
151 free(headers_it->
value);
164 if (
NULL==(retval=malloc(7+1+strlen(uri)+1+8+1))) {
165 perror(
"HTTP_getrequest");
172 strcat(retval,
"GET");
184 fprintf(stderr,
"HTTP method not supported\n");
194 strcat(retval,
" HTTP/");
198 strcat(retval,
"1.1");
206 fprintf(stderr,
"HTTP version not supported\n");
210 strcat(retval,
"\r\n");
220 if (
NULL==(newbody=realloc(http->
body,strlen(body)+1))) {
221 perror(
"HTTP_setbody");
225 http->
body = newbody;
226 strcpy(http->
body, body);
enum HTTPVersion_e HTTPVersion_t
void HTTP_del(HTTP_t *http)
void HTTP_addheader(HTTP_t *http, const char *name, const char *value)
enum HTTPMethod_e HTTPMethod_t
struct HTTPHeaders_s HTTPHeaders_t
char * HTTP_getheaders(const HTTP_t *http)
void HTTP_setbody(HTTP_t *http, const char *body)
char * HTTP_getbody(HTTP_t *http)
char * HTTP_getrequest(const HTTPMethod_t method, const char *uri, const HTTPVersion_t version)
HTTP parsing and building library.