Annotation of libaitwww/example/test_base64.c, revision 1.1.2.2
1.1.2.1 misho 1: #include <stdio.h>
1.1.2.2 ! misho 2: #include <string.h>
1.1.2.1 misho 3: #include <unistd.h>
4: #include <fcntl.h>
1.1.2.2 ! misho 5: #include <sys/limits.h>
! 6: #include <aitio.h>
1.1.2.1 misho 7: #include <aitwww.h>
8:
9:
10: int
11: main(int argc, char **argv)
12: {
1.1.2.2 ! misho 13: int rlen, fd = STDIN_FILENO;
! 14: ait_val_t *e, *d, s, src;
1.1.2.1 misho 15:
16: if (argc > 1) {
17: fd = open(argv[1], O_RDONLY);
18: if (fd == -1) {
19: perror("open");
20: return 1;
21: }
1.1.2.2 ! misho 22: AIT_SET_STRSIZ(&src, lseek(fd, 0, SEEK_END));
! 23: lseek(fd, 0, SEEK_SET);
! 24: } else
! 25: AIT_SET_STRSIZ(&src, USHRT_MAX + 1);
! 26: rlen = read(fd, AIT_GET_STR(&src), AIT_LEN(&src));
! 27: if (rlen == -1) {
! 28: perror("read");
! 29: if (fd > 2)
! 30: close(fd);
! 31: return 2;
! 32: } else {
! 33: AIT_INIT_VAL2(&s, string);
! 34: AIT_SET_STRLCPY(&s, AIT_GET_STR(&src), rlen);
! 35: AIT_FREE_VAL(&src);
1.1.2.1 misho 36: }
37: if (fd > 2)
38: close(fd);
1.1.2.2 ! misho 39:
! 40: e = www_b64encode(&s);
! 41: if (!e) {
! 42: ioLIBERR(www);
! 43: return 3;
! 44: }
! 45: printf("\n\n--- encode base64 len=%u ---\n%s\n", AIT_LEN(e), AIT_GET_STR(e));
! 46:
! 47: d = www_b64decode(e);
! 48: if (!d) {
! 49: ioLIBERR(www);
! 50: io_freeVar(&e);
! 51: return 4;
! 52: }
! 53: printf("\n\n--- decode base64 len=%u ---\n%s\n", AIT_LEN(d), AIT_GET_STR(d));
! 54:
! 55: if ((rlen = io_cmpVar(&s, d)) < 0)
! 56: printf("\n\n>>> FAIL = -1\n");
! 57: else if (!rlen)
! 58: printf("\n\n>>> PASS = 0\n");
! 59: else
! 60: printf("\n\n>>> FAIL = 1\n");
! 61:
! 62: io_freeVar(&d);
! 63: io_freeVar(&e);
! 64: AIT_FREE_VAL(&s);
1.1.2.1 misho 65: return 0;
66: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>