#include "headers.h" /* return a properly formatted request for any implemented protocol */ char *reqgen(uri *urip) { char *req; int is_tls = 0; 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 = malloc((substr_len + 1)))) { return(NULL); } memcpy(substr, str+start, substr_len); return(substr); } /* mastrcat -- improved string concat function. returns a pointer to the first element in a buffer containing the strings str1 */ /* and str2 joined end-to-end. */ char *mastrcat(char *str1, char *str2) { unsigned long int nbi, stri, nbsize; char *nbuf; nbi = stri = 0; nbsize = (strlen(str1) + strlen(str2)); nbuf = malloc(nbsize); for(stri = 0; str1[stri] != '\0'; nbi++, stri++) { nbuf[nbi] = str1[stri]; } for(stri = 0; str2[stri] != '\0'; nbi++, stri++) { nbuf[nbi] = str2[stri]; } return nbuf; }