#include "headers.h" /* return a properly formatted request for any implemented protocol */ char *reqgen(uri *urip) { char *req; if(!strcmp("http", urip->proto) || !strcmp("https", urip->proto)) { reqgen_http(urip->path, urip->fqdn, &req); if(!req) { return(NULL); } return(req); } else if(!strcmp(urip->proto, "gopher")) { reqgen_gopher(urip->path, &req); if(!req) { return(NULL); } return(req); } return(NULL); } /* takes a data buffer and returns an integer corresponding to the server's response value */ /* if not applicable, return -1 */ /* if not found, return 0 */ int resp_parse(char *data, uri *uristruct) { if(strncmp("http", uristruct->proto, 4)) { return(resp_parse_http(data)); } else { return(-1); } } /* 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 = NULL; /* account for zero index plus the nullterm */ if( !(substr = calloc((substr_len + 1), sizeof(char)))) { return(NULL); } memcpy(substr, str+start, substr_len); return(substr); } char *buftolower(char *bufp) { int i; char *nbufp; nbufp = calloc(strlen(bufp), sizeof(char)); for(i = 0; '\0' != bufp[i]; i++) { nbufp[i] = tolower(bufp[i]); } return(nbufp); }