terom@13: #ifndef LIB_URL_H terom@13: #define LIB_URL_H terom@13: terom@13: /* terom@13: * A trivial parser for simple URLs terom@13: * terom@14: * [ [ "+" [ ... ] ] "://" ] [ [ ":" ] "@" ] [  ] [ ":" ] [ "/" ] [ "?" [ [ "=" ] ] [ "&" [ [ "=" ] ] [ ... ] ] terom@13: * terom@13: * example.com terom@13: * tcp://example.com:7348/ terom@13: * psql://postgres@localhost/test_db?charset=utf8 terom@13: * terom@13: */ terom@13: terom@15: #include terom@16: #include terom@15: terom@13: /* terom@13: * The schema terom@13: */ terom@13: struct url_schema { terom@13: size_t count; terom@16: const char *list[]; terom@13: }; terom@13: terom@13: /* terom@13: * The options at the end terom@13: */ terom@13: struct url_opts { terom@13: size_t count; terom@13: struct url_opt { terom@13: const char *key; terom@13: const char *value; terom@16: } list[]; terom@13: }; terom@13: terom@13: /* terom@13: * A parsed URL terom@13: */ terom@13: struct url { terom@13: struct url_schema *schema; terom@13: const char *username; terom@13: const char *password; terom@13: const char *hostname; terom@13: const char *service; terom@13: const char *path; terom@13: struct url_opts *opts; terom@13: }; terom@13: terom@13: /* terom@13: * Parse the given `text` as an URL, returning the result in `url`. Optional fields that are missing in the text will terom@13: * cause those values to be returned unmodified. terom@14: * terom@14: * Returns zero if the url was valid and was parsed, nonzero if it was invalid. terom@13: */ terom@13: int url_parse (struct url *url, const char *text); terom@13: terom@16: /* terom@16: * Prints a url in a debug-output format. terom@16: */ terom@16: void url_dump (const struct url *url, FILE *stream); terom@16: terom@13: #endif /* LIB_URL_H */