Commit ff8d17bd ff8d17bdc5d74ef0a692271ac12dbed6c4409fda by Alain Magloire

_cpystr.c chewurl.c cpystr.h test_url url.c url.h url_mbox.c

 	url_mdir.c url_pop.c url_pop.h url_unix.c urli.c
tight things up.
1 parent 3f5059d8
1 /* GNU mailutils - a suite of utilities for electronic mail 1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Library Public License as published by 5 it under the terms of the GNU General Library Public License as published by
...@@ -17,11 +17,12 @@ ...@@ -17,11 +17,12 @@
17 17
18 #include <cpystr.h> 18 #include <cpystr.h>
19 #include <string.h> 19 #include <string.h>
20 #include <errno.h>
20 21
21 int 22 size_t
22 _cpystr (char *dst, const char *src, unsigned int size) 23 _cpystr (char *dst, const char *src, size_t size)
23 { 24 {
24 unsigned int len = src ? strlen (src) : 0 ; 25 size_t len = src ? strlen (src) : 0 ;
25 26
26 if (dst == NULL || size == 0) 27 if (dst == NULL || size == 0)
27 { 28 {
......
...@@ -13,6 +13,7 @@ main () ...@@ -13,6 +13,7 @@ main ()
13 char buffer[1024]; 13 char buffer[1024];
14 char str[1024]; 14 char str[1024];
15 struct url_type *utype; 15 struct url_type *utype;
16 size_t len = sizeof (buffer);
16 17
17 url_list_mtype (&utype, &status); 18 url_list_mtype (&utype, &status);
18 for (i = 0; i < status; i++) 19 for (i = 0; i < status; i++)
...@@ -26,30 +27,36 @@ main () ...@@ -26,30 +27,36 @@ main ()
26 { 27 {
27 str[strlen(str) - 1] = '\0'; /* chop newline */ 28 str[strlen(str) - 1] = '\0'; /* chop newline */
28 status = url_init (&u, str); 29 status = url_init (&u, str);
29 if (status == -1) { 30 if (status != 0) {
30 printf("%s --> FAILED\n", str); 31 printf("%s --> FAILED\n", str);
31 continue; 32 continue;
32 } 33 }
33 printf("%s --> SUCCESS\n", str); 34 printf("%s --> SUCCESS\n", str);
34 35
35 url_get_scheme (u, buffer, sizeof (buffer)); 36 url_get_scheme (u, buffer, len, NULL);
36 printf("\tscheme <%s>\n", buffer); 37 printf("\tscheme <%s>\n", buffer);
37 38
38 url_get_user (u, buffer, sizeof (buffer)); 39 url_get_user (u, buffer, len, NULL);
39 printf("\tuser <%s>\n", buffer); 40 printf("\tuser <%s>\n", buffer);
40 41
41 url_get_passwd (u, buffer, sizeof (buffer)); 42 url_get_passwd (u, buffer, len, NULL);
42 printf("\tpasswd <%s>\n", buffer); 43 printf("\tpasswd <%s>\n", buffer);
43 44
44 url_pop_get_auth (u, buffer, sizeof (buffer)); 45 //url_pop_get_auth (u, buffer, len, NULL);
45 printf("\tauth <%s>\n", buffer); 46 //printf("\tauth <%s>\n", buffer);
46 47
47 url_get_host (u, buffer, sizeof (buffer)); 48 url_get_host (u, buffer, len, NULL);
48 printf("\thost <%s>\n", buffer); 49 printf("\thost <%s>\n", buffer);
49 50
50 url_get_port (u, &port); 51 url_get_port (u, &port);
51 printf("\tport %ld\n", port); 52 printf("\tport %ld\n", port);
52 53
54 url_get_path (u, buffer, len, NULL);
55 printf("\tpath <%s>\n", buffer);
56
57 url_get_query (u, buffer, len, NULL);
58 printf("\tquery <%s>\n", buffer);
59
53 url_destroy (&u); 60 url_destroy (&u);
54 } 61 }
55 return 0; 62 return 0;
......
1 /* GNU mailutils - a suite of utilities for electronic mail 1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Library Public License as published by 5 it under the terms of the GNU General Library Public License as published by
...@@ -18,13 +18,23 @@ ...@@ -18,13 +18,23 @@
18 #ifndef _CPYSTR_H 18 #ifndef _CPYSTR_H
19 #define _CPYSTR_H 19 #define _CPYSTR_H
20 20
21 #include <sys/types.h>
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
21 #ifndef __P 27 #ifndef __P
22 # ifdef __STDC__ 28 # if __STDC__
23 # define __P(x) x 29 # define __P(x) x
24 # else 30 # else
25 # define __P(x) 31 # define __P(x)
26 # endif 32 # endif
27 #endif 33 #endif
28 extern int _cpystr __P ((char *dst, const char *src, unsigned int size)); 34 extern size_t _cpystr __P ((char *dst, const char *src, size_t size));
35
36 #ifdef __cplusplus
37 }
38 #endif
29 39
30 #endif 40 #endif
......
1 file:///usr/spool/alain
1 pop://<user>;auth=<auth>@<host>:<port> 2 pop://<user>;auth=<auth>@<host>:<port>
2 pop://rg@mailsrv.qualcomm.com 3 pop://rg@mailsrv.qualcomm.com
3 pop://rg;AUTH=+APOP@mail.eudora.com:8110 4 pop://rg;AUTH=+APOP@mail.eudora.com:8110
...@@ -6,3 +7,9 @@ pop://me ...@@ -6,3 +7,9 @@ pop://me
6 pop:/joe@qnx.com 7 pop:/joe@qnx.com
7 pop://;Auth=+me@joe 8 pop://;Auth=+me@joe
8 pop://alain;ATU=me@joe 9 pop://alain;ATU=me@joe
10
11 unix:///var/mail/alain
12 unix://usr/spool/mail
13 file:///usr/spool/alain
14 mdir://home/alain
15 mmdf://u
......
1 /* GNU mailutils - a suite of utilities for electronic mail 1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Library Public License as published by 5 it under the terms of the GNU General Library Public License as published by
...@@ -29,13 +29,19 @@ ...@@ -29,13 +29,19 @@
29 #include <errno.h> 29 #include <errno.h>
30 30
31 /* Forward prototypes */ 31 /* Forward prototypes */
32 static int get_scheme (const url_t, char *, int); 32 static int get_scheme (const url_t, char *, size_t, size_t *);
33 static int get_user (const url_t, char *, int); 33 static int get_mscheme (const url_t, char **, size_t *);
34 static int get_passwd (const url_t, char *, int); 34 static int get_user (const url_t, char *, size_t, size_t *);
35 static int get_host (const url_t, char *, int); 35 static int get_muser (const url_t, char **, size_t *);
36 static int get_passwd (const url_t, char *, size_t, size_t *);
37 static int get_mpasswd (const url_t, char **, size_t *);
38 static int get_host (const url_t, char *, size_t, size_t *);
39 static int get_mhost (const url_t, char **, size_t *);
36 static int get_port (const url_t, long *); 40 static int get_port (const url_t, long *);
37 static int get_path (const url_t, char *, int); 41 static int get_path (const url_t, char *, size_t, size_t *);
38 static int get_query (const url_t, char *, int); 42 static int get_mpath (const url_t, char **, size_t *);
43 static int get_query (const url_t, char *, size_t, size_t *);
44 static int get_mquery (const url_t, char **, size_t *);
39 static int get_id (const url_t, int *id); 45 static int get_id (const url_t, int *id);
40 46
41 /* 47 /*
...@@ -94,34 +100,42 @@ url_remove_type (const struct url_type *utype) ...@@ -94,34 +100,42 @@ url_remove_type (const struct url_type *utype)
94 } 100 }
95 101
96 int 102 int
97 url_list_type (struct url_type *list, int n) 103 url_list_type (struct url_type *list, size_t len, size_t *n)
98 { 104 {
99 struct url_builtin *current; 105 struct url_builtin *current;
100 int i; 106 size_t i = 0;
101 for (i = 0, current = url_builtin->next; current != url_builtin; 107 for (i = 0, current = url_builtin->next; current != url_builtin;
102 current = current->next, i++) 108 current = current->next, i++)
103 { 109 {
104 if (list) 110 if (list)
105 if (i < n) 111 {
112 if (i < len)
106 list[i] = *(current->utype); 113 list[i] = *(current->utype);
114 else
115 break;
107 } 116 }
108 return i; 117 }
118 if (n)
119 *n = i;
120 return 0;
109 } 121 }
110 122
111 int 123 int
112 url_list_mtype (struct url_type **mlist, int *n) 124 url_list_mtype (struct url_type **mlist, size_t *n)
113 { 125 {
114 struct url_type *utype; 126 struct url_type *utype;
115 int i; 127 size_t i;
116 128
117 if ((i = url_list_type (NULL, 0)) <= 0 129 url_list_type (NULL, 0, &i);
118 || (utype = calloc (i, sizeof (*utype))) == NULL) 130 utype = calloc (i, sizeof (*utype));
131 if (utype == NULL)
119 { 132 {
120 return -1; 133 return ENOMEM;
121 } 134 }
122 135
123 *mlist = utype; 136 *mlist = utype;
124 return *n = url_list_type (utype, i); 137 url_list_type (utype, i, n);
138 return 0;
125 } 139 }
126 140
127 int 141 int
...@@ -159,18 +173,30 @@ url_init (url_t * purl, const char *name) ...@@ -159,18 +173,30 @@ url_init (url_t * purl, const char *name)
159 url->utype = utype; 173 url->utype = utype;
160 if (url->_get_scheme == NULL) 174 if (url->_get_scheme == NULL)
161 url->_get_scheme = get_scheme; 175 url->_get_scheme = get_scheme;
176 if (url->_get_mscheme == NULL)
177 url->_get_mscheme = get_mscheme;
162 if (url->_get_user == NULL) 178 if (url->_get_user == NULL)
163 url->_get_user = get_user; 179 url->_get_user = get_user;
180 if (url->_get_muser == NULL)
181 url->_get_muser = get_muser;
164 if (url->_get_passwd == NULL) 182 if (url->_get_passwd == NULL)
165 url->_get_passwd = get_passwd; 183 url->_get_passwd = get_passwd;
184 if (url->_get_mpasswd == NULL)
185 url->_get_mpasswd = get_mpasswd;
166 if (url->_get_host == NULL) 186 if (url->_get_host == NULL)
167 url->_get_host = get_host; 187 url->_get_host = get_host;
188 if (url->_get_mhost == NULL)
189 url->_get_mhost = get_mhost;
168 if (url->_get_port == NULL) 190 if (url->_get_port == NULL)
169 url->_get_port = get_port; 191 url->_get_port = get_port;
170 if (url->_get_path == NULL) 192 if (url->_get_path == NULL)
171 url->_get_path = get_path; 193 url->_get_path = get_path;
194 if (url->_get_mpath == NULL)
195 url->_get_mpath = get_mpath;
172 if (url->_get_query == NULL) 196 if (url->_get_query == NULL)
173 url->_get_query = get_query; 197 url->_get_query = get_query;
198 if (url->_get_mquery == NULL)
199 url->_get_mquery = get_mquery;
174 if (url->_get_id == NULL) 200 if (url->_get_id == NULL)
175 url->_get_id = get_id; 201 url->_get_id = get_id;
176 } 202 }
...@@ -193,29 +219,117 @@ url_destroy (url_t *purl) ...@@ -193,29 +219,117 @@ url_destroy (url_t *purl)
193 /* Simple stub functions they all call _cpystr */ 219 /* Simple stub functions they all call _cpystr */
194 220
195 static int 221 static int
196 get_scheme (const url_t u, char * s, int n) 222 get_scheme (const url_t u, char *s, size_t len, size_t *n)
197 { 223 {
198 return _cpystr (s, u->scheme, n); 224 size_t i;
225 if (u == NULL)
226 return EINVAL;
227 i = _cpystr (s, u->scheme, len);
228 if (n)
229 *n = i;
230 return 0;
231 }
232 static int
233 get_mscheme (const url_t u, char **s, size_t *n)
234 {
235 size_t i;
236 if (u == NULL || s == NULL || u->_get_scheme (u, NULL, 0, &i) != 0)
237 {
238 return EINVAL;
239 }
240 *s = malloc (++i);
241 if (*s == NULL)
242 {
243 return ENOMEM;
244 }
245 u->_get_scheme (u, *s, 0, n);
246 return 0;
199 } 247 }
200 248
201 static int 249 static int
202 get_user (const url_t u, char * s, int n) 250 get_user (const url_t u, char *s, size_t len, size_t *n)
203 { 251 {
204 return _cpystr (s, u->user, n); 252 size_t i;
253 if (u == NULL)
254 return EINVAL;
255 i = _cpystr (s, u->user, len);
256 if (n)
257 *n = i;
258 return 0;
259 }
260 static int
261 get_muser (const url_t u, char **s, size_t *n)
262 {
263 size_t i;
264 if (u == NULL || s == NULL || u->_get_user (u, NULL, 0, &i) != 0)
265 {
266 return EINVAL;
267 }
268 *s = malloc (++i);
269 if (*s == NULL)
270 {
271 return ENOMEM;
272 }
273 u->_get_user (u, *s, i, n);
274 return 0;
205 } 275 }
206 276
207 /* FIXME: We should not store passwd in clear, but rather 277 /* FIXME: We should not store passwd in clear, but rather
208 have a simple encoding, and decoding mechanism */ 278 have a simple encoding, and decoding mechanism */
209 static int 279 static int
210 get_passwd (const url_t u, char * s, int n) 280 get_passwd (const url_t u, char *s, size_t len, size_t *n)
211 { 281 {
212 return _cpystr (s, u->passwd, n); 282 size_t i;
283 if (u == NULL)
284 return EINVAL;
285 i = _cpystr (s, u->passwd, len);
286 if (n)
287 *n = i;
288 return 0;
289 }
290 static int
291 get_mpasswd (const url_t u, char **s, size_t *n)
292 {
293 size_t i;
294 if (u == NULL || s == NULL || u->_get_passwd (u, NULL, 0, &i) != 0)
295 {
296 return EINVAL;
297 }
298 *s = malloc (++i);
299 if (*s == NULL)
300 {
301 return ENOMEM;
302 }
303 u->_get_passwd (u, *s, i, n);
304 return 0;
213 } 305 }
214 306
215 static int 307 static int
216 get_host (const url_t u, char * s, int n) 308 get_host (const url_t u, char *s, size_t len, size_t *n)
217 { 309 {
218 return _cpystr (s, u->host, n); 310 size_t i;
311 if (u == NULL)
312 return EINVAL;
313 i = _cpystr (s, u->host, len);
314 if (n)
315 *n = i;
316 return 0;
317 }
318 static int
319 get_mhost (const url_t u, char **s, size_t *n)
320 {
321 size_t i;
322 if (u == NULL || s == NULL || u->_get_host (u, NULL, 0, &i) != 0)
323 {
324 return EINVAL;
325 }
326 *s = malloc (++i);
327 if (*s == NULL)
328 {
329 return ENOMEM;
330 }
331 u->_get_host (u, *s, i, n);
332 return 0;
219 } 333 }
220 334
221 static int 335 static int
...@@ -226,15 +340,59 @@ get_port (const url_t u, long * p) ...@@ -226,15 +340,59 @@ get_port (const url_t u, long * p)
226 } 340 }
227 341
228 static int 342 static int
229 get_path (const url_t u, char * s, int n) 343 get_path (const url_t u, char *s, size_t len, size_t *n)
344 {
345 size_t i;
346 if (u == NULL)
347 return EINVAL;
348 i = _cpystr(s, u->path, len);
349 if (n)
350 *n = i;
351 return 0;
352 }
353 static int
354 get_mpath (const url_t u, char **s, size_t *n)
230 { 355 {
231 return _cpystr(s, u->path, n); 356 size_t i;
357 if (u == NULL || s == NULL || u->_get_path (u, NULL, 0, &i) != 0)
358 {
359 return EINVAL;
360 }
361 *s = malloc (++i);
362 if (*s == NULL)
363 {
364 return ENOMEM;
365 }
366 u->_get_path (u, *s, i, n);
367 return 0;
232 } 368 }
233 369
234 static int 370 static int
235 get_query (const url_t u, char * s, int n) 371 get_query (const url_t u, char *s, size_t len, size_t *n)
236 { 372 {
237 return _cpystr(s, u->query, n); 373 size_t i;
374 if (u == NULL)
375 return EINVAL;
376 i = _cpystr(s, u->query, len);
377 if (n)
378 *n = i;
379 return 0;
380 }
381 static int
382 get_mquery (const url_t u, char **s, size_t *n)
383 {
384 size_t i;
385 if (u == NULL || s == NULL || u->_get_query (u, NULL, 0, &i) != 0)
386 {
387 return EINVAL;
388 }
389 *s = malloc (++i);
390 if (*s == NULL)
391 {
392 return ENOMEM;
393 }
394 u->_get_query (u, *s, i, n);
395 return 0;
238 } 396 }
239 397
240 static int 398 static int
......
1 /* GNU mailutils - a suite of utilities for electronic mail 1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Library General Public License as published by 5 it under the terms of the GNU Library General Public License as published by
...@@ -18,12 +18,15 @@ ...@@ -18,12 +18,15 @@
18 #ifndef _URL_H 18 #ifndef _URL_H
19 #define _URL_H 1 19 #define _URL_H 1
20 20
21 #include <sys/types.h>
22 #include <stdlib.h>
23
21 #ifdef __cplusplus 24 #ifdef __cplusplus
22 extern "C" { 25 extern "C" {
23 #endif 26 #endif
24 27
25 #ifndef __P 28 #ifndef __P
26 # ifdef __STDC__ 29 # if __STDC__
27 # define __P(args) args 30 # define __P(args) args
28 # else 31 # else
29 # define __P(args) () 32 # define __P(args) ()
...@@ -37,7 +40,7 @@ typedef struct _url * url_t; ...@@ -37,7 +40,7 @@ typedef struct _url * url_t;
37 struct url_type 40 struct url_type
38 { 41 {
39 char *scheme; 42 char *scheme;
40 int len; 43 size_t len;
41 char *description; 44 char *description;
42 int id; 45 int id;
43 int (*_init) __P ((url_t *, const char * name)); 46 int (*_init) __P ((url_t *, const char * name));
...@@ -59,21 +62,40 @@ struct _url ...@@ -59,21 +62,40 @@ struct _url
59 const struct url_type * utype; 62 const struct url_type * utype;
60 63
61 /* Methods */ 64 /* Methods */
62 int (*_get_scheme) __P ((const url_t, char *scheme, int len)); 65 int (*_get_scheme) __P ((const url_t, char *scheme,
63 int (*_get_user) __P ((const url_t, char *user, int len)); 66 size_t len, size_t *n));
64 int (*_get_passwd) __P ((const url_t, char *passwd, int len)); 67 int (*_get_mscheme) __P ((const url_t, char **, size_t *n));
65 int (*_get_host) __P ((const url_t, char *host, int len)); 68
69 int (*_get_user) __P ((const url_t, char *user,
70 size_t len, size_t *n));
71 int (*_get_muser) __P ((const url_t, char **, size_t *n));
72
73 int (*_get_passwd) __P ((const url_t, char *passwd,
74 size_t len, size_t *n));
75 int (*_get_mpasswd) __P ((const url_t, char **, size_t *n));
76
77 int (*_get_host) __P ((const url_t, char *host,
78 size_t len, size_t *n));
79 int (*_get_mhost) __P ((const url_t, char **, size_t *n));
80
66 int (*_get_port) __P ((const url_t, long *port)); 81 int (*_get_port) __P ((const url_t, long *port));
67 int (*_get_path) __P ((const url_t, char *path, int len)); 82
68 int (*_get_query) __P ((const url_t, char *query, int len)); 83 int (*_get_path) __P ((const url_t, char *path,
84 size_t len, size_t *n));
85 int (*_get_mpath) __P ((const url_t, char **, size_t *n));
86
87 int (*_get_query) __P ((const url_t, char *query,
88 size_t len, size_t *n));
89 int (*_get_mquery) __P ((const url_t, char **, size_t *n));
90
69 int (*_get_id) __P ((const url_t, int *id)); 91 int (*_get_id) __P ((const url_t, int *id));
70 }; 92 };
71 93
72 extern int url_init __P ((url_t *, const char *name)); 94 extern int url_init __P ((url_t *, const char *name));
73 extern void url_destroy __P ((url_t *)); 95 extern void url_destroy __P ((url_t *));
74 96
75 extern int url_list_type __P ((struct url_type list[], int len)); 97 extern int url_list_type __P ((struct url_type list[], size_t l, size_t *n));
76 extern int url_list_mtype __P ((struct url_type *mlist[], int *len)); 98 extern int url_list_mtype __P ((struct url_type **mlist, size_t *n));
77 extern int url_add_type __P ((struct url_type *utype)); 99 extern int url_add_type __P ((struct url_type *utype));
78 extern int url_remove_type __P ((const struct url_type *utype)); 100 extern int url_remove_type __P ((const struct url_type *utype));
79 101
...@@ -83,23 +105,41 @@ extern int url_remove_type __P ((const struct url_type *utype)); ...@@ -83,23 +105,41 @@ extern int url_remove_type __P ((const struct url_type *utype));
83 # define INLINE 105 # define INLINE
84 #endif 106 #endif
85 107
86 extern INLINE int url_get_scheme __P ((const url_t, char *scheme, int len)); 108 extern INLINE int url_get_scheme __P ((const url_t, char *sch,
87 extern INLINE int url_get_user __P ((const url_t, char *user, int len)); 109 size_t, size_t *));
88 extern INLINE int url_get_passwd __P ((const url_t, char *passwd, int len)); 110 extern INLINE int url_get_mscheme __P ((const url_t, char **, size_t *));
89 extern INLINE int url_get_host __P ((const url_t, char *host, int len)); 111 extern INLINE int url_get_user __P ((const url_t, char *usr,
112 size_t, size_t *));
113 extern INLINE int url_get_muser __P ((const url_t, char **, size_t *));
114 extern INLINE int url_get_passwd __P ((const url_t, char *passwd,
115 size_t, size_t *));
116 extern INLINE int url_get_mpasswd __P ((const url_t, char **, size_t *));
117 extern INLINE int url_get_host __P ((const url_t, char *host,
118 size_t, size_t *));
119 extern INLINE int url_get_mhost __P ((const url_t, char **, size_t *));
90 extern INLINE int url_get_port __P ((const url_t, long *port)); 120 extern INLINE int url_get_port __P ((const url_t, long *port));
91 extern INLINE int url_get_path __P ((const url_t, char *path, int len)); 121 extern INLINE int url_get_path __P ((const url_t, char *path,
92 extern INLINE int url_get_query __P ((const url_t, char *query, int len)); 122 size_t, size_t *));
123 extern INLINE int url_get_mpath __P ((const url_t, char **, size_t *));
124 extern INLINE int url_get_query __P ((const url_t, char *qeury,
125 size_t, size_t *));
126 extern INLINE int url_get_mquery __P ((const url_t, char **, size_t *));
93 extern INLINE int url_get_id __P ((const url_t, int *id)); 127 extern INLINE int url_get_id __P ((const url_t, int *id));
94 128
95 #ifdef URL_MACROS 129 #ifdef URL_MACROS
96 # define url_get_scheme(url, scheme, n) url->_get_scheme (url, scheme, n) 130 # define url_get_scheme(url, scheme, l, n) url->_get_scheme (url, scheme,l, n)
97 # define url_get_user(url, user, n) url->_get_user (url, user, n) 131 # define url_get_mscheme(url, mscheme, n) url->_get_mscheme (url, mscheme, n)
98 # define url_get_passwd(url, passwd, n) url->_get_passwd (url, passwd, n) 132 # define url_get_user(url, user, l, n) url->_get_user (url, user, l, n)
99 # define url_get_host(url, host, n) url->_get_host (url, host, n) 133 # define url_get_muser(url, muser, n) url->_get_muser (url, muser, n)
134 # define url_get_passwd(url, passwd, l, n) url->_get_passwd (url, passwd, l, n)
135 # define url_get_mpasswd(url, mpasswd, n) url->_get_mpasswd (url, mpasswd, n)
136 # define url_get_host(url, host, l, n) url->_get_host (url, host, l, n)
137 # define url_get_mhost(url, mhost, n) url->_get_mhost (url, mhost, n)
100 # define url_get_port(url, port) url->_get_port (url, port) 138 # define url_get_port(url, port) url->_get_port (url, port)
101 # define url_get_path(url, path, n) url->_get_path (url, path, n) 139 # define url_get_path(url, path, l, n) url->_get_path (url, path, l, n)
102 # define url_get_query(url, query, n) url->_get_query (url, query, n) 140 # define url_get_mpath(url, mpath, n) url->_get_mpath (url, mpath, n)
141 # define url_get_query(url, query, l, n) url->_get_query (url, query, l, n)
142 # define url_get_mquery(url, mquery, n) url->_get_mquery (url, mquery, n)
103 # define url_get_id(url, id) url->_get_id (url, id) 143 # define url_get_id(url, id) url->_get_id (url, id)
104 #endif /* URL_MACROS */ 144 #endif /* URL_MACROS */
105 145
......
1 /* GNU mailutils - a suite of utilities for electronic mail 1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Library General Public License as published by 5 it under the terms of the GNU Library General Public License as published by
...@@ -50,7 +50,7 @@ int ...@@ -50,7 +50,7 @@ int
50 url_mbox_init (url_t *purl, const char *name) 50 url_mbox_init (url_t *purl, const char *name)
51 { 51 {
52 url_t url; 52 url_t url;
53 int len; 53 size_t len;
54 struct url_type *utype = &_url_mbox_type; 54 struct url_type *utype = &_url_mbox_type;
55 55
56 /* reject the obvious */ 56 /* reject the obvious */
......
1 /* GNU mailutils - a suite of utilities for electronic mail 1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Library General Public License as published by 5 it under the terms of the GNU Library General Public License as published by
...@@ -50,7 +50,7 @@ int ...@@ -50,7 +50,7 @@ int
50 url_maildir_init (url_t *purl, const char *name) 50 url_maildir_init (url_t *purl, const char *name)
51 { 51 {
52 url_t url; 52 url_t url;
53 int len; 53 size_t len;
54 struct url_type *utype = &_url_maildir_type; 54 struct url_type *utype = &_url_maildir_type;
55 55
56 /* reject the obvious */ 56 /* reject the obvious */
......
1 /* GNU mailutils - a suite of utilities for electronic mail 1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Library General Public License as published by 5 it under the terms of the GNU Library General Public License as published by
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
19 #include <cpystr.h> 19 #include <cpystr.h>
20 #include <stdlib.h> 20 #include <stdlib.h>
21 #include <string.h> 21 #include <string.h>
22 #include <errno.h>
22 23
23 struct url_type _url_pop_type = 24 struct url_type _url_pop_type =
24 { 25 {
...@@ -28,18 +29,25 @@ struct url_type _url_pop_type = ...@@ -28,18 +29,25 @@ struct url_type _url_pop_type =
28 url_pop_init, url_pop_destroy 29 url_pop_init, url_pop_destroy
29 }; 30 };
30 31
31 static int get_auth (const url_pop_t up, char *s, int n); 32 static int get_auth (const url_pop_t up, char *s, size_t len, size_t *);
32 33
33 static int 34 static int
34 get_auth (const url_pop_t up, char * s, int n) 35 get_auth (const url_pop_t up, char *s, size_t len, size_t *n)
35 { 36 {
36 return _cpystr (s, up->auth, n); 37 size_t i;
38 if (up)
39 return EINVAL;
40 i = _cpystr (s, up->auth, len);
41 if (n)
42 *n = i;
43 return 0;
37 } 44 }
38 45
39 int 46 int
40 (url_pop_get_auth) (const url_t url, char * auth, int n) 47 (url_pop_get_auth) (const url_t url, char *auth, size_t len, size_t *n)
41 { 48 {
42 return ((url_pop_t) (url->data))->_get_auth(url->data, auth, n); 49 return (url) ? ((url_pop_t)(url->data))->_get_auth(url->data, auth, len, n)
50 : EINVAL;
43 } 51 }
44 52
45 void 53 void
......
1 /* GNU mailutils - a suite of utilities for electronic mail 1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Library General Public License as published by 5 it under the terms of the GNU Library General Public License as published by
...@@ -41,7 +41,7 @@ struct _url_pop ...@@ -41,7 +41,7 @@ struct _url_pop
41 /* we use the fields from url_t */ 41 /* we use the fields from url_t */
42 /* user, passwd, host, port */ 42 /* user, passwd, host, port */
43 char * auth; 43 char * auth;
44 int (*_get_auth) __P ((const url_pop_t, char *, int)); 44 int (*_get_auth) __P ((const url_pop_t, char *, size_t, size_t *));
45 }; 45 };
46 46
47 extern int url_pop_init __P ((url_t *, const char *name)); 47 extern int url_pop_init __P ((url_t *, const char *name));
...@@ -60,12 +60,12 @@ extern struct url_type _url_pop_type; ...@@ -60,12 +60,12 @@ extern struct url_type _url_pop_type;
60 #endif 60 #endif
61 61
62 /* pop*/ 62 /* pop*/
63 extern int url_pop_get_auth (const url_t, char *, int); 63 extern int url_pop_get_auth (const url_t, char *, size_t, size_t *);
64 64
65 #ifdef MU_URL_MACROS 65 #ifdef MU_URL_MACROS
66 /* pop */ 66 /* pop */
67 # define url_pop_get_auth(url, auth, n) (((url_pop_t) \ 67 # define url_pop_get_auth(url, auth, l, n) (((url_pop_t) \
68 (url->data))->_get_auth(url->data, auth, n)) 68 (url->data))->_get_auth(url->data, auth, l, n))
69 #endif /* MU_URL_MACROS */ 69 #endif /* MU_URL_MACROS */
70 70
71 #ifdef __cplusplus 71 #ifdef __cplusplus
......
1 /* GNU mailutils - a suite of utilities for electronic mail 1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Library General Public License as published by 5 it under the terms of the GNU Library General Public License as published by
...@@ -50,7 +50,7 @@ int ...@@ -50,7 +50,7 @@ int
50 url_unix_init (url_t *purl, const char *name) 50 url_unix_init (url_t *purl, const char *name)
51 { 51 {
52 url_t url; 52 url_t url;
53 int len; 53 size_t len;
54 struct url_type *utype = &_url_unix_type; 54 struct url_type *utype = &_url_unix_type;
55 55
56 /* reject the obvious */ 56 /* reject the obvious */
......
1 /* GNU mailutils - a suite of utilities for electronic mail 1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Library Public License as published by 5 it under the terms of the GNU General Library Public License as published by
...@@ -16,35 +16,74 @@ ...@@ -16,35 +16,74 @@
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ 16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17 17
18 #include <url.h> 18 #include <url.h>
19 #include <errno.h>
19 20
20 int 21 int (url_get_scheme) (const url_t url, char *scheme, size_t len, size_t *n)
21 (url_get_scheme) (const url_t url, char *scheme, int n) 22 {
22 { return url->_get_scheme(url, scheme, n); } 23 return (url) ? url->_get_scheme(url, scheme, len, n) : EINVAL;
24 }
23 25
24 int 26 int (url_get_mscheme) (const url_t url, char **mscheme, size_t *n)
25 (url_get_user) (const url_t url, char *user, int n) 27 {
26 { return url->_get_user(url, user, n); } 28 return (url) ? url->_get_mscheme(url, mscheme, n) : EINVAL;
29 }
27 30
28 int 31 int (url_get_user) (const url_t url, char *user, size_t len, size_t *n)
29 (url_get_passwd) (const url_t url, char *passwd, int n) 32 {
30 { return url->_get_passwd(url, passwd, n); } 33 return (url) ? url->_get_user(url, user, len, n) : EINVAL;
34 }
31 35
32 int 36 int (url_get_muser) (const url_t url, char **muser, size_t *n)
33 (url_get_host) (const url_t url, char *host, int n) 37 {
34 { return url->_get_host(url, host, n); } 38 return (url) ? url->_get_muser(url, muser, n) : EINVAL;
39 }
35 40
36 int 41 int (url_get_passwd) (const url_t url, char *passwd, size_t len, size_t *n)
37 (url_get_port) (const url_t url, long *port) 42 {
38 { return url->_get_port(url, port); } 43 return (url) ? url->_get_passwd(url, passwd, len, n) : EINVAL;
44 }
39 45
40 int 46 int (url_get_mpasswd) (const url_t url, char **mpasswd, size_t *n)
41 (url_get_path) (const url_t url, char *path, int n) 47 {
42 { return url->_get_path(url, path, n); } 48 return (url) ? url->_get_mpasswd(url, mpasswd, n) : EINVAL;
49 }
43 50
44 int 51 int (url_get_host) (const url_t url, char *host, size_t len, size_t *n)
45 (url_get_query) (const url_t url, char *query, int n) 52 {
46 { return url->_get_query(url, query, n); } 53 return (url) ? url->_get_host(url, host, len, n) : EINVAL;
54 }
47 55
48 int 56 int (url_get_mhost) (const url_t url, char **mhost, size_t *n)
49 (url_get_id) (const url_t url, int *id) 57 {
50 { return url->_get_id (url, id); } 58 return (url) ? url->_get_mhost(url, mhost, n) : EINVAL;
59 }
60
61 int (url_get_port) (const url_t url, long *port)
62 {
63 return (url) ? url->_get_port(url, port) : EINVAL;
64 }
65
66 int (url_get_path) (const url_t url, char *path, size_t len, size_t *n)
67 {
68 return (url) ? url->_get_path(url, path, len, n) : EINVAL;
69 }
70
71 int (url_get_mpath) (const url_t url, char **mpath, size_t *n)
72 {
73 return (url) ? url->_get_mpath(url, mpath, n) : EINVAL;
74 }
75
76 int (url_get_query) (const url_t url, char *query, size_t len, size_t *n)
77 {
78 return (url) ? url->_get_query(url, query, len, n) : EINVAL;
79 }
80
81 int (url_get_mquery) (const url_t url, char **mquery, size_t *n)
82 {
83 return (url) ? url->_get_mquery(url, mquery, n) : EINVAL;
84 }
85
86 int (url_get_id) (const url_t url, int *id)
87 {
88 return (url) ? url->_get_id (url, id) : EINVAL;
89 }
......