48 assert(header->
value);
52 perror(
"HTTP_addheader empty name");
56 if (
NULL==(newname=realloc(header->
name,strlen(
name)+1))) {
57 perror(
"HTTPHeader_setname realloc");
60 header->
name = newname;
68 assert(header->
value);
78 assert(header->
value);
81 if (
NULL==(newvalue=realloc(header->
value,strlen(value)+1))) {
82 perror(
"HTTPHeader_setvalue realloc");
85 header->
value = newvalue;
86 strcpy(header->
value,value);
93 assert(header->
value);
105 perror(
"HTTPHeader_new");
109 perror(
"HTTPHeader_new name");
113 if (
NULL==(header->
value=strdup(value))) {
114 perror(
"HTTPHeader_new value");
125 assert(header->
name);
126 assert(header->
value);
136 if (
NULL==(http=malloc(
sizeof(
struct HTTP_s)))) {
137 perror(
"HTTP_new HTTP_s");
141 if (
NULL==(http->
body=strdup(
""))) {
142 perror(
"HTTP_new body");
148 perror(
"HTTP_new headers");
165 while (headerlst_entry) {
170 HTTPHeader_del(headerlst_value);
190 if (
NULL==(newbody=realloc(http->
body,strlen(body)+1))) {
191 perror(
"HTTP_setbody realloc");
195 http->
body = newbody;
196 strcpy(http->
body, body);
218 perror(
"HTTP_addheader empty name");
222 if (
NULL==(header = HTTPHeader_new(
name,value))) {
223 perror(
"HTTP_addheader HTTPHeader_new");
228 perror(
"HTTP_addheader");
229 HTTPHeader_del(header);
246 if (
NULL==(auth=malloc(strlen(login)+1+strlen(pass)+1))) {
247 perror(
"HTTP_addbasicauth credentials");
257 if (
NULL==(auth=malloc(strlen(
"Basic ")+strlen(auth_encoded)+1))) {
258 perror(
"HTTP_addbasicauth value");
262 strcpy(auth,
"Basic ");
263 strcat(auth, auth_encoded);
267 perror(
"HTTP_addbasicauth addheader");
291 assert(header->
self);
292 assert(header->
name);
293 assert(header->
value);
295 headerlst_entry = header->
self;
310 assert(start->
value);
313 headerlst_entry = start->
self;
315 while (headerlst_entry) {
320 assert(headerlst_value);
322 if (0==strcmp(header_name,
name))
326 if (!headerlst_entry)
340 assert(header->
self);
341 assert(header->
name);
342 assert(header->
value);
349 perror(
"HTTP_addheader");
357 HTTPHeader_del(header);
362static char* strconcat(
char* dst,
char* src) {
368 if (
NULL==(newdst=realloc(dst,strlen(dst)+strlen(src)+1))) {
378 char* headers_str=
NULL;
385 if (
NULL==(headers_str=strdup(
""))) {
386 perror(
"HTTP_buildheaders headers_str");
393 assert(headerlst_value);
396 headers_str=strconcat(headers_str,
": ");
398 headers_str=strconcat(headers_str,
"\r\n");
423 if (
NULL==(retval=malloc(7+1+strlen(uri)+1+8+1))) {
424 perror(
"HTTP_getrequest");
431 strcat(retval,
"GET");
443 fprintf(stderr,
"HTTP method not supported\n");
453 strcat(retval,
" HTTP/");
457 strcat(retval,
"1.1");
465 fprintf(stderr,
"HTTP version not supported\n");
469 strcat(retval,
"\r\n");
char * base64_encode(char *plain)
Encode a zero terminated C string in Base64.
Simple Base64 encoding and decoding functions.
HTTPHeader_t * HTTP_firstheader(const HTTP_t *http)
char * HTTPHeader_getvalue(HTTPHeader_t *header)
HTTP_t * HTTP_remheader(HTTP_t *http, HTTPHeader_t *header)
void HTTP_del(HTTP_t *http)
char * HTTP_buildheaders(const HTTP_t *http)
struct HTTPHeader_s HTTPHeader_t
HTTPHeader_t * HTTP_addbasicauth(HTTP_t *http, const char *login, const char *pass)
char * HTTP_getbody(HTTP_t *http)
char * HTTPHeader_getname(HTTPHeader_t *header)
HTTPHeader_t * HTTPHeader_setname(HTTPHeader_t *header, const char *name)
HTTPHeader_t * HTTP_findheader(const HTTPHeader_t *start, const char *name)
HTTP_t * HTTP_setbody(HTTP_t *http, const char *body)
HTTPHeader_t * HTTP_addheader(HTTP_t *http, const char *name, const char *value)
char * HTTP_buildrequest(const HTTPMethod_t method, const char *uri, const HTTPVersion_t version)
HTTPHeader_t * HTTPHeader_setvalue(HTTPHeader_t *header, const char *value)
HTTPHeader_t * HTTP_nextheader(const HTTPHeader_t *header)
HTTP parsing and building library.
enum HTTPVersion_e HTTPVersion_t
enum HTTPMethod_e HTTPMethod_t
void * sclist_getvalue(sclistrecord_t *record)
Returns the value pointer stored in the record.
sclist_t * sclist_new()
Allocate and initialize the internal list structure.
sclistrecord_t * sclist_nextrecord(const sclistrecord_t *record)
Returns the pointer on the record following the specified one.
sclistrecord_t * sclist_addrecord(sclist_t *sclist, void *value)
Add a value at the end of the list.
sclistrecord_t * sclist_firstrecord(const sclist_t *sclist)
Returns the pointer on the first list record.
void sclist_remrecord(sclist_t *sclist, sclistrecord_t *record)
Remove a record in a list.
Basic single chained generic list.
Private list record structure.