diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-08-26 12:57:53 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-08-26 14:37:21 +0100 |
commit | 71fee73561c771b761aee52fe1e6be986c3defa2 (patch) | |
tree | 41ca2bfd09a77c1e3d8dfae38b965998b1f3cd30 /contrib | |
parent | 719111c00e6debc2728b0436e41c237d7e200664 (diff) | |
download | rspamd-71fee73561c771b761aee52fe1e6be986c3defa2.tar.gz rspamd-71fee73561c771b761aee52fe1e6be986c3defa2.zip |
[Minor] Add function to parse string to rdns request type
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/librdns/rdns.h | 7 | ||||
-rw-r--r-- | contrib/librdns/util.c | 42 |
2 files changed, 49 insertions, 0 deletions
diff --git a/contrib/librdns/rdns.h b/contrib/librdns/rdns.h index 82506d36a..ff8eadcc6 100644 --- a/contrib/librdns/rdns.h +++ b/contrib/librdns/rdns.h @@ -353,6 +353,13 @@ const char *rdns_strerror (enum dns_rcode rcode); const char *rdns_strtype (enum rdns_request_type type); /** + * Parse string and return request type + * @param str + * @return + */ +enum rdns_request_type rdns_type_fromstr (const char *str); + +/** * Increase refcount for a request * @param req * @return diff --git a/contrib/librdns/util.c b/contrib/librdns/util.c index 974c97554..1eb5410c3 100644 --- a/contrib/librdns/util.c +++ b/contrib/librdns/util.c @@ -247,6 +247,48 @@ rdns_strtype (enum rdns_request_type type) return dns_types[type]; } +enum rdns_request_type +rdns_type_fromstr (const char *str) +{ + if (str) { + if (strcmp (str, "a") == 0) { + return RDNS_REQUEST_A; + } + else if (strcmp (str, "ns") == 0) { + return RDNS_REQUEST_NS; + } + else if (strcmp (str, "soa") == 0) { + return RDNS_REQUEST_SOA; + } + else if (strcmp (str, "ptr") == 0) { + return RDNS_REQUEST_PTR; + } + else if (strcmp (str, "mx") == 0) { + return RDNS_REQUEST_MX; + } + else if (strcmp (str, "srv") == 0) { + return RDNS_REQUEST_SRV; + } + else if (strcmp (str, "txt") == 0) { + return RDNS_REQUEST_TXT; + } + else if (strcmp (str, "spf") == 0) { + return RDNS_REQUEST_SPF; + } + else if (strcmp (str, "aaaa") == 0) { + return RDNS_REQUEST_AAAA; + } + else if (strcmp (str, "tlsa") == 0) { + return RDNS_REQUEST_TLSA; + } + else if (strcmp (str, "any") == 0) { + return RDNS_REQUEST_ANY; + } + } + + return -1; +} + uint16_t rdns_permutor_generate_id (void) { |