39 assert(header->
value);
41 if (
NULL==(newname=realloc(header->
name,strlen(
name)+1))) {
42 perror(
"HTTPHeader_setname realloc");
45 header->
name = newname;
53 assert(header->
value);
63 assert(header->
value);
65 if (
NULL==(newvalue=realloc(header->
value,strlen(value)+1))) {
66 perror(
"HTTPHeader_setvalue realloc");
69 header->
value = newvalue;
70 strcpy(header->
value,value);
77 assert(header->
value);
89 perror(
"HTTPHeader_new");
93 perror(
"HTTPHeader_new name");
97 if (
NULL==(header->
value=strdup(value))) {
98 perror(
"HTTPHeader_new value");
109 assert(header->
name);
110 assert(header->
value);
135 if (
NULL==(newbody=realloc(http->
body,strlen(body)+1))) {
136 perror(
"HTTP_setbody realloc");
140 http->
body = newbody;
141 strcpy(http->
body, body);
162 if (
NULL==(header = HTTPHeader_new(
name,value))) {
163 perror(
"HTTP_addheader HTTPHeader_new");
168 perror(
"HTTP_addheader");
169 HTTPHeader_del(header);
186 if (
NULL==(auth=malloc(strlen(login)+1+strlen(pass)+1))) {
187 perror(
"HTTP_addbasicauth credentials");
197 if (
NULL==(auth=malloc(strlen(
"Basic ")+strlen(auth_encoded)+1))) {
198 perror(
"HTTP_addbasicauth value");
202 strcpy(auth,
"Basic ");
203 strcat(auth, auth_encoded);
207 perror(
"HTTP_addbasicauth addheader");
231 assert(header->
self);
232 assert(header->
name);
233 assert(header->
value);
235 headerlst_entry = header->
self;
250 assert(start->
value);
253 headerlst_entry = start->
self;
255 while (headerlst_entry) {
260 assert(headerlst_value);
262 if (0==strcmp(header_name,
name))
266 if (!headerlst_entry)
280 assert(header->
self);
281 assert(header->
name);
282 assert(header->
value);
289 perror(
"HTTP_addheader");
294 HTTPHeader_del(header);
302 if (
NULL==(http=malloc(
sizeof(
struct HTTP_s)))) {
303 perror(
"HTTP_new HTTP_s");
307 if (
NULL==(http->
body=strdup(
""))) {
308 perror(
"HTTP_new body");
314 perror(
"HTTP_new headers");
331 while (headerlst_entry) {
336 HTTPHeader_del(headerlst_value);
348static char* strconcat(
char* dst,
char* src) {
354 if (
NULL==(newdst=realloc(dst,strlen(dst)+strlen(src)+1))) {
364 char* headers_str=
NULL;
372 if (
NULL==(headers_str=strdup(
""))) {
373 perror(
"HTTP_buildheaders headers_str");
378 assert(headerlst_value);
381 headers_str=strconcat(headers_str,
": ");
383 headers_str=strconcat(headers_str,
"\r\n");
408 if (
NULL==(retval=malloc(7+1+strlen(uri)+1+8+1))) {
409 perror(
"HTTP_getrequest");
416 strcat(retval,
"GET");
428 fprintf(stderr,
"HTTP method not supported\n");
438 strcat(retval,
" HTTP/");
442 strcat(retval,
"1.1");
450 fprintf(stderr,
"HTTP version not supported\n");
454 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.