use iterator_t instead of a list_t
Showing
4 changed files
with
23 additions
and
109 deletions
1 | ## Process this file with GNU Automake to create Makefile.in | 1 | ## Process this file with GNU Automake to create Makefile.in |
2 | 2 | ||
3 | ## Copyright (C) 2003 Free Software Foundation, Inc. | 3 | ## Copyright (C) 2003, 2004 Free Software Foundation, Inc. |
4 | ## | 4 | ## |
5 | ## GNU Mailutils is free software; you can redistribute it and/or | 5 | ## GNU Mailutils is free software; you can redistribute it and/or |
6 | ## modify it under the terms of the GNU General Public License as | 6 | ## modify it under the terms of the GNU General Public License as |
... | @@ -37,6 +37,7 @@ libmu_pop_la_SOURCES = \ | ... | @@ -37,6 +37,7 @@ libmu_pop_la_SOURCES = \ |
37 | pop3_dele.c \ | 37 | pop3_dele.c \ |
38 | pop3_destroy.c \ | 38 | pop3_destroy.c \ |
39 | pop3_disconnect.c \ | 39 | pop3_disconnect.c \ |
40 | pop3_iterator.c \ | ||
40 | pop3_lista.c \ | 41 | pop3_lista.c \ |
41 | pop3_list.c \ | 42 | pop3_list.c \ |
42 | pop3_noop.c \ | 43 | pop3_noop.c \ | ... | ... |
... | @@ -32,13 +32,13 @@ | ... | @@ -32,13 +32,13 @@ |
32 | It is the responsability of the caller to destroy the list(list_destroy). | 32 | It is the responsability of the caller to destroy the list(list_destroy). |
33 | */ | 33 | */ |
34 | int | 34 | int |
35 | mu_pop3_capa (mu_pop3_t pop3, list_t *plist) | 35 | mu_pop3_capa (mu_pop3_t pop3, iterator_t *piterator) |
36 | { | 36 | { |
37 | int status; | 37 | int status = 0; |
38 | 38 | ||
39 | if (pop3 == NULL) | 39 | if (pop3 == NULL) |
40 | return EINVAL; | 40 | return EINVAL; |
41 | if (plist == NULL) | 41 | if (piterator == NULL) |
42 | return MU_ERR_OUT_PTR_NULL; | 42 | return MU_ERR_OUT_PTR_NULL; |
43 | 43 | ||
44 | switch (pop3->state) | 44 | switch (pop3->state) |
... | @@ -60,37 +60,13 @@ mu_pop3_capa (mu_pop3_t pop3, list_t *plist) | ... | @@ -60,37 +60,13 @@ mu_pop3_capa (mu_pop3_t pop3, list_t *plist) |
60 | MU_POP3_CHECK_EAGAIN (pop3, status); | 60 | MU_POP3_CHECK_EAGAIN (pop3, status); |
61 | mu_pop3_debug_ack (pop3); | 61 | mu_pop3_debug_ack (pop3); |
62 | MU_POP3_CHECK_OK (pop3); | 62 | MU_POP3_CHECK_OK (pop3); |
63 | status = list_create (plist); | 63 | status = mu_pop3_iterator_create (pop3, piterator); |
64 | MU_POP3_CHECK_ERROR(pop3, status); | 64 | MU_POP3_CHECK_ERROR (pop3, status); |
65 | list_set_destroy_item(*plist, free); | ||
66 | pop3->state = MU_POP3_CAPA_RX; | 65 | pop3->state = MU_POP3_CAPA_RX; |
67 | 66 | ||
68 | case MU_POP3_CAPA_RX: | 67 | case MU_POP3_CAPA_RX: |
69 | { | 68 | /* The iterator_t will read the stream and set the state to MU_POP3_NO_STATE when done. */ |
70 | /* CAPA line are 512 octets maximum according to RFC 2449. | 69 | break; |
71 | But do not use the stack and malloc. */ | ||
72 | char *capability; | ||
73 | size_t n = 0; | ||
74 | |||
75 | capability = malloc (512); | ||
76 | if (capability == NULL) | ||
77 | { | ||
78 | MU_POP3_CHECK_ERROR(pop3, ENOMEM); | ||
79 | } | ||
80 | while ((status = mu_pop3_readline (pop3, capability, 512, &n)) == 0 && n > 0) | ||
81 | { | ||
82 | /* Nuke the trailing newline */ | ||
83 | if (capability[n - 1] == '\n') | ||
84 | capability[n - 1] = '\0'; | ||
85 | /* add to the list. */ | ||
86 | list_append (*plist, strdup (capability)); | ||
87 | n = 0; | ||
88 | } | ||
89 | free (capability); | ||
90 | MU_POP3_CHECK_EAGAIN (pop3, status); | ||
91 | pop3->state = MU_POP3_NO_STATE; | ||
92 | break; | ||
93 | } | ||
94 | 70 | ||
95 | /* They must deal with the error first by reopening. */ | 71 | /* They must deal with the error first by reopening. */ |
96 | case MU_POP3_ERROR: | 72 | case MU_POP3_ERROR: | ... | ... |
... | @@ -26,13 +26,13 @@ | ... | @@ -26,13 +26,13 @@ |
26 | #include <mailutils/sys/pop3.h> | 26 | #include <mailutils/sys/pop3.h> |
27 | 27 | ||
28 | int | 28 | int |
29 | mu_pop3_list_all (mu_pop3_t pop3, list_t *plist) | 29 | mu_pop3_list_all (mu_pop3_t pop3, iterator_t *piterator) |
30 | { | 30 | { |
31 | int status; | 31 | int status = 0; |
32 | 32 | ||
33 | if (pop3 == NULL) | 33 | if (pop3 == NULL) |
34 | return EINVAL; | 34 | return EINVAL; |
35 | if (plist == NULL) | 35 | if (piterator == NULL) |
36 | return MU_ERR_OUT_PTR_NULL; | 36 | return MU_ERR_OUT_PTR_NULL; |
37 | 37 | ||
38 | switch (pop3->state) | 38 | switch (pop3->state) |
... | @@ -54,43 +54,13 @@ mu_pop3_list_all (mu_pop3_t pop3, list_t *plist) | ... | @@ -54,43 +54,13 @@ mu_pop3_list_all (mu_pop3_t pop3, list_t *plist) |
54 | MU_POP3_CHECK_EAGAIN (pop3, status); | 54 | MU_POP3_CHECK_EAGAIN (pop3, status); |
55 | mu_pop3_debug_ack (pop3); | 55 | mu_pop3_debug_ack (pop3); |
56 | MU_POP3_CHECK_OK (pop3); | 56 | MU_POP3_CHECK_OK (pop3); |
57 | status = list_create (plist); | 57 | status = mu_pop3_iterator_create (pop3, piterator); |
58 | MU_POP3_CHECK_ERROR(pop3, status); | 58 | MU_POP3_CHECK_ERROR (pop3, status); |
59 | list_set_destroy_item(*plist, free); | ||
60 | pop3->state = MU_POP3_LIST_RX; | 59 | pop3->state = MU_POP3_LIST_RX; |
61 | 60 | ||
62 | case MU_POP3_LIST_RX: | 61 | case MU_POP3_LIST_RX: |
63 | { | 62 | /* The iterator_t will read the stream and set the state to MU_POP3_NO_STATE when done. */ |
64 | /* LIST line should not be over 512 octets maximum according to RFC 2449. | 63 | break; |
65 | But do not use the stack and malloc. */ | ||
66 | char *lista; | ||
67 | size_t n = 0; | ||
68 | |||
69 | lista = malloc (512); | ||
70 | if (lista == NULL) | ||
71 | { | ||
72 | /* MU_POP3_CHECK_ERROR(pop3, ENOMEM); | ||
73 | Do not use the macro we need to clear the list if errors. */ | ||
74 | pop3->io.ptr = pop3->io.buf; | ||
75 | pop3->state = MU_POP3_ERROR; | ||
76 | list_destroy (plist); | ||
77 | return ENOMEM; | ||
78 | } | ||
79 | |||
80 | while ((status = mu_pop3_readline (pop3, lista, 512, &n)) == 0 && n > 0) | ||
81 | { | ||
82 | /* Nuke the trailing newline */ | ||
83 | if (lista[n - 1] == '\n') | ||
84 | lista[n - 1] = '\0'; | ||
85 | /* add to the list. */ | ||
86 | list_append (*plist, strdup (lista)); | ||
87 | n = 0; | ||
88 | } | ||
89 | free (lista); | ||
90 | MU_POP3_CHECK_EAGAIN (pop3, status); | ||
91 | pop3->state = MU_POP3_NO_STATE; | ||
92 | break; | ||
93 | } | ||
94 | 64 | ||
95 | /* They must deal with the error first by reopening. */ | 65 | /* They must deal with the error first by reopening. */ |
96 | case MU_POP3_ERROR: | 66 | case MU_POP3_ERROR: | ... | ... |
... | @@ -25,13 +25,13 @@ | ... | @@ -25,13 +25,13 @@ |
25 | #include <mailutils/sys/pop3.h> | 25 | #include <mailutils/sys/pop3.h> |
26 | 26 | ||
27 | int | 27 | int |
28 | mu_pop3_uidl_all (mu_pop3_t pop3, list_t *plist) | 28 | mu_pop3_uidl_all (mu_pop3_t pop3, iterator_t *piterator) |
29 | { | 29 | { |
30 | int status; | 30 | int status = 0; |
31 | 31 | ||
32 | if (pop3 == NULL) | 32 | if (pop3 == NULL) |
33 | return EINVAL; | 33 | return EINVAL; |
34 | if (plist == NULL) | 34 | if (piterator == NULL) |
35 | return MU_ERR_OUT_PTR_NULL; | 35 | return MU_ERR_OUT_PTR_NULL; |
36 | 36 | ||
37 | switch (pop3->state) | 37 | switch (pop3->state) |
... | @@ -53,45 +53,13 @@ mu_pop3_uidl_all (mu_pop3_t pop3, list_t *plist) | ... | @@ -53,45 +53,13 @@ mu_pop3_uidl_all (mu_pop3_t pop3, list_t *plist) |
53 | MU_POP3_CHECK_EAGAIN (pop3, status); | 53 | MU_POP3_CHECK_EAGAIN (pop3, status); |
54 | mu_pop3_debug_ack (pop3); | 54 | mu_pop3_debug_ack (pop3); |
55 | MU_POP3_CHECK_OK (pop3); | 55 | MU_POP3_CHECK_OK (pop3); |
56 | status = list_create (plist); | 56 | status = mu_pop3_iterator_create (pop3, piterator); |
57 | MU_POP3_CHECK_ERROR(pop3, status); | 57 | MU_POP3_CHECK_ERROR (pop3, status); |
58 | list_set_destroy_item(*plist, free); | ||
59 | pop3->state = MU_POP3_UIDL_RX; | 58 | pop3->state = MU_POP3_UIDL_RX; |
60 | 59 | ||
61 | case MU_POP3_UIDL_RX: | 60 | case MU_POP3_UIDL_RX: |
62 | { | 61 | /* The iterator_t will read the stream and set the state to MU_POP3_NO_STATE when done. */ |
63 | /* UIDL line are 512 octets maximum according to RFC 1939. | 62 | break; |
64 | But do not use the stack and malloc. */ | ||
65 | char *uidla; | ||
66 | size_t n = 0; | ||
67 | |||
68 | uidla = malloc (512); | ||
69 | if (uidla == NULL) | ||
70 | { | ||
71 | /* MU_POP3_CHECK_ERROR(pop3, ENOMEM) | ||
72 | Do not use the macro since we have to remove the list | ||
73 | if things go wrong. | ||
74 | */ | ||
75 | pop3->io.ptr = pop3->io.buf; | ||
76 | pop3->state = MU_POP3_ERROR; | ||
77 | list_destroy (plist); | ||
78 | return ENOMEM; | ||
79 | } | ||
80 | |||
81 | while ((status = mu_pop3_readline (pop3, uidla, 512, &n)) == 0 && n > 0) | ||
82 | { | ||
83 | /* Nuke the trailing newline */ | ||
84 | if (uidla[n - 1] == '\n') | ||
85 | uidla[n - 1] = '\0'; | ||
86 | /* add to the list. */ | ||
87 | list_append (*plist, strdup (uidla)); | ||
88 | n = 0; | ||
89 | } | ||
90 | free (uidla); | ||
91 | MU_POP3_CHECK_EAGAIN (pop3, status); | ||
92 | pop3->state = MU_POP3_NO_STATE; | ||
93 | break; | ||
94 | } | ||
95 | 63 | ||
96 | /* They must deal with the error first by reopening. */ | 64 | /* They must deal with the error first by reopening. */ |
97 | case MU_POP3_ERROR: | 65 | case MU_POP3_ERROR: |
... | @@ -104,4 +72,3 @@ mu_pop3_uidl_all (mu_pop3_t pop3, list_t *plist) | ... | @@ -104,4 +72,3 @@ mu_pop3_uidl_all (mu_pop3_t pop3, list_t *plist) |
104 | 72 | ||
105 | return status; | 73 | return status; |
106 | } | 74 | } |
107 | ... | ... |
-
Please register or sign in to post a comment