This commit is contained in:
2022-01-15 16:19:41 +08:00
parent 4468799a86
commit cfa10b4e37
8 changed files with 274 additions and 4 deletions

27
urlparse.h Normal file
View File

@@ -0,0 +1,27 @@
#ifndef _UTIL_URLPARSE_H
#define _UTIL_URLPARSE_H
#ifdef __cplusplus
extern "C" {
#endif
typedef struct UrlParseResult {
char* scheme;
char* netloc;
char* path;
char* params;
char* query;
char* fragment;
} UrlParseResult;
/**
* @brief Parse a URL into 6 components: <scheme>://<netloc>/<path>;<params>?<query>#<fragment>
* @param url URL
* @param sch Provides the default value of the scheme component when no scheme is found in url.
* @param allow_fragments If is 0, no attempt is made to separate the fragment component from the previous component, which can be either path or query.
* @return
*/
UrlParseResult* urlparse(const char* url, const char* sch, char allow_fragments);
void free_url_parse_result(UrlParseResult* r);
void dump_url_parse_result(UrlParseResult* r, int indent_now);
#ifdef __cplusplus
}
#endif
#endif