diff options
author | Sam Roberts <sroberts@uniserve.com> | 2001-07-18 12:51:41 +0000 |
---|---|---|
committer | Sam Roberts <sroberts@uniserve.com> | 2001-07-18 12:51:41 +0000 |
commit | 389d4aacf9b3e06736d8632ee4575b5e3a707e63 (patch) | |
tree | 5daf21fd3b6da1139a74e201c4f09a6dd972f4eb /examples | |
parent | 7ce849a0541ee9e7b4493f5b433687d4794eb624 (diff) | |
download | mailutils-389d4aacf9b3e06736d8632ee4575b5e3a707e63.tar.gz mailutils-389d4aacf9b3e06736d8632ee4575b5e3a707e63.tar.bz2 |
Added example of URL parsing, and test for parsing.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/.cvsignore | 3 | ||||
-rw-r--r-- | examples/Makefile | 33 | ||||
-rw-r--r-- | examples/Urls | 65 | ||||
-rw-r--r-- | examples/url-parse.c | 64 |
4 files changed, 146 insertions, 19 deletions
diff --git a/examples/.cvsignore b/examples/.cvsignore index 8d2b3d5b6..011c9e531 100644 --- a/examples/.cvsignore +++ b/examples/.cvsignore @@ -1,7 +1,10 @@ +.gdbinit bad-dates.out addr Addrs.test +Urls.test mbox-dates mbox-dates.out mbox-explode +url-parse _* diff --git a/examples/Makefile b/examples/Makefile index bcaaffa76..eeb38e433 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -1,39 +1,34 @@ # Makefile -CFLAGS = -g -I../include +CFLAGS = -g -I../include -Wall LDFLAGS = -g -static -LIBS = ../mailbox/.libs/libmailbox.a ../lib/libmailutils.a +LDLIBS = ../mailbox/.libs/libmailbox.a ../lib/libmailutils.a -lsocket -default: addr mbox-explode mbox-dates +EXES = addr mbox-explode mbox-dates mbox-auth url-parse -# showmail +$(EXES): $(LDLIBS) -showmail: showmail.c $(LIBS) - $(CC) $(CFLAGS) -o $@ $< $(LIBS) - -# example of saving MIME parts to a file - -mbox-explode: mbox-explode.c $(LIBS) - $(CC) $(CFLAGS) -o $@ $< $(LIBS) +default: $(EXES) # example of parsing the date fields, prints all the incorrectly # formatted dates in a mailbox. -mbox-dates: mbox-dates.c $(LIBS) - $(CC) $(CFLAGS) -o $@ $< $(LIBS) - bad-dates: mbox-dates for m in ~/Mail/*; do ./mbox-dates $$m; done | tee bad-dates.out # addr example and test -test: addr +addr.test: addr ./addr < Addrs > Addrs.test - diff -u Addrs.good Addrs.test @echo "---- There should be no differences! ----" + diff -u Addrs.good Addrs.test + +# url example and test -addr: addr.c $(LIBS) - $(CC) $(CFLAGS) -o $@ $< $(LIBS) +url.test: url-parse + ./url-parse < Urls > Urls.test + @echo "---- There should be no differences! ----" + diff -u Urls.good Urls.test # clean and empty @@ -41,5 +36,5 @@ clean: rm -f *.o empty: clean - rm -f addr showmail mbox-explode mbox-dates + rm -f $(EXES) diff --git a/examples/Urls b/examples/Urls new file mode 100644 index 000000000..fa493cc30 --- /dev/null +++ b/examples/Urls @@ -0,0 +1,65 @@ +scheme://%75%73%65%72:%70%61%73%73@%68%6f%73%74 + +ftp://user:pass@host//a/path +ftp://:pass@host//a/path +ftp://user:@host//a/path +ftp://user:pass@//a/path +ftp://user:@//a/path +ftp://:@host//a/path +ftp://:pass@//a/path +ftp://:@//a/path +ftp://://a/path +ftp://@//a/path +ftp:////a/path + +ftp://user:pass@host/a/path +ftp://:pass@host/a/path +ftp://user:@host/a/path +ftp://user:pass@/a/path +ftp://user:@/a/path +ftp://:@host/a/path +ftp://:pass@/a/path +ftp://:@/a/path +ftp://:/a/path +ftp://@/a/path +ftp:///a/path + +pop://pop.example.net +pop://user@pop.example.net +pop://user:passwd@pop.example.net +pop://user;auth=*@pop.example.net +pop://pop.example.net:111 +pop://user@pop.example.net:111 +pop://user:passwd@pop.example.net:111 +pop://user;auth=*@pop.example.net:111 + +imap://imap.example.net +imap://user@imap.example.net +imap://user:passwd@imap.example.net +imap://user;auth=*@imap.example.net +imap://imap.example.net:111 +imap://user@imap.example.net:111 +imap://user:passwd@imap.example.net:111 +imap://user;auth=*@imap.example.net:111 + +imap://imap.example.net/mbox +imap://user@imap.example.net/mbox +imap://user:passwd@imap.example.net/mbox +imap://user;auth=*@imap.example.net/mbox +imap://imap.example.net:111/mbox +imap://user@imap.example.net:111/mbox +imap://user:passwd@imap.example.net:111/mbox +imap://user;auth=*@imap.example.net:111/mbox + +imap://imap.example.net/mbox/user@host +imap://user@imap.example.net/mbox/user@host +imap://user:passwd@imap.example.net/mbox/user@host +imap://user;auth=*@imap.example.net/mbox/user@host +imap://imap.example.net:111/mbox/user@host +imap://user@imap.example.net:111/mbox/user@host +imap://user:passwd@imap.example.net:111/mbox/user@host +imap://user;auth=*@imap.example.net:111/mbox/user@host + +ftp://ftp.example.org/mbox/user%40host +ftp://ftp.example.org:111/mbox/user%40host + diff --git a/examples/url-parse.c b/examples/url-parse.c new file mode 100644 index 000000000..7b912ba29 --- /dev/null +++ b/examples/url-parse.c @@ -0,0 +1,64 @@ +#include <mailutils/url.h> +#include <stdio.h> +#include <string.h> + +int +main () +{ + char str[1024]; + char buffer[1024]; + long port = 0; + int len = sizeof (buffer); + url_t u = NULL; + + while (fgets (str, sizeof (str), stdin) != NULL) + { + int rc; + + str[strlen (str) - 1] = '\0'; /* chop newline */ + if(strspn(str, " \t") == strlen(str)) + continue; /* skip empty lines */ + if ((rc = url_create(&u, str)) != 0) + { + fprintf(stderr, "url_create %s ERROR: [%d] %s", + str, rc, strerror(rc)); + exit (1); + } + if ((rc = url_parse (u)) != 0) + { + printf ("%s --> FAILED: [%d] %s\n", + str, rc, strerror(rc)); + continue; + } + printf ("%s --> SUCCESS\n", str); + + url_get_scheme (u, buffer, len, NULL); + printf (" scheme <%s>\n", buffer); + + url_get_user (u, buffer, len, NULL); + printf (" user <%s>\n", buffer); + + url_get_passwd (u, buffer, len, NULL); + printf (" passwd <%s>\n", buffer); + + url_get_auth (u, buffer, len, NULL); + printf (" auth <%s>\n", buffer); + + url_get_host (u, buffer, len, NULL); + printf (" host <%s>\n", buffer); + + url_get_port (u, &port); + printf (" port %ld\n", port); + + url_get_path (u, buffer, len, NULL); + printf (" path <%s>\n", buffer); + + url_get_query (u, buffer, len, NULL); + printf (" query <%s>\n", buffer); + + url_destroy (&u); + + } + return 0; +} + |