Kyle J. McKay | 3402a8d | 2013-07-31 13:52:00 -0700 | [diff] [blame] | 1 | #ifndef URL_MATCH_H |
Elijah Newren | 64e68a3 | 2018-08-15 10:54:08 -0700 | [diff] [blame] | 2 | #define URL_MATCH_H |
| 3 | |
Kyle J. McKay | 3402a8d | 2013-07-31 13:52:00 -0700 | [diff] [blame] | 4 | #include "string-list.h" |
| 5 | |
| 6 | struct url_info { |
| 7 | /* normalized url on success, must be freed, otherwise NULL */ |
| 8 | char *url; |
| 9 | /* if !url, a brief reason for the failure, otherwise NULL */ |
| 10 | const char *err; |
| 11 | |
| 12 | /* the rest of the fields are only set if url != NULL */ |
| 13 | |
| 14 | size_t url_len; /* total length of url (which is now normalized) */ |
| 15 | size_t scheme_len; /* length of scheme name (excluding final :) */ |
| 16 | size_t user_off; /* offset into url to start of user name (0 => none) */ |
| 17 | size_t user_len; /* length of user name; if user_off != 0 but |
| 18 | user_len == 0, an empty user name was given */ |
| 19 | size_t passwd_off; /* offset into url to start of passwd (0 => none) */ |
| 20 | size_t passwd_len; /* length of passwd; if passwd_off != 0 but |
| 21 | passwd_len == 0, an empty passwd was given */ |
| 22 | size_t host_off; /* offset into url to start of host name (0 => none) */ |
Patrick Steinhardt | 3ec6e6e | 2017-01-31 10:01:45 +0100 | [diff] [blame] | 23 | size_t host_len; /* length of host name; |
Kyle J. McKay | 3402a8d | 2013-07-31 13:52:00 -0700 | [diff] [blame] | 24 | * file urls may have host_len == 0 */ |
Patrick Steinhardt | 3ec6e6e | 2017-01-31 10:01:45 +0100 | [diff] [blame] | 25 | size_t port_off; /* offset into url to start of port number (0 => none) */ |
| 26 | size_t port_len; /* if a portnum is present (port_off != 0), it has |
| 27 | * this length (excluding the leading ':') starting |
| 28 | * from port_off (always 0 for file urls) */ |
Kyle J. McKay | 3402a8d | 2013-07-31 13:52:00 -0700 | [diff] [blame] | 29 | size_t path_off; /* offset into url to the start of the url path; |
| 30 | * this will always point to a '/' character |
| 31 | * after the url has been normalized */ |
| 32 | size_t path_len; /* length of path portion excluding any trailing |
| 33 | * '?...' and '#...' portion; will always be >= 1 */ |
| 34 | }; |
| 35 | |
Denton Liu | 5545442 | 2019-04-29 04:28:14 -0400 | [diff] [blame] | 36 | char *url_normalize(const char *, struct url_info *); |
Kyle J. McKay | 3402a8d | 2013-07-31 13:52:00 -0700 | [diff] [blame] | 37 | |
Junio C Hamano | 836b6fb | 2013-07-31 10:42:01 -0700 | [diff] [blame] | 38 | struct urlmatch_item { |
Patrick Steinhardt | af99049 | 2017-01-31 10:01:46 +0100 | [diff] [blame] | 39 | size_t hostmatch_len; |
| 40 | size_t pathmatch_len; |
Junio C Hamano | 836b6fb | 2013-07-31 10:42:01 -0700 | [diff] [blame] | 41 | char user_matched; |
| 42 | }; |
| 43 | |
| 44 | struct urlmatch_config { |
| 45 | struct string_list vars; |
| 46 | struct url_info url; |
| 47 | const char *section; |
| 48 | const char *key; |
| 49 | |
| 50 | void *cb; |
| 51 | int (*collect_fn)(const char *var, const char *value, void *cb); |
| 52 | int (*cascade_fn)(const char *var, const char *value, void *cb); |
| 53 | }; |
| 54 | |
Denton Liu | 5545442 | 2019-04-29 04:28:14 -0400 | [diff] [blame] | 55 | int urlmatch_config_entry(const char *var, const char *value, void *cb); |
Junio C Hamano | 836b6fb | 2013-07-31 10:42:01 -0700 | [diff] [blame] | 56 | |
Kyle J. McKay | 3402a8d | 2013-07-31 13:52:00 -0700 | [diff] [blame] | 57 | #endif /* URL_MATCH_H */ |