(mu_address_set_local_part,mu_address_set_domain,mu_address_set_route,mu_address…
…_set_email,mu_address_sget_comments,mu_address_sget_local_part,mu_address_sget_personal,mu_address_sget_domain,mu_address_sget_route,mu_address_sget_email): New functions
Showing
2 changed files
with
148 additions
and
308 deletions
... | @@ -36,27 +36,54 @@ extern int mu_address_concatenate (mu_address_t to, mu_address_t* from); | ... | @@ -36,27 +36,54 @@ extern int mu_address_concatenate (mu_address_t to, mu_address_t* from); |
36 | 36 | ||
37 | extern int mu_address_get_nth | 37 | extern int mu_address_get_nth |
38 | (mu_address_t addr, size_t no, mu_address_t *pret); | 38 | (mu_address_t addr, size_t no, mu_address_t *pret); |
39 | |||
40 | extern int mu_address_set_email (mu_address_t, size_t, const char *); | ||
41 | extern int mu_address_sget_email | ||
42 | (mu_address_t, size_t, const char **); | ||
39 | extern int mu_address_get_email | 43 | extern int mu_address_get_email |
40 | (mu_address_t, size_t, char *, size_t, size_t *); | 44 | (mu_address_t, size_t, char *, size_t, size_t *); |
41 | extern int mu_address_get_local_part | 45 | extern int mu_address_aget_email |
46 | (mu_address_t, size_t, char **); | ||
47 | |||
48 | extern int mu_address_set_comments (mu_address_t, size_t, const char *); | ||
49 | extern int mu_address_sget_comments | ||
50 | (mu_address_t, size_t, const char **); | ||
51 | extern int mu_address_get_comments | ||
42 | (mu_address_t, size_t, char *, size_t, size_t *); | 52 | (mu_address_t, size_t, char *, size_t, size_t *); |
43 | extern int mu_address_get_domain | 53 | extern int mu_address_aget_comments |
54 | (mu_address_t, size_t, char **); | ||
55 | |||
56 | extern int mu_address_set_local_part (mu_address_t, size_t, const char *); | ||
57 | extern int mu_address_sget_local_part | ||
58 | (mu_address_t, size_t, const char **); | ||
59 | extern int mu_address_get_local_part | ||
44 | (mu_address_t, size_t, char *, size_t, size_t *); | 60 | (mu_address_t, size_t, char *, size_t, size_t *); |
61 | extern int mu_address_aget_local_part | ||
62 | (mu_address_t, size_t, char **); | ||
63 | |||
64 | extern int mu_address_set_personal (mu_address_t, size_t, const char *); | ||
65 | extern int mu_address_sget_personal | ||
66 | (mu_address_t, size_t, const char **); | ||
45 | extern int mu_address_get_personal | 67 | extern int mu_address_get_personal |
46 | (mu_address_t, size_t, char *, size_t, size_t *); | 68 | (mu_address_t, size_t, char *, size_t, size_t *); |
47 | extern int mu_address_get_comments | 69 | extern int mu_address_aget_personal |
70 | (mu_address_t, size_t, char **); | ||
71 | |||
72 | extern int mu_address_set_domain (mu_address_t, size_t, const char *); | ||
73 | extern int mu_address_sget_domain | ||
74 | (mu_address_t, size_t, const char **); | ||
75 | extern int mu_address_get_domain | ||
48 | (mu_address_t, size_t, char *, size_t, size_t *); | 76 | (mu_address_t, size_t, char *, size_t, size_t *); |
77 | extern int mu_address_aget_domain | ||
78 | (mu_address_t, size_t, char **); | ||
79 | |||
80 | extern int mu_address_set_route (mu_address_t, size_t, const char *); | ||
81 | extern int mu_address_sget_route | ||
82 | (mu_address_t, size_t, const char **); | ||
49 | extern int mu_address_get_route | 83 | extern int mu_address_get_route |
50 | (mu_address_t, size_t, char *, size_t, size_t *); | 84 | (mu_address_t, size_t, char *, size_t, size_t *); |
51 | 85 | extern int mu_address_aget_route | |
52 | extern int mu_address_aget_email | ||
53 | (mu_address_t, size_t, char **); | 86 | (mu_address_t, size_t, char **); |
54 | extern int mu_address_aget_local_part | ||
55 | (mu_address_t addr, size_t no, char **buf); | ||
56 | extern int mu_address_aget_domain | ||
57 | (mu_address_t addr, size_t no, char **buf); | ||
58 | extern int mu_address_aget_personal | ||
59 | (mu_address_t addr, size_t no, char **buf); | ||
60 | 87 | ||
61 | extern int mu_address_is_group | 88 | extern int mu_address_is_group |
62 | (mu_address_t, size_t, int*); | 89 | (mu_address_t, size_t, int*); |
... | @@ -72,13 +99,6 @@ extern int mu_address_union (mu_address_t *a, mu_address_t b); | ... | @@ -72,13 +99,6 @@ extern int mu_address_union (mu_address_t *a, mu_address_t b); |
72 | 99 | ||
73 | extern size_t mu_address_format_string (mu_address_t addr, char *buf, size_t buflen); | 100 | extern size_t mu_address_format_string (mu_address_t addr, char *buf, size_t buflen); |
74 | 101 | ||
75 | /* The following setters are not entirely orthogonal to their _get_ | ||
76 | counterparts. Only personal and comments parts can be set */ | ||
77 | extern int mu_address_set_personal (mu_address_t addr, size_t no, | ||
78 | const char *buf); | ||
79 | extern int mu_address_set_comments (mu_address_t addr, size_t no, | ||
80 | const char *buf); | ||
81 | |||
82 | #ifdef __cplusplus | 102 | #ifdef __cplusplus |
83 | } | 103 | } |
84 | #endif | 104 | #endif | ... | ... |
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | 1 | /* GNU Mailutils -- a suite of utilities for electronic mail |
2 | Copyright (C) 1999, 2000, 2001, 2005, 2006 Free Software Foundation, Inc. | 2 | Copyright (C) 1999, 2000, 2001, 2005, 2006, |
3 | 2007 Free Software Foundation, Inc. | ||
3 | 4 | ||
4 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Lesser General Public | 6 | modify it under the terms of the GNU Lesser General Public |
... | @@ -212,112 +213,114 @@ mu_address_get_nth (mu_address_t addr, size_t no, mu_address_t *pret) | ... | @@ -212,112 +213,114 @@ mu_address_get_nth (mu_address_t addr, size_t no, mu_address_t *pret) |
212 | return 0; | 213 | return 0; |
213 | } | 214 | } |
214 | 215 | ||
215 | int | 216 | |
216 | mu_address_get_personal (mu_address_t addr, size_t no, char *buf, size_t len, | 217 | /* General accessors: */ |
217 | size_t * n) | 218 | #define AC4(a,b,c,d) a ## b ## c ## d |
218 | { | 219 | #define ACCESSOR(action,field) AC4(mu_address_,action,_,field) |
219 | size_t i; | 220 | |
220 | mu_address_t subaddr; | 221 | #define DECL_SET(field) \ |
221 | 222 | int \ | |
222 | if (addr == NULL) | 223 | ACCESSOR(set, field) (mu_address_t addr, size_t no, const char *buf) \ |
223 | return EINVAL; | 224 | { \ |
224 | 225 | char *s; \ | |
225 | subaddr = _address_get_nth (addr, no); | 226 | mu_address_t subaddr; \ |
226 | if (!subaddr) | 227 | \ |
227 | return MU_ERR_NOENT; | 228 | if (addr == NULL) \ |
228 | 229 | return EINVAL; \ | |
229 | i = mu_cpystr (buf, subaddr->personal, len); | 230 | \ |
230 | if (n) | 231 | subaddr = _address_get_nth (addr, no); \ |
231 | *n = i; | 232 | if (!subaddr) \ |
232 | return 0; | 233 | return MU_ERR_NOENT; \ |
233 | } | 234 | \ |
234 | 235 | s = strdup (buf); \ | |
235 | int | 236 | if (!s) \ |
236 | mu_address_set_personal (mu_address_t addr, size_t no, const char *buf) | 237 | return errno; \ |
237 | { | 238 | \ |
238 | char *s; | 239 | free (subaddr->field); \ |
239 | mu_address_t subaddr; | 240 | subaddr->field = s; \ |
240 | 241 | \ | |
241 | if (addr == NULL) | 242 | return 0; \ |
242 | return EINVAL; | 243 | } |
243 | 244 | ||
244 | subaddr = _address_get_nth (addr, no); | 245 | #define DECL_SGET(field) \ |
245 | if (!subaddr) | 246 | int \ |
246 | return MU_ERR_NOENT; | 247 | ACCESSOR(sget,field) (mu_address_t addr, size_t no, char const **sptr) \ |
247 | 248 | { \ | |
248 | s = strdup (buf); | 249 | mu_address_t subaddr; \ |
249 | if (!s) | 250 | \ |
250 | return errno; | 251 | if (addr == NULL) \ |
251 | 252 | return EINVAL; \ | |
252 | free (subaddr->personal); | 253 | \ |
253 | subaddr->personal = s; | 254 | subaddr = _address_get_nth (addr, no); \ |
254 | 255 | if (!subaddr) \ | |
255 | return 0; | 256 | return MU_ERR_NOENT; \ |
256 | } | 257 | \ |
257 | 258 | *sptr = subaddr->field; \ | |
258 | int | 259 | return 0; \ |
259 | mu_address_get_comments (mu_address_t addr, size_t no, char *buf, size_t len, | 260 | } |
260 | size_t * n) | 261 | |
261 | { | 262 | #define DECL_GET(field) \ |
262 | size_t i; | 263 | int \ |
263 | mu_address_t subaddr; | 264 | ACCESSOR(get,field) (mu_address_t addr, size_t no, char *buf, size_t len, \ |
264 | 265 | size_t * n) \ | |
265 | if (addr == NULL) | 266 | { \ |
266 | return EINVAL; | 267 | size_t i; \ |
267 | 268 | const char *str; \ | |
268 | subaddr = _address_get_nth (addr, no); | 269 | int status = ACCESSOR(sget, field) (addr, no, &str); \ |
269 | if (!subaddr) | 270 | \ |
270 | return MU_ERR_NOENT; | 271 | if (status) \ |
271 | 272 | return status; \ | |
272 | i = mu_cpystr (buf, subaddr->comments, len); | 273 | \ |
273 | if (n) | 274 | i = mu_cpystr (buf, str, len); \ |
274 | *n = i; | 275 | if (n) \ |
275 | return 0; | 276 | *n = i; \ |
276 | } | 277 | return 0; \ |
277 | 278 | } | |
278 | int | 279 | |
279 | mu_address_set_comments (mu_address_t addr, size_t no, const char *buf) | 280 | #define DECL_AGET(field) \ |
280 | { | 281 | int \ |
281 | char *s; | 282 | ACCESSOR(aget, field) (mu_address_t addr, size_t no, char **buf) \ |
282 | mu_address_t subaddr; | 283 | { \ |
283 | 284 | const char *str; \ | |
284 | if (addr == NULL) | 285 | int status = ACCESSOR(sget, field) (addr, no, &str); \ |
285 | return EINVAL; | 286 | \ |
286 | 287 | if (status) \ | |
287 | subaddr = _address_get_nth (addr, no); | 288 | return status; \ |
288 | if (!subaddr) | 289 | \ |
289 | return MU_ERR_NOENT; | 290 | if (str) \ |
290 | 291 | { \ | |
291 | s = strdup (buf); | 292 | *buf = strdup (str); \ |
292 | if (!s) | 293 | if (!*buf) \ |
293 | return errno; | 294 | status = ENOMEM; \ |
294 | 295 | } \ | |
295 | free (subaddr->comments); | 296 | else \ |
296 | subaddr->comments = s; | 297 | *buf = NULL; \ |
297 | 298 | return status; \ | |
298 | return 0; | 299 | } |
299 | } | 300 | |
300 | 301 | #define DECL_ACCESSORS(field) \ | |
301 | int | 302 | DECL_SET(field) \ |
302 | mu_address_get_email (mu_address_t addr, size_t no, char *buf, size_t len, | 303 | DECL_SGET(field) \ |
303 | size_t * n) | 304 | DECL_GET(field) \ |
304 | { | 305 | DECL_AGET(field) |
305 | size_t i; | 306 | |
306 | mu_address_t subaddr; | 307 | |
307 | 308 | ||
308 | if (addr == NULL) | 309 | /* Personal part */ |
309 | return EINVAL; | 310 | DECL_ACCESSORS(personal) |
310 | 311 | /* Comments */ | |
311 | subaddr = _address_get_nth (addr, no); | 312 | DECL_ACCESSORS(comments) |
312 | if (!subaddr) | 313 | /* Email */ |
313 | return MU_ERR_NOENT; | 314 | DECL_ACCESSORS(email) |
314 | 315 | /* Local part */ | |
315 | i = mu_cpystr (buf, subaddr->email, len); | 316 | DECL_ACCESSORS(local_part) |
316 | if (n) | 317 | /* Domain */ |
317 | *n = i; | 318 | DECL_ACCESSORS(domain) |
318 | return 0; | 319 | /* Route */ |
319 | } | 320 | DECL_ACCESSORS(route) |
320 | 321 | ||
322 | |||
323 | |||
321 | #define format_char(c) do {\ | 324 | #define format_char(c) do {\ |
322 | if (buflen) \ | 325 | if (buflen) \ |
323 | {\ | 326 | {\ |
... | @@ -384,189 +387,6 @@ mu_address_format_string (mu_address_t addr, char *buf, size_t buflen) | ... | @@ -384,189 +387,6 @@ mu_address_format_string (mu_address_t addr, char *buf, size_t buflen) |
384 | return rc; | 387 | return rc; |
385 | } | 388 | } |
386 | 389 | ||
387 | int | ||
388 | mu_address_aget_personal (mu_address_t addr, size_t no, char **buf) | ||
389 | { | ||
390 | int status = 0; | ||
391 | mu_address_t subaddr; | ||
392 | |||
393 | if (addr == NULL) | ||
394 | return EINVAL; | ||
395 | |||
396 | subaddr = _address_get_nth (addr, no); | ||
397 | if (!subaddr) | ||
398 | return MU_ERR_NOENT; | ||
399 | |||
400 | if (subaddr->personal) | ||
401 | { | ||
402 | *buf = strdup (subaddr->personal); | ||
403 | if (!*buf) | ||
404 | status = ENOMEM; | ||
405 | } | ||
406 | else | ||
407 | *buf = NULL; | ||
408 | return status; | ||
409 | } | ||
410 | |||
411 | int | ||
412 | address_aget_comments (mu_address_t addr, size_t no, char **buf) | ||
413 | { | ||
414 | int status = 0; | ||
415 | mu_address_t subaddr; | ||
416 | |||
417 | if (addr == NULL) | ||
418 | return EINVAL; | ||
419 | |||
420 | subaddr = _address_get_nth (addr, no); | ||
421 | if (!subaddr) | ||
422 | return MU_ERR_NOENT; | ||
423 | |||
424 | if (subaddr->comments) | ||
425 | { | ||
426 | *buf = strdup (subaddr->comments); | ||
427 | if (!*buf) | ||
428 | status = ENOMEM; | ||
429 | } | ||
430 | else | ||
431 | *buf = NULL; | ||
432 | return status; | ||
433 | } | ||
434 | |||
435 | int | ||
436 | mu_address_aget_email (mu_address_t addr, size_t no, char **buf) | ||
437 | { | ||
438 | int status = 0; | ||
439 | mu_address_t subaddr; | ||
440 | |||
441 | if (addr == NULL || buf == NULL) | ||
442 | return EINVAL; | ||
443 | |||
444 | subaddr = _address_get_nth (addr, no); | ||
445 | if (!subaddr) | ||
446 | return MU_ERR_NOENT; | ||
447 | |||
448 | if (subaddr->email) | ||
449 | { | ||
450 | *buf = strdup (subaddr->email); | ||
451 | if (!*buf) | ||
452 | status = ENOMEM; | ||
453 | } | ||
454 | else | ||
455 | *buf = NULL; | ||
456 | |||
457 | return status; | ||
458 | } | ||
459 | |||
460 | int | ||
461 | mu_address_aget_local_part (mu_address_t addr, size_t no, char **buf) | ||
462 | { | ||
463 | int status = 0; | ||
464 | mu_address_t subaddr; | ||
465 | |||
466 | if (addr == NULL || buf == NULL) | ||
467 | return EINVAL; | ||
468 | |||
469 | subaddr = _address_get_nth (addr, no); | ||
470 | if (!subaddr) | ||
471 | return MU_ERR_NOENT; | ||
472 | |||
473 | if (subaddr->local_part) | ||
474 | { | ||
475 | *buf = strdup (subaddr->local_part); | ||
476 | if (!*buf) | ||
477 | status = ENOMEM; | ||
478 | } | ||
479 | else | ||
480 | *buf = NULL; | ||
481 | |||
482 | return status; | ||
483 | } | ||
484 | |||
485 | int | ||
486 | mu_address_aget_domain (mu_address_t addr, size_t no, char **buf) | ||
487 | { | ||
488 | int status = 0; | ||
489 | mu_address_t subaddr; | ||
490 | |||
491 | if (addr == NULL || buf == NULL) | ||
492 | return EINVAL; | ||
493 | |||
494 | subaddr = _address_get_nth (addr, no); | ||
495 | if (!subaddr) | ||
496 | return MU_ERR_NOENT; | ||
497 | |||
498 | if (subaddr->domain) | ||
499 | { | ||
500 | *buf = strdup (subaddr->domain); | ||
501 | if (!*buf) | ||
502 | status = ENOMEM; | ||
503 | } | ||
504 | else | ||
505 | *buf = NULL; | ||
506 | |||
507 | return status; | ||
508 | } | ||
509 | |||
510 | int | ||
511 | mu_address_get_local_part (mu_address_t addr, size_t no, char *buf, size_t len, | ||
512 | size_t * n) | ||
513 | { | ||
514 | size_t i; | ||
515 | mu_address_t subaddr; | ||
516 | |||
517 | if (addr == NULL) | ||
518 | return EINVAL; | ||
519 | |||
520 | subaddr = _address_get_nth (addr, no); | ||
521 | if (!subaddr) | ||
522 | return MU_ERR_NOENT; | ||
523 | |||
524 | i = mu_cpystr (buf, subaddr->local_part, len); | ||
525 | if (n) | ||
526 | *n = i; | ||
527 | return 0; | ||
528 | } | ||
529 | |||
530 | int | ||
531 | mu_address_get_domain (mu_address_t addr, size_t no, char *buf, size_t len, | ||
532 | size_t * n) | ||
533 | { | ||
534 | size_t i; | ||
535 | mu_address_t subaddr; | ||
536 | |||
537 | if (addr == NULL) | ||
538 | return EINVAL; | ||
539 | |||
540 | subaddr = _address_get_nth (addr, no); | ||
541 | if (!subaddr) | ||
542 | return MU_ERR_NOENT; | ||
543 | |||
544 | i = mu_cpystr (buf, subaddr->domain, len); | ||
545 | if (n) | ||
546 | *n = i; | ||
547 | return 0; | ||
548 | } | ||
549 | |||
550 | int | ||
551 | mu_address_get_route (mu_address_t addr, size_t no, char *buf, size_t len, | ||
552 | size_t * n) | ||
553 | { | ||
554 | size_t i; | ||
555 | mu_address_t subaddr; | ||
556 | |||
557 | if (addr == NULL) | ||
558 | return EINVAL; | ||
559 | |||
560 | subaddr = _address_get_nth (addr, no); | ||
561 | if (!subaddr) | ||
562 | return MU_ERR_NOENT; | ||
563 | |||
564 | i = mu_cpystr (buf, subaddr->route, len); | ||
565 | if (n) | ||
566 | *n = i; | ||
567 | return 0; | ||
568 | } | ||
569 | |||
570 | static int | 390 | static int |
571 | _address_is_group (mu_address_t addr) | 391 | _address_is_group (mu_address_t addr) |
572 | { | 392 | { | ... | ... |
-
Please register or sign in to post a comment