Commit fb88ec09 fb88ec09f517d42e4bc1a9a45009b12db7602a5d by Sergey Poznyakoff

(amd_url_init): New function

1 parent 56f96e76
...@@ -65,6 +65,7 @@ ...@@ -65,6 +65,7 @@
65 #include <mailutils/observer.h> 65 #include <mailutils/observer.h>
66 #include <mailbox0.h> 66 #include <mailbox0.h>
67 #include <registrar0.h> 67 #include <registrar0.h>
68 #include <url0.h>
68 #include <amd.h> 69 #include <amd.h>
69 70
70 static void amd_destroy __P((mailbox_t mailbox)); 71 static void amd_destroy __P((mailbox_t mailbox));
...@@ -197,7 +198,6 @@ static int ...@@ -197,7 +198,6 @@ static int
197 amd_open (mailbox_t mailbox, int flags) 198 amd_open (mailbox_t mailbox, int flags)
198 { 199 {
199 struct _amd_data *amd = mailbox->data; 200 struct _amd_data *amd = mailbox->data;
200 int status = 0;
201 struct stat st; 201 struct stat st;
202 202
203 mailbox->flags = flags; 203 mailbox->flags = flags;
...@@ -1314,3 +1314,50 @@ amd_envelope_sender (envelope_t envelope, char *buf, size_t len, size_t *psize) ...@@ -1314,3 +1314,50 @@ amd_envelope_sender (envelope_t envelope, char *buf, size_t len, size_t *psize)
1314 return 0; 1314 return 0;
1315 } 1315 }
1316 1316
1317 static void
1318 amd_url_destroy (url_t url ARG_UNUSED)
1319 {
1320 }
1321
1322 int
1323 amd_url_init (url_t url, const char *scheme)
1324 {
1325 const char *name = url_to_string (url);
1326 const char *path_ptr = name;
1327 size_t len = strlen (name);
1328 size_t scheme_len = strlen (scheme);
1329
1330 if (!name)
1331 return 0;
1332
1333 if (strncmp (MU_PATH_SCHEME, name, MU_PATH_SCHEME_LEN) == 0)
1334 path_ptr = name;
1335 /* reject the obvious */
1336 else if (strncmp (scheme, name, scheme_len) != 0
1337 || len < scheme_len + 1)
1338 return EINVAL;
1339 else
1340 path_ptr = name + scheme_len;
1341
1342 /* TYPE */
1343 url->_destroy = amd_url_destroy;
1344
1345 /* SCHEME */
1346 url->scheme = strdup (scheme);
1347 if (url->scheme == NULL)
1348 {
1349 amd_url_destroy (url);
1350 return ENOMEM;
1351 }
1352
1353 /* PATH */
1354 url->path = strdup (path_ptr);
1355 if (url->path == NULL)
1356 {
1357 amd_url_destroy (url);
1358 return ENOMEM;
1359 }
1360
1361 return 0;
1362 }
1363
......
...@@ -97,3 +97,4 @@ void _amd_message_insert __P((struct _amd_data *mhd, ...@@ -97,3 +97,4 @@ void _amd_message_insert __P((struct _amd_data *mhd,
97 int amd_message_stream_open __P((struct _amd_message *mhm)); 97 int amd_message_stream_open __P((struct _amd_message *mhm));
98 void amd_message_stream_close __P((struct _amd_message *mhm)); 98 void amd_message_stream_close __P((struct _amd_message *mhm));
99 void amd_cleanup (void *arg); 99 void amd_cleanup (void *arg);
100 int amd_url_init (url_t url, const char *scheme);
......