/* */ #ifndef D_URI_SPLIT_H #define D_URI_SPLIT_H #ifdef __cplusplus extern "C" { #endif #include #include typedef enum { USR_SCHEME, USR_HOST, USR_PORT, USR_PATH, USR_QUERY, USR_FRAGMENT, USR_USERINFO, USR_USER, USR_PASSWD, USR_BASENAME, USR_MAX } uri_split_field; typedef enum { USF_IPV6ADDR = 1 } uri_split_flag; /* The structure is based on http-parser by Joyent, Inc and other Node contributors. https://github.com/joyent/http-parser */ typedef struct { uint16_t field_set; uint16_t port; struct { uint16_t off; uint16_t len; } fields[USR_MAX]; uint8_t flags; } uri_split_result; /* Splits URI |uri| and stores the results in the |res|. To check * particular URI component is available, evaluate |res->field_set| * with 1 shifted by the field defined in uri_split_field. If the * |res| is NULL, processing is done but the result will not stored. * If the host component of the |uri| is IPv6 numeric address, then * USF_IPV6ADDR & res->flags will be nonzero. * * This function returns 0 if it succeeds, or -1. */ int uri_split(uri_split_result* res, const char* uri); #ifdef __cplusplus } #endif #endif /* D_URI_SPLIT_H */