48 lines
864 B
C
48 lines
864 B
C
|
#include "headers.h"
|
||
|
|
||
|
/* return a properly formatted request for any implemented protocol */
|
||
|
char *reqgen(uri *urip)
|
||
|
{
|
||
|
char *req;
|
||
|
|
||
|
if(!strcmp("http", urip->proto))
|
||
|
{
|
||
|
reqgen_http(urip->path, urip->fqdn, &req);
|
||
|
|
||
|
if(!req)
|
||
|
{
|
||
|
return(NULL);
|
||
|
}
|
||
|
|
||
|
return(req);
|
||
|
}
|
||
|
|
||
|
return(NULL);
|
||
|
}
|
||
|
|
||
|
void throw(int errcode)
|
||
|
{
|
||
|
fprintf(stderr, "fetch: error %d.\n", errcode);
|
||
|
exit(errcode);
|
||
|
}
|
||
|
|
||
|
/* return a pointer to a character array on the heap consisting of all bytes */
|
||
|
/* between start and end in str. */
|
||
|
char *substr_extract(const char *str, int start, int end)
|
||
|
{
|
||
|
int substr_len;
|
||
|
char *substr;
|
||
|
|
||
|
substr_len = (end - start);
|
||
|
substr = 0;
|
||
|
|
||
|
/* account for zero index plus the nullterm */
|
||
|
if( !(substr = malloc((substr_len + 1))))
|
||
|
{
|
||
|
return(NULL);
|
||
|
}
|
||
|
|
||
|
memcpy(substr, str+start, substr_len);
|
||
|
|
||
|
return(substr);
|
||
|
}
|