_url_smtp_init(): using url_parse(), now accepts host AND port as args
Showing
1 changed file
with
15 additions
and
36 deletions
... | @@ -26,51 +26,30 @@ | ... | @@ -26,51 +26,30 @@ |
26 | #include <registrar0.h> | 26 | #include <registrar0.h> |
27 | #include <url0.h> | 27 | #include <url0.h> |
28 | 28 | ||
29 | static void url_smtp_destroy (url_t purl); | ||
30 | |||
31 | static void | ||
32 | url_smtp_destroy (url_t url) | ||
33 | { | ||
34 | (void) url; | ||
35 | } | ||
36 | |||
37 | /* | ||
38 | UNIX File | ||
39 | file:path | ||
40 | */ | ||
41 | int | 29 | int |
42 | _url_smtp_init (url_t url) | 30 | _url_smtp_init (url_t url) |
43 | { | 31 | { |
44 | const char *name = url_to_string (url); | 32 | int status = 0; |
45 | size_t len = strlen (name); | ||
46 | 33 | ||
47 | /* reject the obvious */ | 34 | if((status = url_parse(url))) |
48 | if (name == NULL || strncmp (MU_SMTP_SCHEME, name, MU_SMTP_SCHEME_LEN) != 0 | 35 | return status; |
49 | || len < (MU_SMTP_SCHEME_LEN + 1) /* (scheme)+1(path)*/) | 36 | |
37 | if(!url_is_scheme(url, "smtp")) | ||
50 | return EINVAL; | 38 | return EINVAL; |
51 | 39 | ||
52 | /* do I need to decode url encoding '% hex hex' ? */ | 40 | /* host isn't optional */ |
53 | 41 | ||
54 | /* TYPE */ | 42 | if(!url->host) |
55 | url->_destroy = url_smtp_destroy; | 43 | return EINVAL; |
56 | 44 | ||
57 | /* SCHEME */ | 45 | /* port has a default */ |
58 | url->scheme = strdup (MU_SMTP_SCHEME); | 46 | if(!url->port) |
59 | if (url->scheme == NULL) | 47 | url->port = MU_SMTP_PORT; |
60 | { | ||
61 | url_smtp_destroy (url); | ||
62 | return ENOMEM; | ||
63 | } | ||
64 | 48 | ||
65 | /* PATH */ | 49 | /* all other fields must be NULL */ |
66 | name += MU_SMTP_SCHEME_LEN; /* pass the scheme */ | 50 | if(url->user || url->passwd || url->auth || url->path || url->query) |
67 | url->host = strdup (name); | 51 | return EINVAL; |
68 | if (url->host == NULL) | ||
69 | { | ||
70 | url_smtp_destroy (url); | ||
71 | return ENOMEM; | ||
72 | } | ||
73 | url->port = MU_SMTP_PORT; | ||
74 | 52 | ||
75 | return 0; | 53 | return 0; |
76 | } | 54 | } |
55 | ... | ... |
-
Please register or sign in to post a comment