use mu_url_sget or mu_url_aget accessors
Showing
11 changed files
with
100 additions
and
192 deletions
... | @@ -160,30 +160,24 @@ authenticate_imap_login (mu_authority_t auth) | ... | @@ -160,30 +160,24 @@ authenticate_imap_login (mu_authority_t auth) |
160 | case IMAP_AUTH: | 160 | case IMAP_AUTH: |
161 | { | 161 | { |
162 | /* Grab the User and Passwd information. */ | 162 | /* Grab the User and Passwd information. */ |
163 | size_t n = 0; | ||
164 | mu_authority_get_ticket (auth, &ticket); | 163 | mu_authority_get_ticket (auth, &ticket); |
165 | if (f_imap->user) | 164 | if (f_imap->user) |
166 | free (f_imap->user); | 165 | free (f_imap->user); |
167 | if (f_imap->passwd) | 166 | if (f_imap->passwd) |
168 | free (f_imap->passwd); | 167 | free (f_imap->passwd); |
169 | /* Was it in the URL? */ | 168 | /* Was it in the URL? */ |
170 | status = mu_url_get_user (folder->url, NULL, 0, &n); | 169 | status = mu_url_aget_user (folder->url, &f_imap->user); |
171 | if (status != 0 || n == 0) | 170 | if (status == MU_ERR_NOENT) |
172 | mu_ticket_pop (ticket, folder->url, "Imap User: ", &f_imap->user); | 171 | mu_ticket_pop (ticket, folder->url, "Imap User: ", &f_imap->user); |
173 | else | 172 | else if (status) |
174 | { | 173 | return status; |
175 | f_imap->user = calloc (1, n + 1); | 174 | |
176 | mu_url_get_user (folder->url, f_imap->user, n + 1, NULL); | 175 | status = mu_url_aget_passwd (folder->url, &f_imap->passwd); |
177 | } | 176 | if (status == MU_ERR_NOENT) |
178 | /* Was it in the URL? */ | 177 | mu_ticket_pop (ticket, folder->url, "Imap Passwd: ", |
179 | status = mu_url_get_passwd (folder->url, NULL, 0, &n); | 178 | &f_imap->passwd); |
180 | if (status != 0 || n == 0) | 179 | else if (status) |
181 | mu_ticket_pop (ticket, folder->url, "Imap Passwd: ", &f_imap->passwd); | 180 | return status; |
182 | else | ||
183 | { | ||
184 | f_imap->passwd = calloc (1, n + 1); | ||
185 | mu_url_get_passwd (folder->url, f_imap->passwd, n + 1, NULL); | ||
186 | } | ||
187 | 181 | ||
188 | if (f_imap->user == NULL) | 182 | if (f_imap->user == NULL) |
189 | return MU_ERR_NOUSERNAME; | 183 | return MU_ERR_NOUSERNAME; |
... | @@ -582,7 +576,7 @@ static int | ... | @@ -582,7 +576,7 @@ static int |
582 | folder_imap_open (mu_folder_t folder, int flags) | 576 | folder_imap_open (mu_folder_t folder, int flags) |
583 | { | 577 | { |
584 | f_imap_t f_imap = folder->data; | 578 | f_imap_t f_imap = folder->data; |
585 | char *host; | 579 | const char *host; |
586 | long port = 143; /* default imap port. */ | 580 | long port = 143; /* default imap port. */ |
587 | int status = 0; | 581 | int status = 0; |
588 | size_t len = 0; | 582 | size_t len = 0; |
... | @@ -597,11 +591,9 @@ folder_imap_open (mu_folder_t folder, int flags) | ... | @@ -597,11 +591,9 @@ folder_imap_open (mu_folder_t folder, int flags) |
597 | mu_monitor_unlock (folder->monitor); | 591 | mu_monitor_unlock (folder->monitor); |
598 | 592 | ||
599 | /* Fetch the server name and the port in the mu_url_t. */ | 593 | /* Fetch the server name and the port in the mu_url_t. */ |
600 | status = mu_url_get_host (folder->url, NULL, 0, &len); | 594 | status = mu_url_sget_host (folder->url, &host); |
601 | if (status != 0) | 595 | if (status != 0) |
602 | return status; | 596 | return status; |
603 | host = alloca (len + 1); | ||
604 | mu_url_get_host (folder->url, host, len + 1, NULL); | ||
605 | mu_url_get_port (folder->url, &port); | 597 | mu_url_get_port (folder->url, &port); |
606 | 598 | ||
607 | folder->flags = flags; | 599 | folder->flags = flags; | ... | ... |
... | @@ -125,8 +125,8 @@ static int is_same_folder (mu_mailbox_t, mu_message_t); | ... | @@ -125,8 +125,8 @@ static int is_same_folder (mu_mailbox_t, mu_message_t); |
125 | int | 125 | int |
126 | _mailbox_imap_init (mu_mailbox_t mailbox) | 126 | _mailbox_imap_init (mu_mailbox_t mailbox) |
127 | { | 127 | { |
128 | int status; | ||
128 | m_imap_t m_imap; | 129 | m_imap_t m_imap; |
129 | size_t name_len = 0; | ||
130 | mu_folder_t folder = NULL; | 130 | mu_folder_t folder = NULL; |
131 | 131 | ||
132 | assert(mailbox); | 132 | assert(mailbox); |
... | @@ -138,18 +138,15 @@ _mailbox_imap_init (mu_mailbox_t mailbox) | ... | @@ -138,18 +138,15 @@ _mailbox_imap_init (mu_mailbox_t mailbox) |
138 | return ENOMEM; | 138 | return ENOMEM; |
139 | 139 | ||
140 | /* Retrieve the name of the mailbox from the URL. */ | 140 | /* Retrieve the name of the mailbox from the URL. */ |
141 | mu_url_get_path (mailbox->url, NULL, 0, &name_len); | 141 | status = mu_url_aget_path (mailbox->url, &m_imap->name); |
142 | if (name_len == 0) | 142 | if (status == MU_ERR_NOENT) |
143 | { | 143 | { |
144 | /* name "INBOX" is the default. */ | 144 | m_imap->name = strdup ("INBOX"); |
145 | m_imap->name = calloc (6, sizeof (char)); | 145 | if (!m_imap->name) |
146 | strcpy (m_imap->name, "INBOX"); | 146 | return ENOMEM; |
147 | } | ||
148 | else | ||
149 | { | ||
150 | m_imap->name = calloc (name_len + 1, sizeof (char)); | ||
151 | mu_url_get_path (mailbox->url, m_imap->name, name_len + 1, NULL); | ||
152 | } | 147 | } |
148 | else if (status) | ||
149 | return status; | ||
153 | 150 | ||
154 | /* Overload the functions. */ | 151 | /* Overload the functions. */ |
155 | mailbox->_destroy = mailbox_imap_destroy; | 152 | mailbox->_destroy = mailbox_imap_destroy; |
... | @@ -298,21 +295,18 @@ mailbox_imap_open (mu_mailbox_t mailbox, int flags) | ... | @@ -298,21 +295,18 @@ mailbox_imap_open (mu_mailbox_t mailbox, int flags) |
298 | { | 295 | { |
299 | case IMAP_NO_STATE: | 296 | case IMAP_NO_STATE: |
300 | { | 297 | { |
301 | char *path; | 298 | const char *path; |
302 | size_t len; | 299 | size_t len; |
303 | mu_url_get_path (folder->url, NULL, 0, &len); | 300 | status = mu_url_sget_path (folder->url, &path); |
304 | if (len == 0) | 301 | if (status == MU_ERR_NOENT) |
305 | return 0; | 302 | return 0; |
306 | path = calloc (len + 1, sizeof (*path)); | 303 | else if (status) |
307 | if (path == NULL) | 304 | return status; |
308 | return ENOMEM; | ||
309 | mu_url_get_path (folder->url, path, len + 1, NULL); | ||
310 | status = imap_writeline (f_imap, "g%u CREATE %s\r\n", | 305 | status = imap_writeline (f_imap, "g%u CREATE %s\r\n", |
311 | f_imap->seq, path); | 306 | f_imap->seq, path); |
312 | MAILBOX_DEBUG2 (folder, MU_DEBUG_PROT, "g%u CREATE %s\n", | 307 | MAILBOX_DEBUG2 (folder, MU_DEBUG_PROT, "g%u CREATE %s\n", |
313 | f_imap->seq, path); | 308 | f_imap->seq, path); |
314 | f_imap->seq++; | 309 | f_imap->seq++; |
315 | free (path); | ||
316 | if (status != 0) | 310 | if (status != 0) |
317 | { | 311 | { |
318 | m_imap->state = f_imap->state = IMAP_NO_STATE; | 312 | m_imap->state = f_imap->state = IMAP_NO_STATE; |
... | @@ -980,7 +974,7 @@ imap_append_message0 (mu_mailbox_t mailbox, mu_message_t msg) | ... | @@ -980,7 +974,7 @@ imap_append_message0 (mu_mailbox_t mailbox, mu_message_t msg) |
980 | case IMAP_NO_STATE: | 974 | case IMAP_NO_STATE: |
981 | { | 975 | { |
982 | size_t lines, size; | 976 | size_t lines, size; |
983 | char *path; | 977 | const char *path; |
984 | char *abuf = malloc (1); | 978 | char *abuf = malloc (1); |
985 | /* Get the desired flags attribute. */ | 979 | /* Get the desired flags attribute. */ |
986 | if (abuf == NULL) | 980 | if (abuf == NULL) |
... | @@ -1009,28 +1003,9 @@ imap_append_message0 (mu_mailbox_t mailbox, mu_message_t msg) | ... | @@ -1009,28 +1003,9 @@ imap_append_message0 (mu_mailbox_t mailbox, mu_message_t msg) |
1009 | } | 1003 | } |
1010 | 1004 | ||
1011 | /* Get the mailbox filepath. */ | 1005 | /* Get the mailbox filepath. */ |
1012 | { | 1006 | status = mu_url_sget_path (mailbox->url, &path); |
1013 | size_t n = 0; | 1007 | if (status == MU_ERR_NOENT) |
1014 | mu_url_get_path (mailbox->url, NULL, 0, &n); | 1008 | path = "INBOX"; |
1015 | if (n == 0) | ||
1016 | { | ||
1017 | if (!(path = strdup ("INBOX"))) | ||
1018 | { | ||
1019 | free (abuf); | ||
1020 | return ENOMEM; | ||
1021 | } | ||
1022 | } | ||
1023 | else | ||
1024 | { | ||
1025 | path = calloc (n + 1, sizeof (*path)); | ||
1026 | if (path == NULL) | ||
1027 | { | ||
1028 | free (abuf); | ||
1029 | return ENOMEM; | ||
1030 | } | ||
1031 | mu_url_get_path (mailbox->url, path, n + 1, NULL); | ||
1032 | } | ||
1033 | } | ||
1034 | 1009 | ||
1035 | /* FIXME: we need to get the mu_envelope_date and use it. | 1010 | /* FIXME: we need to get the mu_envelope_date and use it. |
1036 | currently it is ignored. */ | 1011 | currently it is ignored. */ |
... | @@ -1046,7 +1021,6 @@ imap_append_message0 (mu_mailbox_t mailbox, mu_message_t msg) | ... | @@ -1046,7 +1021,6 @@ imap_append_message0 (mu_mailbox_t mailbox, mu_message_t msg) |
1046 | abuf, | 1021 | abuf, |
1047 | mu_umaxtostr (1, size + lines)); | 1022 | mu_umaxtostr (1, size + lines)); |
1048 | free (abuf); | 1023 | free (abuf); |
1049 | free (path); | ||
1050 | CHECK_ERROR (f_imap, status); | 1024 | CHECK_ERROR (f_imap, status); |
1051 | MAILBOX_DEBUG0 (mailbox, MU_DEBUG_PROT, f_imap->buffer); | 1025 | MAILBOX_DEBUG0 (mailbox, MU_DEBUG_PROT, f_imap->buffer); |
1052 | f_imap->state = IMAP_APPEND; | 1026 | f_imap->state = IMAP_APPEND; |
... | @@ -1132,21 +1106,14 @@ imap_copy_message (mu_mailbox_t mailbox, mu_message_t msg) | ... | @@ -1132,21 +1106,14 @@ imap_copy_message (mu_mailbox_t mailbox, mu_message_t msg) |
1132 | { | 1106 | { |
1133 | case IMAP_NO_STATE: | 1107 | case IMAP_NO_STATE: |
1134 | { | 1108 | { |
1135 | char *path; | 1109 | const char *path; |
1136 | size_t n = 0; | ||
1137 | /* Check for a valid mailbox name. */ | 1110 | /* Check for a valid mailbox name. */ |
1138 | mu_url_get_path (mailbox->url, NULL, 0, &n); | 1111 | status = mu_url_sget_path (mailbox->url, &path); |
1139 | if (n == 0) | 1112 | if (status == 0) |
1140 | return EINVAL; | 1113 | status = imap_writeline (f_imap, "g%s COPY %s %s\r\n", |
1141 | path = calloc (n + 1, sizeof (*path)); | 1114 | mu_umaxtostr (0, f_imap->seq++), |
1142 | if (path == NULL) | 1115 | mu_umaxtostr (1, msg_imap->num), |
1143 | return ENOMEM; | 1116 | path); |
1144 | mu_url_get_path (mailbox->url, path, n + 1, NULL); | ||
1145 | status = imap_writeline (f_imap, "g%s COPY %s %s\r\n", | ||
1146 | mu_umaxtostr (0, f_imap->seq++), | ||
1147 | mu_umaxtostr (1, msg_imap->num), | ||
1148 | path); | ||
1149 | free (path); | ||
1150 | CHECK_ERROR (f_imap, status); | 1117 | CHECK_ERROR (f_imap, status); |
1151 | MAILBOX_DEBUG0 (mailbox, MU_DEBUG_PROT, f_imap->buffer); | 1118 | MAILBOX_DEBUG0 (mailbox, MU_DEBUG_PROT, f_imap->buffer); |
1152 | f_imap->state = IMAP_COPY; | 1119 | f_imap->state = IMAP_COPY; | ... | ... |
... | @@ -152,15 +152,13 @@ _folder_mbox_init (mu_folder_t folder) | ... | @@ -152,15 +152,13 @@ _folder_mbox_init (mu_folder_t folder) |
152 | if (dfolder == NULL) | 152 | if (dfolder == NULL) |
153 | return ENOMEM; | 153 | return ENOMEM; |
154 | 154 | ||
155 | mu_url_get_path (folder->url, NULL, 0, &name_len); | 155 | status = mu_url_aget_path (folder->url, &dfolder->dirname); |
156 | dfolder->dirname = calloc (name_len + 1, sizeof (char)); | 156 | if (status) |
157 | if (dfolder->dirname == NULL) | ||
158 | { | 157 | { |
159 | free (dfolder); | 158 | free (dfolder); |
160 | folder->data = NULL; | 159 | folder->data = NULL; |
161 | return ENOMEM; | 160 | return ENOMEM; |
162 | } | 161 | } |
163 | mu_url_get_path (folder->url, dfolder->dirname, name_len + 1, NULL); | ||
164 | 162 | ||
165 | folder->_destroy = folder_mbox_destroy; | 163 | folder->_destroy = folder_mbox_destroy; |
166 | 164 | ... | ... |
... | @@ -76,8 +76,8 @@ static int mbox_tmpfile (mu_mailbox_t, char **pbox); | ... | @@ -76,8 +76,8 @@ static int mbox_tmpfile (mu_mailbox_t, char **pbox); |
76 | int | 76 | int |
77 | _mailbox_mbox_init (mu_mailbox_t mailbox) | 77 | _mailbox_mbox_init (mu_mailbox_t mailbox) |
78 | { | 78 | { |
79 | int status; | ||
79 | mbox_data_t mud; | 80 | mbox_data_t mud; |
80 | size_t name_len; | ||
81 | 81 | ||
82 | if (mailbox == NULL) | 82 | if (mailbox == NULL) |
83 | return EINVAL; | 83 | return EINVAL; |
... | @@ -98,15 +98,13 @@ _mailbox_mbox_init (mu_mailbox_t mailbox) | ... | @@ -98,15 +98,13 @@ _mailbox_mbox_init (mu_mailbox_t mailbox) |
98 | will be "///var/mail/alain", we let open() do the right thing. | 98 | will be "///var/mail/alain", we let open() do the right thing. |
99 | So it will let things like this "mbox://390/var/mail/alain" where | 99 | So it will let things like this "mbox://390/var/mail/alain" where |
100 | the "//" _is_ part of the filename, pass correctely. */ | 100 | the "//" _is_ part of the filename, pass correctely. */ |
101 | mu_url_get_path (mailbox->url, NULL, 0, &name_len); | 101 | status = mu_url_aget_path (mailbox->url, &mud->name); |
102 | mud->name = calloc (name_len + 1, sizeof (char)); | 102 | if (status) |
103 | if (mud->name == NULL) | ||
104 | { | 103 | { |
105 | free (mud); | 104 | free (mud); |
106 | mailbox->data = NULL; | 105 | mailbox->data = NULL; |
107 | return ENOMEM; | 106 | return status; |
108 | } | 107 | } |
109 | mu_url_get_path (mailbox->url, mud->name, name_len + 1, NULL); | ||
110 | 108 | ||
111 | mud->state = MBOX_NO_STATE; | 109 | mud->state = MBOX_NO_STATE; |
112 | 110 | ... | ... |
... | @@ -100,10 +100,9 @@ nntp_folder_open (mu_folder_t folder, int flags) | ... | @@ -100,10 +100,9 @@ nntp_folder_open (mu_folder_t folder, int flags) |
100 | { | 100 | { |
101 | f_nntp_t f_nntp = folder->data; | 101 | f_nntp_t f_nntp = folder->data; |
102 | mu_stream_t carrier = NULL; | 102 | mu_stream_t carrier = NULL; |
103 | char *host; | 103 | const char *host; |
104 | long port = MU_NNTP_DEFAULT_PORT; /* default nntp port. */ | 104 | long port = MU_NNTP_DEFAULT_PORT; /* default nntp port. */ |
105 | int status = 0; | 105 | int status = 0; |
106 | size_t len = 0; | ||
107 | 106 | ||
108 | /* If we are already open for business, noop. */ | 107 | /* If we are already open for business, noop. */ |
109 | mu_monitor_wrlock (folder->monitor); | 108 | mu_monitor_wrlock (folder->monitor); |
... | @@ -115,25 +114,21 @@ nntp_folder_open (mu_folder_t folder, int flags) | ... | @@ -115,25 +114,21 @@ nntp_folder_open (mu_folder_t folder, int flags) |
115 | mu_monitor_unlock (folder->monitor); | 114 | mu_monitor_unlock (folder->monitor); |
116 | 115 | ||
117 | /* Fetch the server name and the port in the mu_url_t. */ | 116 | /* Fetch the server name and the port in the mu_url_t. */ |
118 | status = mu_url_get_host (folder->url, NULL, 0, &len); | 117 | status = mu_url_sget_host (folder->url, &host); |
119 | if (status != 0) | 118 | if (status != 0) |
120 | return status; | 119 | return status; |
121 | host = malloc (len + 1); | ||
122 | if (!host) | ||
123 | return ENOMEM; | ||
124 | mu_url_get_host (folder->url, host, len + 1, NULL); | ||
125 | mu_url_get_port (folder->url, &port); | 120 | mu_url_get_port (folder->url, &port); |
126 | 121 | ||
127 | folder->flags = flags; | 122 | folder->flags = flags; |
128 | 123 | ||
129 | /* Create the networking stack. */ | 124 | /* Create the networking stack. */ |
130 | status = mu_tcp_stream_create (&carrier, host, port, folder->flags); | 125 | status = mu_tcp_stream_create (&carrier, host, port, folder->flags); |
131 | free (host); | ||
132 | if (status != 0) | 126 | if (status != 0) |
133 | return status; | 127 | return status; |
134 | /* Ask for the stream internal buffering mechanism scheme. */ | 128 | /* Ask for the stream internal buffering mechanism scheme. */ |
135 | mu_stream_setbufsiz (carrier, BUFSIZ); | 129 | mu_stream_setbufsiz (carrier, BUFSIZ); |
136 | FOLDER_DEBUG2 (folder, MU_DEBUG_PROT, "folder_nntp_open (%s:%d)\n", host, port); | 130 | FOLDER_DEBUG2 (folder, MU_DEBUG_PROT, "folder_nntp_open (%s:%d)\n", |
131 | host, port); | ||
137 | 132 | ||
138 | status = mu_nntp_create (&f_nntp->nntp); | 133 | status = mu_nntp_create (&f_nntp->nntp); |
139 | if (status == 0) | 134 | if (status == 0) | ... | ... |
... | @@ -92,7 +92,6 @@ _nntp_mailbox_init (mu_mailbox_t mbox) | ... | @@ -92,7 +92,6 @@ _nntp_mailbox_init (mu_mailbox_t mbox) |
92 | { | 92 | { |
93 | m_nntp_t m_nntp; | 93 | m_nntp_t m_nntp; |
94 | int status = 0; | 94 | int status = 0; |
95 | size_t name_len = 0; | ||
96 | 95 | ||
97 | /* Allocate specifics for nntp data. */ | 96 | /* Allocate specifics for nntp data. */ |
98 | m_nntp = mbox->data = calloc (1, sizeof (*m_nntp)); | 97 | m_nntp = mbox->data = calloc (1, sizeof (*m_nntp)); |
... | @@ -106,19 +105,19 @@ _nntp_mailbox_init (mu_mailbox_t mbox) | ... | @@ -106,19 +105,19 @@ _nntp_mailbox_init (mu_mailbox_t mbox) |
106 | m_nntp->mailbox = mbox; /* Back pointer. */ | 105 | m_nntp->mailbox = mbox; /* Back pointer. */ |
107 | 106 | ||
108 | /* Retrieve the name of the newsgroup from the URL. */ | 107 | /* Retrieve the name of the newsgroup from the URL. */ |
109 | mu_url_get_path (mbox->url, NULL, 0, &name_len); | 108 | status = mu_url_aget_path (mbox->url, &m_nntp->name); |
110 | if (name_len == 0) | 109 | if (status == MU_ERR_NOENT) |
111 | { | 110 | { |
112 | /* name "INBOX" is the default. */ | 111 | m_nntp->name = strdup ("INBOX"); |
113 | m_nntp->name = calloc (6, sizeof (char)); | 112 | if (!m_nntp->name) |
114 | strcpy (m_nntp->name, "INBOX"); | 113 | return ENOMEM; |
115 | } | 114 | } |
116 | else | 115 | else if (status) |
116 | return status; | ||
117 | else | ||
117 | { | 118 | { |
118 | char *p; | 119 | char *p; |
119 | m_nntp->name = calloc (name_len + 1, sizeof (char)); | 120 | p = strchr (m_nntp->name, '/'); |
120 | mu_url_get_path (mbox->url, m_nntp->name, name_len + 1, NULL); | ||
121 | p = strchr (m_nntp->name,'/'); | ||
122 | if (p) | 121 | if (p) |
123 | *p = '\0'; | 122 | *p = '\0'; |
124 | } | 123 | } | ... | ... |
... | @@ -680,8 +680,7 @@ pop_open (mu_mailbox_t mbox, int flags) | ... | @@ -680,8 +680,7 @@ pop_open (mu_mailbox_t mbox, int flags) |
680 | { | 680 | { |
681 | pop_data_t mpd = mbox->data; | 681 | pop_data_t mpd = mbox->data; |
682 | int status; | 682 | int status; |
683 | char *host; | 683 | const char *host; |
684 | size_t hostlen = 0; | ||
685 | long port = MU_POP_PORT; | 684 | long port = MU_POP_PORT; |
686 | 685 | ||
687 | /* Sanity checks. */ | 686 | /* Sanity checks. */ |
... | @@ -689,11 +688,9 @@ pop_open (mu_mailbox_t mbox, int flags) | ... | @@ -689,11 +688,9 @@ pop_open (mu_mailbox_t mbox, int flags) |
689 | return EINVAL; | 688 | return EINVAL; |
690 | 689 | ||
691 | /* Fetch the pop server name and the port in the mu_url_t. */ | 690 | /* Fetch the pop server name and the port in the mu_url_t. */ |
692 | status = mu_url_get_host (mbox->url, NULL, 0, &hostlen); | 691 | status = mu_url_sget_host (mbox->url, &host); |
693 | if (status != 0) | 692 | if (status != 0) |
694 | return status; | 693 | return status; |
695 | host = alloca (hostlen + 1); | ||
696 | mu_url_get_host (mbox->url, host, hostlen + 1, NULL); | ||
697 | mu_url_get_port (mbox->url, &port); | 694 | mu_url_get_port (mbox->url, &port); |
698 | 695 | ||
699 | mbox->flags = flags; | 696 | mbox->flags = flags; |
... | @@ -2044,7 +2041,6 @@ pop_get_user (mu_authority_t auth) | ... | @@ -2044,7 +2041,6 @@ pop_get_user (mu_authority_t auth) |
2044 | mu_ticket_t ticket = NULL; | 2041 | mu_ticket_t ticket = NULL; |
2045 | int status; | 2042 | int status; |
2046 | /* Fetch the user from them. */ | 2043 | /* Fetch the user from them. */ |
2047 | size_t n = 0; | ||
2048 | 2044 | ||
2049 | mu_authority_get_ticket (auth, &ticket); | 2045 | mu_authority_get_ticket (auth, &ticket); |
2050 | if (mpd->user) | 2046 | if (mpd->user) |
... | @@ -2053,14 +2049,11 @@ pop_get_user (mu_authority_t auth) | ... | @@ -2053,14 +2049,11 @@ pop_get_user (mu_authority_t auth) |
2053 | mpd->user = NULL; | 2049 | mpd->user = NULL; |
2054 | } | 2050 | } |
2055 | /* Was it in the URL? */ | 2051 | /* Was it in the URL? */ |
2056 | status = mu_url_get_user (mbox->url, NULL, 0, &n); | 2052 | status = mu_url_aget_user (mbox->url, &mpd->user); |
2057 | if (status != 0 || n == 0) | 2053 | if (status == MU_ERR_NOENT) |
2058 | mu_ticket_pop (ticket, mbox->url, "Pop User: ", &mpd->user); | 2054 | mu_ticket_pop (ticket, mbox->url, "Pop User: ", &mpd->user); |
2059 | else | 2055 | else if (status) |
2060 | { | 2056 | return status; |
2061 | mpd->user = calloc (1, n + 1); | ||
2062 | mu_url_get_user (mbox->url, mpd->user, n + 1, NULL); | ||
2063 | } | ||
2064 | return 0; | 2057 | return 0; |
2065 | } | 2058 | } |
2066 | 2059 | ||
... | @@ -2073,8 +2066,6 @@ pop_get_passwd (mu_authority_t auth) | ... | @@ -2073,8 +2066,6 @@ pop_get_passwd (mu_authority_t auth) |
2073 | pop_data_t mpd = mbox->data; | 2066 | pop_data_t mpd = mbox->data; |
2074 | mu_ticket_t ticket = NULL; | 2067 | mu_ticket_t ticket = NULL; |
2075 | int status; | 2068 | int status; |
2076 | /* Fetch the user from them. */ | ||
2077 | size_t n = 0; | ||
2078 | 2069 | ||
2079 | mu_authority_get_ticket (auth, &ticket); | 2070 | mu_authority_get_ticket (auth, &ticket); |
2080 | if (mpd->passwd) | 2071 | if (mpd->passwd) |
... | @@ -2083,14 +2074,11 @@ pop_get_passwd (mu_authority_t auth) | ... | @@ -2083,14 +2074,11 @@ pop_get_passwd (mu_authority_t auth) |
2083 | mpd->passwd = NULL; | 2074 | mpd->passwd = NULL; |
2084 | } | 2075 | } |
2085 | /* Was it in the URL? */ | 2076 | /* Was it in the URL? */ |
2086 | status = mu_url_get_passwd (mbox->url, NULL, 0, &n); | 2077 | status = mu_url_aget_passwd (mbox->url, &mpd->passwd); |
2087 | if (status != 0 || n == 0) | 2078 | if (status == MU_ERR_NOENT) |
2088 | mu_ticket_pop (ticket, mbox->url, "Pop Passwd: ", &mpd->passwd); | 2079 | mu_ticket_pop (ticket, mbox->url, "Pop Passwd: ", &mpd->passwd); |
2089 | else | 2080 | else if (status) |
2090 | { | 2081 | return status; |
2091 | mpd->passwd = calloc (1, n + 1); | ||
2092 | mu_url_get_passwd (mbox->url, mpd->passwd, n + 1, NULL); | ||
2093 | } | ||
2094 | return 0; | 2082 | return 0; |
2095 | } | 2083 | } |
2096 | 2084 | ... | ... |
... | @@ -242,10 +242,11 @@ amd_array_shrink (struct _amd_data *amd, size_t index) | ... | @@ -242,10 +242,11 @@ amd_array_shrink (struct _amd_data *amd, size_t index) |
242 | 242 | ||
243 | 243 | ||
244 | int | 244 | int |
245 | amd_init_mailbox (mu_mailbox_t mailbox, size_t amd_size, struct _amd_data **pamd) | 245 | amd_init_mailbox (mu_mailbox_t mailbox, size_t amd_size, |
246 | struct _amd_data **pamd) | ||
246 | { | 247 | { |
248 | int status; | ||
247 | struct _amd_data *amd; | 249 | struct _amd_data *amd; |
248 | size_t name_len; | ||
249 | 250 | ||
250 | if (mailbox == NULL) | 251 | if (mailbox == NULL) |
251 | return MU_ERR_MBX_NULL; | 252 | return MU_ERR_MBX_NULL; |
... | @@ -259,15 +260,13 @@ amd_init_mailbox (mu_mailbox_t mailbox, size_t amd_size, struct _amd_data **pamd | ... | @@ -259,15 +260,13 @@ amd_init_mailbox (mu_mailbox_t mailbox, size_t amd_size, struct _amd_data **pamd |
259 | /* Back pointer. */ | 260 | /* Back pointer. */ |
260 | amd->mailbox = mailbox; | 261 | amd->mailbox = mailbox; |
261 | 262 | ||
262 | mu_url_get_path (mailbox->url, NULL, 0, &name_len); | 263 | status = mu_url_aget_path (mailbox->url, &amd->name); |
263 | amd->name = calloc (name_len + 1, sizeof (char)); | 264 | if (status) |
264 | if (amd->name == NULL) | ||
265 | { | 265 | { |
266 | free (amd); | 266 | free (amd); |
267 | mailbox->data = NULL; | 267 | mailbox->data = NULL; |
268 | return ENOMEM; | 268 | return status; |
269 | } | 269 | } |
270 | mu_url_get_path (mailbox->url, amd->name, name_len + 1, NULL); | ||
271 | 270 | ||
272 | /* Overloading the defaults. */ | 271 | /* Overloading the defaults. */ |
273 | mailbox->_destroy = amd_destroy; | 272 | mailbox->_destroy = amd_destroy; | ... | ... |
... | @@ -125,7 +125,6 @@ sendmail_open (mu_mailer_t mailer, int flags) | ... | @@ -125,7 +125,6 @@ sendmail_open (mu_mailer_t mailer, int flags) |
125 | { | 125 | { |
126 | sendmail_t sendmail = mailer->data; | 126 | sendmail_t sendmail = mailer->data; |
127 | int status; | 127 | int status; |
128 | size_t pathlen = 0; | ||
129 | char *path; | 128 | char *path; |
130 | 129 | ||
131 | /* Sanity checks. */ | 130 | /* Sanity checks. */ |
... | @@ -134,13 +133,9 @@ sendmail_open (mu_mailer_t mailer, int flags) | ... | @@ -134,13 +133,9 @@ sendmail_open (mu_mailer_t mailer, int flags) |
134 | 133 | ||
135 | mailer->flags = flags; | 134 | mailer->flags = flags; |
136 | 135 | ||
137 | if ((status = mu_url_get_path (mailer->url, NULL, 0, &pathlen)) != 0 | 136 | if ((status = mu_url_aget_path (mailer->url, &path))) |
138 | || pathlen == 0) | ||
139 | return status; | 137 | return status; |
140 | 138 | ||
141 | path = calloc (pathlen + 1, sizeof (char)); | ||
142 | mu_url_get_path (mailer->url, path, pathlen + 1, NULL); | ||
143 | |||
144 | if (access (path, X_OK) == -1) | 139 | if (access (path, X_OK) == -1) |
145 | { | 140 | { |
146 | free (path); | 141 | free (path); | ... | ... |
... | @@ -297,7 +297,6 @@ smtp_open (mu_mailer_t mailer, int flags) | ... | @@ -297,7 +297,6 @@ smtp_open (mu_mailer_t mailer, int flags) |
297 | smtp_t smtp = mailer->data; | 297 | smtp_t smtp = mailer->data; |
298 | int status; | 298 | int status; |
299 | long port; | 299 | long port; |
300 | size_t buf_len = 0; | ||
301 | 300 | ||
302 | /* Sanity checks. */ | 301 | /* Sanity checks. */ |
303 | if (!smtp) | 302 | if (!smtp) |
... | @@ -305,27 +304,21 @@ smtp_open (mu_mailer_t mailer, int flags) | ... | @@ -305,27 +304,21 @@ smtp_open (mu_mailer_t mailer, int flags) |
305 | 304 | ||
306 | mailer->flags = flags; | 305 | mailer->flags = flags; |
307 | 306 | ||
308 | /* Fetch the mailer server name and the port in the mu_url_t. */ | 307 | if ((status = mu_url_get_port (mailer->url, &port)) != 0) |
309 | if ((status = mu_url_get_host (mailer->url, NULL, 0, &buf_len)) != 0 | 308 | return status; |
310 | || buf_len == 0 || (status = mu_url_get_port (mailer->url, &port)) != 0) | ||
311 | return status; | ||
312 | 309 | ||
313 | switch (smtp->state) | 310 | switch (smtp->state) |
314 | { | 311 | { |
315 | case SMTP_NO_STATE: | 312 | case SMTP_NO_STATE: |
316 | /* Set up the mailer, open the stream, etc. */ | ||
317 | /* Get the mailhost. */ | ||
318 | if (smtp->mailhost) | 313 | if (smtp->mailhost) |
319 | { | 314 | { |
320 | free (smtp->mailhost); | 315 | free (smtp->mailhost); |
321 | smtp->mailhost = NULL; | 316 | smtp->mailhost = NULL; |
322 | } | 317 | } |
323 | smtp->mailhost = calloc (buf_len + 1, sizeof (char)); | ||
324 | |||
325 | if (smtp->mailhost == NULL) | ||
326 | return ENOMEM; | ||
327 | 318 | ||
328 | mu_url_get_host (mailer->url, smtp->mailhost, buf_len + 1, NULL); | 319 | /* Fetch the mailer server name and the port in the mu_url_t. */ |
320 | if ((status = mu_url_aget_host (mailer->url, &smtp->mailhost)) != 0) | ||
321 | return status; | ||
329 | 322 | ||
330 | if (smtp->localhost) | 323 | if (smtp->localhost) |
331 | { | 324 | { | ... | ... |
... | @@ -378,35 +378,27 @@ static int | ... | @@ -378,35 +378,27 @@ static int |
378 | get_user (mu_url_t url, const char *filename, char **user) | 378 | get_user (mu_url_t url, const char *filename, char **user) |
379 | { | 379 | { |
380 | char *u = 0; | 380 | char *u = 0; |
381 | int status; | ||
381 | 382 | ||
382 | if (url) | 383 | if (url) |
383 | { | 384 | { |
384 | size_t n = 0; | 385 | status = mu_url_aget_user (url, &u); |
385 | mu_url_get_user (url, NULL, 0, &n); | 386 | if (status && status != MU_ERR_NOENT) |
386 | 387 | return status; | |
387 | if (n) | ||
388 | { | ||
389 | u = calloc (1, n + 1); | ||
390 | mu_url_get_user (url, u, n + 1, NULL); | ||
391 | } | ||
392 | } | 388 | } |
389 | |||
393 | if (!u && filename) | 390 | if (!u && filename) |
394 | { | 391 | { |
395 | mu_url_t ticket = 0; | 392 | mu_url_t ticket = 0; |
396 | int e = get_ticket (url, NULL, filename, &ticket); | 393 | status = get_ticket (url, NULL, filename, &ticket); |
397 | if (e) | 394 | if (status) |
398 | return e; | 395 | return status; |
399 | 396 | ||
400 | if (ticket) | 397 | if (ticket) |
401 | { | 398 | { |
402 | size_t n = 0; | 399 | status = mu_url_aget_user (ticket, &u); |
403 | mu_url_get_user (ticket, NULL, 0, &n); | 400 | if (status && status != MU_ERR_NOENT) |
404 | 401 | return status; | |
405 | if (n) | ||
406 | { | ||
407 | u = calloc (1, n + 1); | ||
408 | mu_url_get_user (ticket, u, n + 1, NULL); | ||
409 | } | ||
410 | mu_url_destroy (&ticket); | 402 | mu_url_destroy (&ticket); |
411 | } | 403 | } |
412 | } | 404 | } |
... | @@ -428,36 +420,28 @@ get_user (mu_url_t url, const char *filename, char **user) | ... | @@ -428,36 +420,28 @@ get_user (mu_url_t url, const char *filename, char **user) |
428 | static int | 420 | static int |
429 | get_pass (mu_url_t url, const char *user, const char *filename, char **pass) | 421 | get_pass (mu_url_t url, const char *user, const char *filename, char **pass) |
430 | { | 422 | { |
423 | int status; | ||
431 | char *u = 0; | 424 | char *u = 0; |
432 | 425 | ||
433 | if (url) | 426 | if (url) |
434 | { | 427 | { |
435 | size_t n = 0; | 428 | status = mu_url_aget_passwd (url, &u); |
436 | mu_url_get_passwd (url, NULL, 0, &n); | 429 | if (status && status != MU_ERR_NOENT) |
437 | 430 | return status; | |
438 | if (n) | ||
439 | { | ||
440 | u = calloc (1, n + 1); | ||
441 | mu_url_get_passwd (url, u, n + 1, NULL); | ||
442 | } | ||
443 | } | 431 | } |
432 | |||
444 | if (!u && filename) | 433 | if (!u && filename) |
445 | { | 434 | { |
446 | mu_url_t ticket = 0; | 435 | mu_url_t ticket = 0; |
447 | int e = get_ticket (url, user, filename, &ticket); | 436 | status = get_ticket (url, user, filename, &ticket); |
448 | if (e) | 437 | if (status) |
449 | return e; | 438 | return status; |
450 | 439 | ||
451 | if (ticket) | 440 | if (ticket) |
452 | { | 441 | { |
453 | size_t n = 0; | 442 | status = mu_url_aget_passwd (ticket, &u); |
454 | mu_url_get_passwd (ticket, NULL, 0, &n); | 443 | if (status && status != MU_ERR_NOENT) |
455 | 444 | return status; | |
456 | if (n) | ||
457 | { | ||
458 | u = calloc (1, n + 1); | ||
459 | mu_url_get_passwd (ticket, u, n + 1, NULL); | ||
460 | } | ||
461 | mu_url_destroy (&ticket); | 445 | mu_url_destroy (&ticket); |
462 | } | 446 | } |
463 | } | 447 | } | ... | ... |
-
Please register or sign in to post a comment