attribute.c body.c header.c io.c mbx_unix.c message.c mime.c
net.c tcp.c transcode.c url_pop.c include/private/io0.h include/private/url0.h include/public/attribute.h include/public/io.h include/public/mailbox.h all function *_init() rename to *_create().
Showing
16 changed files
with
112 additions
and
89 deletions
... | @@ -254,8 +254,7 @@ attribute_copy (attribute_t dest, attribute_t src) | ... | @@ -254,8 +254,7 @@ attribute_copy (attribute_t dest, attribute_t src) |
254 | } | 254 | } |
255 | 255 | ||
256 | int | 256 | int |
257 | string_to_attribute (const char *buffer, size_t len, | 257 | string_to_attribute (const char *buffer, attribute_t *pattr, void *owner) |
258 | attribute_t *pattr, void *owner) | ||
259 | { | 258 | { |
260 | char *sep; | 259 | char *sep; |
261 | int status; | 260 | int status; |
... | @@ -265,9 +264,11 @@ string_to_attribute (const char *buffer, size_t len, | ... | @@ -265,9 +264,11 @@ string_to_attribute (const char *buffer, size_t len, |
265 | return status; | 264 | return status; |
266 | 265 | ||
267 | /* Set the attribute */ | 266 | /* Set the attribute */ |
268 | if (len > 7 && strncasecmp (buffer, "Status:", 7) == 0) | 267 | if (strncasecmp (buffer, "Status:", 7) == 0) |
269 | { | 268 | { |
270 | sep = strchr(buffer, ':'); /* pass the ':' */ | 269 | sep = strchr(buffer, ':'); /* pass the ':' */ |
270 | sep++; | ||
271 | while (*sep == ' ') sep++; /* glob spaces */ | ||
271 | if (strchr (sep, 'R') != NULL || strchr (sep, 'r') != NULL) | 272 | if (strchr (sep, 'R') != NULL || strchr (sep, 'r') != NULL) |
272 | attribute_set_read (*pattr); | 273 | attribute_set_read (*pattr); |
273 | if (strchr (sep, 'O') != NULL || strchr (sep, 'o') != NULL) | 274 | if (strchr (sep, 'O') != NULL || strchr (sep, 'o') != NULL) |
... | @@ -280,3 +281,40 @@ string_to_attribute (const char *buffer, size_t len, | ... | @@ -280,3 +281,40 @@ string_to_attribute (const char *buffer, size_t len, |
280 | return 0; | 281 | return 0; |
281 | } | 282 | } |
282 | 283 | ||
284 | int | ||
285 | attribute_to_string (attribute_t attr, char *buffer, size_t len, size_t *pn) | ||
286 | { | ||
287 | char status[32]; | ||
288 | char a[8]; | ||
289 | size_t i; | ||
290 | |||
291 | *status = *a = '\0'; | ||
292 | |||
293 | if (attribute_is_seen (attr)) | ||
294 | strcat (a, "R"); | ||
295 | if (attribute_is_answered (attr)) | ||
296 | strcat (a, "A"); | ||
297 | if (attribute_is_flagged (attr)) | ||
298 | strcat (a, "F"); | ||
299 | if (attribute_is_read (attr)) | ||
300 | strcat (a, "O"); | ||
301 | |||
302 | if (*a != '\0') | ||
303 | { | ||
304 | strcpy (status, "Status: "); | ||
305 | strcat (status, a); | ||
306 | strcat (status, "\n"); | ||
307 | } | ||
308 | |||
309 | i = strlen (status); | ||
310 | |||
311 | if (buffer && len != 0) | ||
312 | { | ||
313 | strncpy (buffer, status, len - 1); | ||
314 | buffer[len - 1] = '\0'; | ||
315 | i = strlen (buffer); | ||
316 | } | ||
317 | if (pn) | ||
318 | *pn = i; | ||
319 | return 0; | ||
320 | } | ... | ... |
... | @@ -82,7 +82,7 @@ body_get_stream (body_t body, stream_t *pstream) | ... | @@ -82,7 +82,7 @@ body_get_stream (body_t body, stream_t *pstream) |
82 | /* lazy floating body it is created when | 82 | /* lazy floating body it is created when |
83 | * doing the first body_write call | 83 | * doing the first body_write call |
84 | */ | 84 | */ |
85 | status = stream_create (&stream, body); | 85 | status = stream_create (&stream, 0, body); |
86 | if (status != 0) | 86 | if (status != 0) |
87 | return status; | 87 | return status; |
88 | stream_set_read (stream, body_read, body); | 88 | stream_set_read (stream, body_read, body); | ... | ... |
... | @@ -68,7 +68,7 @@ header_create (header_t *ph, const char *blurb, size_t len, void *owner) | ... | @@ -68,7 +68,7 @@ header_create (header_t *ph, const char *blurb, size_t len, void *owner) |
68 | 68 | ||
69 | header_parse (h, (char *)blurb, len); | 69 | header_parse (h, (char *)blurb, len); |
70 | 70 | ||
71 | status = stream_create (&(h->stream), h); | 71 | status = stream_create (&(h->stream), 0, h); |
72 | if (status != 0) | 72 | if (status != 0) |
73 | return status; | 73 | return status; |
74 | 74 | ... | ... |
... | @@ -35,6 +35,8 @@ extern "C" { | ... | @@ -35,6 +35,8 @@ extern "C" { |
35 | struct _stream | 35 | struct _stream |
36 | { | 36 | { |
37 | void *owner; | 37 | void *owner; |
38 | int flags; | ||
39 | void (*_destroy) __P ((void *)); | ||
38 | int (*_get_fd) __P ((stream_t, int *)); | 40 | int (*_get_fd) __P ((stream_t, int *)); |
39 | int (*_read) __P ((stream_t, char *, size_t, off_t, size_t *)); | 41 | int (*_read) __P ((stream_t, char *, size_t, off_t, size_t *)); |
40 | int (*_write) __P ((stream_t, const char *, size_t, off_t, size_t *)); | 42 | int (*_write) __P ((stream_t, const char *, size_t, off_t, size_t *)); | ... | ... |
... | @@ -92,22 +92,9 @@ struct _url | ... | @@ -92,22 +92,9 @@ struct _url |
92 | /* MMDF */ | 92 | /* MMDF */ |
93 | 93 | ||
94 | /* POP3 */ | 94 | /* POP3 */ |
95 | struct _url_pop; | ||
96 | typedef struct _url_pop * url_pop_t; | ||
97 | |||
98 | struct _url_pop | ||
99 | { | ||
100 | /* we use the fields from url_t */ | ||
101 | /* user, passwd, host, port */ | ||
102 | char * auth; | ||
103 | int (*_get_auth) __P ((const url_pop_t, char *, size_t, size_t *)); | ||
104 | }; | ||
105 | 95 | ||
106 | #define MU_POP_PORT 110 | 96 | #define MU_POP_PORT 110 |
107 | 97 | ||
108 | /* pop*/ | ||
109 | extern int url_pop_get_auth (const url_t, char *, size_t, size_t *); | ||
110 | |||
111 | /* UNIX MBOX */ | 98 | /* UNIX MBOX */ |
112 | 99 | ||
113 | #ifdef __cplusplus | 100 | #ifdef __cplusplus | ... | ... |
... | @@ -67,8 +67,10 @@ extern int attribute_is_equal __P ((attribute_t att1, attribute_t att2)); | ... | @@ -67,8 +67,10 @@ extern int attribute_is_equal __P ((attribute_t att1, attribute_t att2)); |
67 | extern int attribute_copy __P ((attribute_t dst, | 67 | extern int attribute_copy __P ((attribute_t dst, |
68 | attribute_t src)); | 68 | attribute_t src)); |
69 | 69 | ||
70 | extern int string_to_attribute __P ((const char *buf, size_t len, | 70 | extern int string_to_attribute __P ((const char *buf, |
71 | attribute_t *pattr, void *owner)); | 71 | attribute_t *pattr, void *owner)); |
72 | extern int attribute_to_string __P ((attribute_t attr, char *buf, | ||
73 | size_t len, size_t *)); | ||
72 | extern int attribute_get_owner __P ((attribute_t attr, void **owner)); | 74 | extern int attribute_get_owner __P ((attribute_t attr, void **owner)); |
73 | #ifdef __cplusplus | 75 | #ifdef __cplusplus |
74 | } | 76 | } | ... | ... |
... | @@ -35,9 +35,16 @@ extern "C" { /*}*/ | ... | @@ -35,9 +35,16 @@ extern "C" { /*}*/ |
35 | struct _stream; | 35 | struct _stream; |
36 | typedef struct _stream *stream_t; | 36 | typedef struct _stream *stream_t; |
37 | 37 | ||
38 | extern int stream_create __P ((stream_t *, void *owner)); | 38 | /* stream will be destroy on stream_destroy */ |
39 | #define MU_STREAM_NO_CHECK 1 | ||
40 | |||
41 | extern int stream_create __P ((stream_t *, int flags, void *owner)); | ||
39 | extern void stream_destroy __P ((stream_t *, void *owner)); | 42 | extern void stream_destroy __P ((stream_t *, void *owner)); |
40 | 43 | ||
44 | extern int stream_set_destroy __P ((stream_t, | ||
45 | void (*_destroy) __P ((void *)), | ||
46 | void *owner)); | ||
47 | |||
41 | extern int stream_set_fd __P ((stream_t, | 48 | extern int stream_set_fd __P ((stream_t, |
42 | int (*_get_fd)(stream_t, int *), | 49 | int (*_get_fd)(stream_t, int *), |
43 | void *owner)); | 50 | void *owner)); | ... | ... |
... | @@ -81,7 +81,7 @@ extern int mailbox_is_updated __P ((mailbox_t)); | ... | @@ -81,7 +81,7 @@ extern int mailbox_is_updated __P ((mailbox_t)); |
81 | extern int mailbox_scan __P ((mailbox_t, size_t msgno, size_t *count)); | 81 | extern int mailbox_scan __P ((mailbox_t, size_t msgno, size_t *count)); |
82 | 82 | ||
83 | /* mailbox size ? */ | 83 | /* mailbox size ? */ |
84 | extern int mailbox_size __P ((mailbox_t, off_t size)); | 84 | extern int mailbox_size __P ((mailbox_t, off_t *size)); |
85 | 85 | ||
86 | extern int mailbox_get_url __P ((mailbox_t, url_t *)); | 86 | extern int mailbox_get_url __P ((mailbox_t, url_t *)); |
87 | 87 | ... | ... |
... | @@ -22,7 +22,7 @@ | ... | @@ -22,7 +22,7 @@ |
22 | #include <stdio.h> | 22 | #include <stdio.h> |
23 | 23 | ||
24 | int | 24 | int |
25 | stream_create (stream_t *pstream, void *owner) | 25 | stream_create (stream_t *pstream, int flags, void *owner) |
26 | { | 26 | { |
27 | stream_t stream; | 27 | stream_t stream; |
28 | if (pstream == NULL || owner == NULL) | 28 | if (pstream == NULL || owner == NULL) |
... | @@ -31,6 +31,7 @@ stream_create (stream_t *pstream, void *owner) | ... | @@ -31,6 +31,7 @@ stream_create (stream_t *pstream, void *owner) |
31 | if (stream == NULL) | 31 | if (stream == NULL) |
32 | return ENOMEM; | 32 | return ENOMEM; |
33 | stream->owner = owner; | 33 | stream->owner = owner; |
34 | stream->flags = flags; | ||
34 | *pstream = stream; | 35 | *pstream = stream; |
35 | return 0; | 36 | return 0; |
36 | } | 37 | } |
... | @@ -41,13 +42,30 @@ stream_destroy (stream_t *pstream, void *owner) | ... | @@ -41,13 +42,30 @@ stream_destroy (stream_t *pstream, void *owner) |
41 | if (pstream && *pstream) | 42 | if (pstream && *pstream) |
42 | { | 43 | { |
43 | stream_t stream = *pstream; | 44 | stream_t stream = *pstream; |
44 | if (stream->owner == owner) | 45 | |
46 | if (stream->_destroy) | ||
47 | stream->_destroy (owner); | ||
48 | if ((stream->flags & MU_STREAM_NO_CHECK) || stream->owner == owner) | ||
45 | free (stream); | 49 | free (stream); |
46 | *pstream = NULL; | 50 | *pstream = NULL; |
47 | } | 51 | } |
48 | } | 52 | } |
49 | 53 | ||
50 | int | 54 | int |
55 | stream_set_destroy (stream_t stream, void (*_destroy) (void *), | ||
56 | void *owner) | ||
57 | { | ||
58 | if (stream == NULL) | ||
59 | return EINVAL; | ||
60 | |||
61 | if (stream->owner != owner) | ||
62 | return EACCES; | ||
63 | |||
64 | stream->_destroy = _destroy; | ||
65 | return 0; | ||
66 | } | ||
67 | |||
68 | int | ||
51 | stream_set_fd (stream_t stream, int (*_get_fd) (stream_t, int *), void *owner) | 69 | stream_set_fd (stream_t stream, int (*_get_fd) (stream_t, int *), void *owner) |
52 | { | 70 | { |
53 | if (stream == NULL) | 71 | if (stream == NULL) | ... | ... |
... | @@ -908,7 +908,7 @@ mailbox_unix_readstream (stream_t is, char *buffer, size_t buflen, | ... | @@ -908,7 +908,7 @@ mailbox_unix_readstream (stream_t is, char *buffer, size_t buflen, |
908 | mailbox_unix_message_t mum; | 908 | mailbox_unix_message_t mum; |
909 | size_t nread = 0; | 909 | size_t nread = 0; |
910 | 910 | ||
911 | if (is == NULL || (mum = (mailbox_unix_message_t)is->owner) == NULL) | 911 | if (is == NULL || (mum = is->owner) == NULL) |
912 | return EINVAL; | 912 | return EINVAL; |
913 | 913 | ||
914 | if (buffer == NULL || buflen == 0) | 914 | if (buffer == NULL || buflen == 0) |
... | @@ -1167,7 +1167,9 @@ mailbox_unix_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg) | ... | @@ -1167,7 +1167,9 @@ mailbox_unix_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg) |
1167 | message_destroy (&msg, mum); | 1167 | message_destroy (&msg, mum); |
1168 | return status; | 1168 | return status; |
1169 | } | 1169 | } |
1170 | status = stream_create (&stream, mum); | 1170 | message_set_body (msg, body, mum); |
1171 | |||
1172 | status = stream_create (&stream, 0, mum); | ||
1171 | if (status != 0) | 1173 | if (status != 0) |
1172 | { | 1174 | { |
1173 | message_destroy (&msg, mum); | 1175 | message_destroy (&msg, mum); |
... | @@ -1177,9 +1179,7 @@ mailbox_unix_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg) | ... | @@ -1177,9 +1179,7 @@ mailbox_unix_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg) |
1177 | stream_set_fd (stream, mailbox_unix_getfd, mum); | 1179 | stream_set_fd (stream, mailbox_unix_getfd, mum); |
1178 | body_set_stream (body, stream, mum); | 1180 | body_set_stream (body, stream, mum); |
1179 | body_set_size (body, mailbox_unix_body_size, mum); | 1181 | body_set_size (body, mailbox_unix_body_size, mum); |
1180 | /* set the line */ | ||
1181 | body_set_lines (body, mailbox_unix_body_lines, mum); | 1182 | body_set_lines (body, mailbox_unix_body_lines, mum); |
1182 | message_set_body (msg, body, mum); | ||
1183 | 1183 | ||
1184 | /* set the attribute */ | 1184 | /* set the attribute */ |
1185 | status = message_set_attribute (msg, mum->new_attr, mum); | 1185 | status = message_set_attribute (msg, mum->new_attr, mum); |
... | @@ -1293,7 +1293,7 @@ mailbox_unix_append_message (mailbox_t mbox, message_t msg) | ... | @@ -1293,7 +1293,7 @@ mailbox_unix_append_message (mailbox_t mbox, message_t msg) |
1293 | } | 1293 | } |
1294 | 1294 | ||
1295 | static int | 1295 | static int |
1296 | mailbox_unix_size (mailbox_t mbox, off_t *size) | 1296 | mailbox_unix_size (mailbox_t mbox, off_t *psize) |
1297 | { | 1297 | { |
1298 | mailbox_unix_data_t mud; | 1298 | mailbox_unix_data_t mud; |
1299 | struct stat st; | 1299 | struct stat st; |
... | @@ -1310,7 +1310,8 @@ mailbox_unix_size (mailbox_t mbox, off_t *size) | ... | @@ -1310,7 +1310,8 @@ mailbox_unix_size (mailbox_t mbox, off_t *size) |
1310 | /* oops !! */ | 1310 | /* oops !! */ |
1311 | if (fstat (fd, &st) != 0) | 1311 | if (fstat (fd, &st) != 0) |
1312 | return errno; | 1312 | return errno; |
1313 | *size = st.st_size; | 1313 | if (psize) |
1314 | *psize = st.st_size; | ||
1314 | return 0; | 1315 | return 0; |
1315 | } | 1316 | } |
1316 | 1317 | ... | ... |
... | @@ -47,7 +47,7 @@ message_create (message_t *pmsg, void *owner) | ... | @@ -47,7 +47,7 @@ message_create (message_t *pmsg, void *owner) |
47 | msg = calloc (1, sizeof (*msg)); | 47 | msg = calloc (1, sizeof (*msg)); |
48 | if (msg == NULL) | 48 | if (msg == NULL) |
49 | return ENOMEM; | 49 | return ENOMEM; |
50 | status = stream_create (&stream, msg); | 50 | status = stream_create (&stream, 0, msg); |
51 | if (status != 0) | 51 | if (status != 0) |
52 | { | 52 | { |
53 | free (msg); | 53 | free (msg); |
... | @@ -188,7 +188,7 @@ message_get_stream (message_t msg, stream_t *pstream) | ... | @@ -188,7 +188,7 @@ message_get_stream (message_t msg, stream_t *pstream) |
188 | { | 188 | { |
189 | stream_t stream; | 189 | stream_t stream; |
190 | int status; | 190 | int status; |
191 | status = stream_create (&stream, msg); | 191 | status = stream_create (&stream, 0, msg); |
192 | if (status != 0) | 192 | if (status != 0) |
193 | return status; | 193 | return status; |
194 | stream_set_read (stream, message_read, msg); | 194 | stream_set_read (stream, message_read, msg); | ... | ... |
... | @@ -449,7 +449,7 @@ int mime_get_part(mime_t mime, int part, message_t *msg) | ... | @@ -449,7 +449,7 @@ int mime_get_part(mime_t mime, int part, message_t *msg) |
449 | message_set_header(mime_part->msg, mime_part->hdr, mime_part); | 449 | message_set_header(mime_part->msg, mime_part->hdr, mime_part); |
450 | header_size(mime_part->hdr, &hsize); | 450 | header_size(mime_part->hdr, &hsize); |
451 | if ( ( ret = body_create(&body, mime_part) ) == 0 ) { | 451 | if ( ( ret = body_create(&body, mime_part) ) == 0 ) { |
452 | if ( ( ret = stream_create(&stream, mime_part) ) == 0 ) { | 452 | if ( ( ret = stream_create(&stream, 0, mime_part) ) == 0 ) { |
453 | body_set_size (body, _mime_body_size, mime_part); | 453 | body_set_size (body, _mime_body_size, mime_part); |
454 | stream_set_read(stream, _mime_message_read, mime_part); | 454 | stream_set_read(stream, _mime_message_read, mime_part); |
455 | body_set_stream(body, stream, mime_part); | 455 | body_set_stream(body, stream, mime_part); |
... | @@ -521,7 +521,7 @@ int mime_unencapsulate(mime_t mime, message_t msg, message_t *newmsg) | ... | @@ -521,7 +521,7 @@ int mime_unencapsulate(mime_t mime, message_t msg, message_t *newmsg) |
521 | if ( ( ret = message_create(&(mime_part->msg), mime_part) ) == 0) { | 521 | if ( ( ret = message_create(&(mime_part->msg), mime_part) ) == 0) { |
522 | message_set_header(mime_part->msg, mime_part->hdr, mime_part); | 522 | message_set_header(mime_part->msg, mime_part->hdr, mime_part); |
523 | if ( ( ret = body_create(&body, mime_part) ) == 0 ) { | 523 | if ( ( ret = body_create(&body, mime_part) ) == 0 ) { |
524 | if ( ( ret = stream_create(&stream, mime_part) ) == 0 ) { | 524 | if ( ( ret = stream_create(&stream, 0, mime_part) ) == 0 ) { |
525 | stream_set_read(stream, _mime_message_read, mime_part); | 525 | stream_set_read(stream, _mime_message_read, mime_part); |
526 | body_set_size (body, _mime_body_size, mime_part); | 526 | body_set_size (body, _mime_body_size, mime_part); |
527 | body_set_stream( body, stream, mime_part); | 527 | body_set_stream( body, stream, mime_part); | ... | ... |
... | @@ -17,6 +17,7 @@ | ... | @@ -17,6 +17,7 @@ |
17 | 17 | ||
18 | 18 | ||
19 | #include <stdlib.h> | 19 | #include <stdlib.h> |
20 | #include <string.h> | ||
20 | #include <errno.h> | 21 | #include <errno.h> |
21 | 22 | ||
22 | #include <net0.h> | 23 | #include <net0.h> |
... | @@ -42,7 +43,7 @@ int net_api_create(net_t *net, net_t parent, const char *type) | ... | @@ -42,7 +43,7 @@ int net_api_create(net_t *net, net_t parent, const char *type) |
42 | } | 43 | } |
43 | if ( i == napis ) | 44 | if ( i == napis ) |
44 | return ENOTSUP; | 45 | return ENOTSUP; |
45 | if ( ret = ( _netreg[i].create(&(n->data), &(n->api)) ) != 0 ) | 46 | if ( (ret = ( _netreg[i].create(&(n->data), &(n->api)) )) != 0 ) |
46 | free(n); | 47 | free(n); |
47 | n->parent = parent; | 48 | n->parent = parent; |
48 | n->net_reg = &_netreg[i]; | 49 | n->net_reg = &_netreg[i]; | ... | ... |
... | @@ -154,7 +154,7 @@ static int _tcp_new(void *netdata, net_t parent, void **data) | ... | @@ -154,7 +154,7 @@ static int _tcp_new(void *netdata, net_t parent, void **data) |
154 | tcp->host = NULL; | 154 | tcp->host = NULL; |
155 | tcp->port = -1; | 155 | tcp->port = -1; |
156 | tcp->state = TCP_STATE_INIT; | 156 | tcp->state = TCP_STATE_INIT; |
157 | stream_create(&tcp->stream, tcp); | 157 | stream_create(&tcp->stream, 0, tcp); |
158 | stream_set_read(tcp->stream, _tcp_read, tcp); | 158 | stream_set_read(tcp->stream, _tcp_read, tcp); |
159 | stream_set_write(tcp->stream, _tcp_write, tcp); | 159 | stream_set_write(tcp->stream, _tcp_write, tcp); |
160 | stream_set_fd(tcp->stream, _tcp_get_fd, tcp); | 160 | stream_set_fd(tcp->stream, _tcp_get_fd, tcp); | ... | ... |
... | @@ -61,7 +61,7 @@ int transcode_create(transcoder_t *ptc, char *encoding) | ... | @@ -61,7 +61,7 @@ int transcode_create(transcoder_t *ptc, char *encoding) |
61 | if ( i == NUM_TRANSCODERS ) | 61 | if ( i == NUM_TRANSCODERS ) |
62 | return ENOTSUP; | 62 | return ENOTSUP; |
63 | 63 | ||
64 | stream_create(&tc->ustream, tc ); | 64 | stream_create(&tc->ustream, 0, tc ); |
65 | stream_set_read(tc->ustream, tclist[i].decode_read, tc ); | 65 | stream_set_read(tc->ustream, tclist[i].decode_read, tc ); |
66 | stream_set_write(tc->ustream, tclist[i].encode_write, tc ); | 66 | stream_set_write(tc->ustream, tclist[i].encode_write, tc ); |
67 | tc->destroy = tclist[i].destroy; | 67 | tc->destroy = tclist[i].destroy; | ... | ... |
... | @@ -19,7 +19,6 @@ | ... | @@ -19,7 +19,6 @@ |
19 | #include <registrar.h> | 19 | #include <registrar.h> |
20 | 20 | ||
21 | #include <errno.h> | 21 | #include <errno.h> |
22 | #include <cpystr.h> | ||
23 | #include <stdlib.h> | 22 | #include <stdlib.h> |
24 | #include <string.h> | 23 | #include <string.h> |
25 | #include <errno.h> | 24 | #include <errno.h> |
... | @@ -33,27 +32,6 @@ struct url_registrar _url_pop_registrar = | ... | @@ -33,27 +32,6 @@ struct url_registrar _url_pop_registrar = |
33 | url_pop_create, url_pop_destroy | 32 | url_pop_create, url_pop_destroy |
34 | }; | 33 | }; |
35 | 34 | ||
36 | static int get_auth (const url_pop_t up, char *s, size_t len, size_t *); | ||
37 | |||
38 | static int | ||
39 | get_auth (const url_pop_t up, char *s, size_t len, size_t *n) | ||
40 | { | ||
41 | size_t i; | ||
42 | if (up) | ||
43 | return EINVAL; | ||
44 | i = _cpystr (s, up->auth, len); | ||
45 | if (n) | ||
46 | *n = i; | ||
47 | return 0; | ||
48 | } | ||
49 | |||
50 | int | ||
51 | (url_pop_get_auth) (const url_t url, char *auth, size_t len, size_t *n) | ||
52 | { | ||
53 | return (url) ? | ||
54 | ((url_pop_t)(url->data))->_get_auth(url->data, auth, len, n) : EINVAL; | ||
55 | } | ||
56 | |||
57 | static void | 35 | static void |
58 | url_pop_destroy (url_t *purl) | 36 | url_pop_destroy (url_t *purl) |
59 | { | 37 | { |
... | @@ -64,12 +42,6 @@ url_pop_destroy (url_t *purl) | ... | @@ -64,12 +42,6 @@ url_pop_destroy (url_t *purl) |
64 | free (url->user); | 42 | free (url->user); |
65 | free (url->passwd); | 43 | free (url->passwd); |
66 | free (url->host); | 44 | free (url->host); |
67 | if (url->data) | ||
68 | { | ||
69 | url_pop_t up = url->data; | ||
70 | free (up->auth); | ||
71 | } | ||
72 | free (url->data); | ||
73 | free (url); | 45 | free (url); |
74 | *purl = NULL; | 46 | *purl = NULL; |
75 | } | 47 | } |
... | @@ -77,28 +49,25 @@ url_pop_destroy (url_t *purl) | ... | @@ -77,28 +49,25 @@ url_pop_destroy (url_t *purl) |
77 | 49 | ||
78 | /* | 50 | /* |
79 | POP URL | 51 | POP URL |
80 | pop://<user>;AUTH=<auth>@<host>:<port> | 52 | pop://[<user>;AUTH=<auth>@]<host>[:<port>] |
81 | */ | 53 | */ |
82 | static int | 54 | static int |
83 | url_pop_create (url_t *purl, const char *name) | 55 | url_pop_create (url_t *purl, const char *name) |
84 | { | 56 | { |
85 | const char *host_port, *indexe; | 57 | const char *host_port, *indexe; |
86 | struct url_registrar *ureg = &_url_pop_registrar; | 58 | struct url_registrar *ureg = &_url_pop_registrar; |
87 | size_t len, scheme_len = strlen (ureg->scheme); | 59 | size_t scheme_len = strlen (ureg->scheme); |
88 | url_t url; | 60 | url_t url; |
89 | url_pop_t up; | ||
90 | 61 | ||
91 | /* reject the obvious */ | 62 | /* reject the obvious */ |
92 | if (name == NULL || strncmp (ureg->scheme, name, scheme_len) != 0 | 63 | if (name == NULL || strncmp (ureg->scheme, name, scheme_len) != 0) |
93 | || (host_port = strchr (name, '@')) == NULL | 64 | return EINVAL; |
94 | || (len = strlen (name)) < 9 /* 6(scheme)+1(user)+1(@)+1(host)*/) | ||
95 | return ENOMEM; | ||
96 | 65 | ||
97 | /* do I need to decode url encoding '% hex hex' ? */ | 66 | /* do I need to decode url encoding '% hex hex' ? */ |
98 | 67 | ||
99 | url = calloc(1, sizeof (*url)); | 68 | url = calloc(1, sizeof (*url)); |
100 | url->data = up = calloc(1, sizeof(*up)); | 69 | if (url == NULL) |
101 | up->_get_auth = get_auth; | 70 | return ENOMEM; |
102 | 71 | ||
103 | /* TYPE */ | 72 | /* TYPE */ |
104 | url->_create = _url_pop_registrar._create; | 73 | url->_create = _url_pop_registrar._create; |
... | @@ -114,24 +83,22 @@ url_pop_create (url_t *purl, const char *name) | ... | @@ -114,24 +83,22 @@ url_pop_create (url_t *purl, const char *name) |
114 | 83 | ||
115 | name += scheme_len; /* pass the scheme */ | 84 | name += scheme_len; /* pass the scheme */ |
116 | 85 | ||
86 | host_port = strchr (name, '@'); | ||
87 | if (host_port == NULL) | ||
88 | host_port= name; | ||
89 | |||
117 | /* looking for "user;auth=auth-enc" */ | 90 | /* looking for "user;auth=auth-enc" */ |
118 | for (indexe = name; indexe != host_port; indexe++) | 91 | for (indexe = name; indexe != host_port; indexe++) |
119 | { | 92 | { |
120 | /* Auth ? */ | 93 | /* Auth ? */ |
121 | if (*indexe == ';') | 94 | if (*indexe == ';') |
122 | { | 95 | { |
123 | /* make sure it the token */ | 96 | /* make sure it's the token */ |
124 | if (strncasecmp(indexe + 1, "auth=", 5) == 0) | 97 | if (strncasecmp(indexe + 1, "auth=", 5) == 0) |
125 | break; | 98 | break; |
126 | } | 99 | } |
127 | } | 100 | } |
128 | 101 | ||
129 | if (indexe == name) | ||
130 | { | ||
131 | url_pop_destroy (&url); | ||
132 | return -1; | ||
133 | } | ||
134 | |||
135 | /* USER */ | 102 | /* USER */ |
136 | url->user = malloc(indexe - name + 1); | 103 | url->user = malloc(indexe - name + 1); |
137 | if (url->user == NULL) | 104 | if (url->user == NULL) |
... | @@ -142,29 +109,29 @@ url_pop_create (url_t *purl, const char *name) | ... | @@ -142,29 +109,29 @@ url_pop_create (url_t *purl, const char *name) |
142 | ((char *)memcpy(url->user, name, indexe - name))[indexe - name] = '\0'; | 109 | ((char *)memcpy(url->user, name, indexe - name))[indexe - name] = '\0'; |
143 | 110 | ||
144 | /* AUTH */ | 111 | /* AUTH */ |
145 | if ((host_port - indexe) <= 6 /*strlen(";AUTH=")*/) | 112 | if (indexe == host_port) |
146 | { | 113 | { |
147 | /* Use default AUTH '*' */ | 114 | /* Use default AUTH '*' */ |
148 | up->auth = malloc (1 + 1); | 115 | url->passwd = malloc (1 + 1); |
149 | if (up->auth) | 116 | if (url->passwd) |
150 | { | 117 | { |
151 | up->auth[0] = '*'; | 118 | url->passwd[0] = '*'; |
152 | up->auth[1] = '\0'; | 119 | url->passwd[1] = '\0'; |
153 | } | 120 | } |
154 | } | 121 | } |
155 | else | 122 | else |
156 | { | 123 | { |
157 | /* move pass AUTH= */ | 124 | /* move pass AUTH= */ |
158 | indexe += 6; | 125 | indexe += 6; |
159 | up->auth = malloc (host_port - indexe + 1); | 126 | url->passwd = malloc (host_port - indexe + 1); |
160 | if (up->auth) | 127 | if (url->passwd) |
161 | { | 128 | { |
162 | ((char *)memcpy (up->auth, indexe, host_port - indexe)) | 129 | ((char *)memcpy (url->passwd, indexe, host_port - indexe)) |
163 | [host_port - indexe] = '\0'; | 130 | [host_port - indexe] = '\0'; |
164 | } | 131 | } |
165 | } | 132 | } |
166 | 133 | ||
167 | if (up->auth == NULL) | 134 | if (url->passwd == NULL) |
168 | { | 135 | { |
169 | url_pop_destroy (&url); | 136 | url_pop_destroy (&url); |
170 | return -1; | 137 | return -1; | ... | ... |
-
Please register or sign in to post a comment