Commit c00bfa73 c00bfa73fc3764dbbcc282f3f90ff080127fe694 by Sergey Poznyakoff

Rewrite using sget accessors

1 parent 4e342c17
...@@ -22,18 +22,31 @@ ...@@ -22,18 +22,31 @@
22 #include <mailutils/errno.h> 22 #include <mailutils/errno.h>
23 #include <mailutils/url.h> 23 #include <mailutils/url.h>
24 24
25 #define CAT2(a,b) a ## b
26
27 #define GET_AND_PRINT(field,u,buf,status) \
28 status = CAT2(mu_url_sget_,field) (u, &buf); \
29 if (status == MU_ERR_NOENT) \
30 buf = ""; \
31 else if (status) \
32 { \
33 mu_error ("cannot get %s: %s", #field, mu_strerror (status)); \
34 exit (1); \
35 } \
36 printf ("\t" #field " <%s>\n", buf)
37
38
25 int 39 int
26 main () 40 main ()
27 { 41 {
28 char str[1024]; 42 char str[1024];
29 char buffer[1024];
30 long port = 0; 43 long port = 0;
31 int len = sizeof (buffer);
32 mu_url_t u = NULL; 44 mu_url_t u = NULL;
33 45
34 while (fgets (str, sizeof (str), stdin) != NULL) 46 while (fgets (str, sizeof (str), stdin) != NULL)
35 { 47 {
36 int rc; 48 int rc;
49 const char *buf;
37 50
38 str[strlen (str) - 1] = '\0'; /* chop newline */ 51 str[strlen (str) - 1] = '\0'; /* chop newline */
39 if (strspn (str, " \t") == strlen (str)) 52 if (strspn (str, " \t") == strlen (str))
...@@ -52,29 +65,22 @@ main () ...@@ -52,29 +65,22 @@ main ()
52 } 65 }
53 printf ("%s => SUCCESS\n", str); 66 printf ("%s => SUCCESS\n", str);
54 67
55 mu_url_get_scheme (u, buffer, len, NULL); 68 GET_AND_PRINT (scheme, u, buf, rc);
56 printf ("\tscheme <%s>\n", buffer); 69 GET_AND_PRINT (user, u, buf, rc);
57 70 GET_AND_PRINT (passwd, u, buf, rc);
58 mu_url_get_user (u, buffer, len, NULL); 71 GET_AND_PRINT (auth, u, buf, rc);
59 printf ("\tuser <%s>\n", buffer); 72 GET_AND_PRINT (host, u, buf, rc);
60
61 mu_url_get_passwd (u, buffer, len, NULL);
62 printf ("\tpasswd <%s>\n", buffer);
63
64 mu_url_get_auth (u, buffer, len, NULL);
65 printf ("\tauth <%s>\n", buffer);
66 73
67 mu_url_get_host (u, buffer, len, NULL); 74 rc = mu_url_get_port (u, &port);
68 printf ("\thost <%s>\n", buffer); 75 if (rc)
69 76 {
70 mu_url_get_port (u, &port); 77 mu_error ("cannot get %s: %s", "port", mu_strerror (rc));
78 exit (1);
79 }
71 printf ("\tport %ld\n", port); 80 printf ("\tport %ld\n", port);
72 81
73 mu_url_get_path (u, buffer, len, NULL); 82 GET_AND_PRINT (path, u, buf, rc);
74 printf ("\tpath <%s>\n", buffer); 83 GET_AND_PRINT (query, u, buf, rc);
75
76 mu_url_get_query (u, buffer, len, NULL);
77 printf ("\tquery <%s>\n", buffer);
78 84
79 mu_url_destroy (&u); 85 mu_url_destroy (&u);
80 86
......