diff --git a/src/http/config.h b/src/http/config.h new file mode 100644 index 0000000..0ea64bc --- /dev/null +++ b/src/http/config.h @@ -0,0 +1,3 @@ +#define Server "UNIX" +#define HTTP_ROOT "/var/www" +#define SERVER_ADDRESS "www.example.com" diff --git a/src/http/url.c b/src/http/url.c new file mode 100644 index 0000000..cb141c1 --- /dev/null +++ b/src/http/url.c @@ -0,0 +1,94 @@ +#include "url.h" + +/* safely frees URL struct */ +struct Url * +free_url(struct Url *url){ + free(url->s); + free(url->ssp); + free(url); + return NULL; +} + +/* turns scheme specific part of URL from string into SSP struct */ +/* returns NULL on allocation error or scheme syntax error */ +struct CommonInternetScheme * +disassemble_commoninternetscheme(char *ssp){ + int i; + char *p; + struct CommonInternetScheme *retval; + + if( /* embarrassingly long if statement */ + (retval + = (struct CommonInternetScheme *) + malloc(sizeof(struct CommonInternetScheme)) + ) == NULL + ) + return NULL; + + parsed = 0; + + /* the scheme-specific data starts with a double slash to indicate that + * it complies with the common Internet scheme syntax (RFC 1738 3.1) */ + if(ssp[0] != '/' || ssp[1] != '/') + return NULL; + ssp += 2; + + /* probe to determine what areas of the SSP are filled */ + p = ssp; + + return retval; +} + +/* turns URL string into URL struct */ +struct Url * +disassemble_url(char *url){ + char *p; + struct Url *retval; + size_t s_s; + size_t ssp_s; + size_t *s; + + if((retval = (struct Url *)malloc(sizeof(struct Url))) == NULL) + return NULL; + s_s = 0; + ssp_s = 0; + + /* get the lengths of the scheme and scheme specific part, excluding + * the nul byte */ + p = url; + s = &s_s; + while(*p != '\0'){ + /* standard; scheme names can't contain colons so the first + * colon must delimit the scheme from the scheme specific part + * (RFC 1738 2.1) */ + if(s == &s_s && *p == ':'){ + s = &ssp_s; + ++p; + } + ++*p; + } + + /* malloc the lengths, including the nul byte */ + if((retval->s = (char *)malloc(sizeof(char) * (s_s + 1))) == NULL) + goto free_retval; + if((retval->ssp = (char *)malloc(sizeof(char) * (ssp_s + 1))) == NULL) + goto free_s; + + /* copy over the scheme and scheme specific part strings */ + p = retval->s; + while(*url != ':') + *(p++) = *(url++); + *p = '\0'; + p = retval->ssp; + while(*url != '\0') + *(p++) = *(url++); + *p = '\0'; + + return retval; + +free_s: + free(retval->s); +free_retval: + free(retval); + return NULL; +} diff --git a/src/http/url.h b/src/http/url.h new file mode 100644 index 0000000..a82d81e --- /dev/null +++ b/src/http/url.h @@ -0,0 +1,20 @@ +/* #include /* free(3), malloc(3), NULL */ + +/* RFC 1738 3.1 */ +struct CommonInternetScheme{ + char *user; + char *password; + char *host; /* FQDN, IPv4, or IPv6 address */ + char *port; /* Can have default; must be supplied in decimal. */ + char *url_path; +}; + +/* standard; RFC 1738 */ +struct Url{ + char *s; /* scheme */ + /* char * or some sort of struct SchemeSpecificPart * */ + void *ssp; /* scheme-specific-part */ +}; + +struct Url *disassemble_url(char *url); +struct Url *free_url(struct Url *url);