Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
mailutils
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
c00bfa73
...
c00bfa73fc3764dbbcc282f3f90ff080127fe694
authored
2007-07-05 20:00:19 +0000
by
Sergey Poznyakoff
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Rewrite using sget accessors
1 parent
4e342c17
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
22 deletions
examples/url-parse.c
examples/url-parse.c
View file @
c00bfa7
...
...
@@ -22,18 +22,31 @@
#include <mailutils/errno.h>
#include <mailutils/url.h>
#define CAT2(a,b) a ## b
#define GET_AND_PRINT(field,u,buf,status) \
status = CAT2(mu_url_sget_,field) (u, &buf); \
if (status == MU_ERR_NOENT) \
buf = ""; \
else if (status) \
{ \
mu_error ("cannot get %s: %s", #field, mu_strerror (status)); \
exit (1); \
} \
printf ("\t" #field " <%s>\n", buf)
int
main
()
{
char
str
[
1024
];
char
buffer
[
1024
];
long
port
=
0
;
int
len
=
sizeof
(
buffer
);
mu_url_t
u
=
NULL
;
while
(
fgets
(
str
,
sizeof
(
str
),
stdin
)
!=
NULL
)
{
int
rc
;
const
char
*
buf
;
str
[
strlen
(
str
)
-
1
]
=
'\0'
;
/* chop newline */
if
(
strspn
(
str
,
"
\t
"
)
==
strlen
(
str
))
...
...
@@ -52,29 +65,22 @@ main ()
}
printf
(
"%s => SUCCESS
\n
"
,
str
);
mu_url_get_scheme
(
u
,
buffer
,
len
,
NULL
);
printf
(
"
\t
scheme <%s>
\n
"
,
buffer
);
mu_url_get_user
(
u
,
buffer
,
len
,
NULL
);
printf
(
"
\t
user <%s>
\n
"
,
buffer
);
mu_url_get_passwd
(
u
,
buffer
,
len
,
NULL
);
printf
(
"
\t
passwd <%s>
\n
"
,
buffer
);
mu_url_get_auth
(
u
,
buffer
,
len
,
NULL
);
printf
(
"
\t
auth <%s>
\n
"
,
buffer
);
GET_AND_PRINT
(
scheme
,
u
,
buf
,
rc
);
GET_AND_PRINT
(
user
,
u
,
buf
,
rc
);
GET_AND_PRINT
(
passwd
,
u
,
buf
,
rc
);
GET_AND_PRINT
(
auth
,
u
,
buf
,
rc
);
GET_AND_PRINT
(
host
,
u
,
buf
,
rc
);
mu_url_get_host
(
u
,
buffer
,
len
,
NULL
);
printf
(
"
\t
host <%s>
\n
"
,
buffer
);
mu_url_get_port
(
u
,
&
port
);
rc
=
mu_url_get_port
(
u
,
&
port
);
if
(
rc
)
{
mu_error
(
"cannot get %s: %s"
,
"port"
,
mu_strerror
(
rc
));
exit
(
1
);
}
printf
(
"
\t
port %ld
\n
"
,
port
);
mu_url_get_path
(
u
,
buffer
,
len
,
NULL
);
printf
(
"
\t
path <%s>
\n
"
,
buffer
);
mu_url_get_query
(
u
,
buffer
,
len
,
NULL
);
printf
(
"
\t
query <%s>
\n
"
,
buffer
);
GET_AND_PRINT
(
path
,
u
,
buf
,
rc
);
GET_AND_PRINT
(
query
,
u
,
buf
,
rc
);
mu_url_destroy
(
&
u
);
...
...
Please
register
or
sign in
to post a comment