44 assert(header->
value);
48 perror(
"HTTP_addheader empty name");
52 if (
NULL==(newname=realloc(header->
name,strlen(
name)+1))) {
53 perror(
"HTTPHeader_setname realloc");
56 header->
name = newname;
64 assert(header->
value);
74 assert(header->
value);
77 if (
NULL==(newvalue=realloc(header->
value,strlen(value)+1))) {
78 perror(
"HTTPHeader_setvalue realloc");
81 header->
value = newvalue;
82 strcpy(header->
value,value);
89 assert(header->
value);
101 perror(
"HTTPHeader_new");
105 perror(
"HTTPHeader_new name");
109 if (
NULL==(header->
value=strdup(value))) {
110 perror(
"HTTPHeader_new value");
121 assert(header->
name);
122 assert(header->
value);
132 if (
NULL==(http=malloc(
sizeof(
struct HTTP_s)))) {
133 perror(
"HTTP_new HTTP_s");
137 if (
NULL==(http->
body=strdup(
""))) {
138 perror(
"HTTP_new body");
144 perror(
"HTTP_new headers");
161 while (headerlst_entry) {
166 HTTPHeader_del(headerlst_value);
186 if (
NULL==(newbody=realloc(http->
body,strlen(body)+1))) {
187 perror(
"HTTP_setbody realloc");
191 http->
body = newbody;
192 strcpy(http->
body, body);
214 perror(
"HTTP_addheader empty name");
218 if (
NULL==(header = HTTPHeader_new(
name,value))) {
219 perror(
"HTTP_addheader HTTPHeader_new");
224 perror(
"HTTP_addheader");
225 HTTPHeader_del(header);
242 if (
NULL==(auth=malloc(strlen(login)+1+strlen(pass)+1))) {
243 perror(
"HTTP_addbasicauth credentials");
253 if (
NULL==(auth=malloc(strlen(
"Basic ")+strlen(auth_encoded)+1))) {
254 perror(
"HTTP_addbasicauth value");
258 strcpy(auth,
"Basic ");
259 strcat(auth, auth_encoded);
263 perror(
"HTTP_addbasicauth addheader");
287 assert(header->
self);
288 assert(header->
name);
289 assert(header->
value);
291 headerlst_entry = header->
self;
306 assert(start->
value);
309 headerlst_entry = start->
self;
311 while (headerlst_entry) {
316 assert(headerlst_value);
318 if (0==strcmp(header_name,
name))
322 if (!headerlst_entry)
336 assert(header->
self);
337 assert(header->
name);
338 assert(header->
value);
345 perror(
"HTTP_addheader");
350 HTTPHeader_del(header);
355static char* strconcat(
char* dst,
char* src) {
361 if (
NULL==(newdst=realloc(dst,strlen(dst)+strlen(src)+1))) {
371 char* headers_str=
NULL;
378 if (
NULL==(headers_str=strdup(
""))) {
379 perror(
"HTTP_buildheaders headers_str");
386 assert(headerlst_value);
389 headers_str=strconcat(headers_str,
": ");
391 headers_str=strconcat(headers_str,
"\r\n");
416 if (
NULL==(retval=malloc(7+1+strlen(uri)+1+8+1))) {
417 perror(
"HTTP_getrequest");
424 strcat(retval,
"GET");
436 fprintf(stderr,
"HTTP method not supported\n");
446 strcat(retval,
" HTTP/");
450 strcat(retval,
"1.1");
458 fprintf(stderr,
"HTTP version not supported\n");
462 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.