Now takes advantage of url_parse().
Showing
1 changed file
with
30 additions
and
28 deletions
... | @@ -23,6 +23,14 @@ | ... | @@ -23,6 +23,14 @@ |
23 | #include <stdlib.h> | 23 | #include <stdlib.h> |
24 | #include <string.h> | 24 | #include <string.h> |
25 | 25 | ||
26 | #ifdef HAVE_PATHS_H | ||
27 | # include <paths.h> | ||
28 | #endif | ||
29 | |||
30 | #ifndef _PATH_SENDMAIL | ||
31 | # define _PATH_SENDMAIL "/usr/lib/sendmail" | ||
32 | #endif | ||
33 | |||
26 | #include <registrar0.h> | 34 | #include <registrar0.h> |
27 | #include <url0.h> | 35 | #include <url0.h> |
28 | 36 | ||
... | @@ -35,41 +43,35 @@ url_sendmail_destroy (url_t url) | ... | @@ -35,41 +43,35 @@ url_sendmail_destroy (url_t url) |
35 | } | 43 | } |
36 | 44 | ||
37 | /* | 45 | /* |
38 | UNIX Sendmail | 46 | Sendmail URL: |
39 | sendmail:path | 47 | sendmail:/path/to/sendmail |
40 | */ | 48 | */ |
49 | |||
41 | int | 50 | int |
42 | _url_sendmail_init (url_t url) | 51 | _url_sendmail_init (url_t url) |
43 | { | 52 | { |
44 | const char *name = url_to_string (url); | 53 | int status = 0; |
45 | size_t len = strlen (name); | 54 | |
55 | url->_destroy = url_sendmail_destroy; | ||
56 | |||
57 | status = url_parse(url); | ||
58 | |||
59 | if(status) | ||
60 | return status; | ||
46 | 61 | ||
47 | /* reject the obvious */ | 62 | /* is it sendmail? */ |
48 | if (name == NULL || strncmp (MU_SENDMAIL_SCHEME, name, MU_SENDMAIL_SCHEME_LEN) != 0 | 63 | if (strcmp ("sendmail", url->scheme) != 0) |
49 | || len < (MU_SENDMAIL_SCHEME_LEN + 1) /* (scheme)+1(path)*/) | ||
50 | return EINVAL; | 64 | return EINVAL; |
51 | 65 | ||
52 | /* do I need to decode url encoding '% hex hex' ? */ | 66 | /* not valid in a sendmail url */ |
67 | if (url->user || url->passwd || url->auth || url->query | ||
68 | || url->host || url->port) | ||
69 | return EINVAL; | ||
53 | 70 | ||
54 | /* TYPE */ | 71 | if (url->path == 0) |
55 | url->_destroy = url_sendmail_destroy; | 72 | if((url->path = strdup(_PATH_SENDMAIL)) == 0) |
73 | status = ENOMEM; | ||
56 | 74 | ||
57 | /* SCHEME */ | 75 | return status; |
58 | url->scheme = strdup (MU_SENDMAIL_SCHEME); | ||
59 | if (url->scheme == NULL) | ||
60 | { | ||
61 | url_sendmail_destroy (url); | ||
62 | return ENOMEM; | ||
63 | } | ||
64 | |||
65 | /* PATH */ | ||
66 | name += MU_SENDMAIL_SCHEME_LEN; /* pass the scheme */ | ||
67 | url->path = strdup (name); | ||
68 | if (url->path == NULL) | ||
69 | { | ||
70 | url_sendmail_destroy (url); | ||
71 | return ENOMEM; | ||
72 | } | ||
73 | |||
74 | return 0; | ||
75 | } | 76 | } |
77 | ... | ... |
-
Please register or sign in to post a comment