r6369: update release notes
[Samba.git] / examples / libsmbclient / testbrowse.c
blob27d6a6973882e377f6b4429d7ac14d742408872f
1 #include <sys/types.h>
2 #include <unistd.h>
3 #include <dirent.h>
4 #include <errno.h>
5 #include <stdio.h>
6 #include <string.h>
7 #include <popt.h>
8 #include <stdlib.h>
9 #include <libsmbclient.h>
10 #include "get_auth_data_fn.h"
12 void error_message(char * pMessage)
14 printf("ERROR: %s\n", pMessage);
18 int
19 main(int argc, char * argv[])
21 int debug = 0;
22 int opt;
23 char * p;
24 char * q;
25 char buf[1024];
26 int dir;
27 struct stat stat;
28 struct smbc_dirent * dirent;
29 poptContext pc;
30 struct poptOption long_options[] =
32 POPT_AUTOHELP
34 "debug", 'd', POPT_ARG_INT, &debug,
35 0, "Set debug level", "integer"
38 NULL
42 setbuf(stdout, NULL);
44 pc = poptGetContext("opendir", argc, (const char **)argv, long_options, 0);
46 poptSetOtherOptionHelp(pc, "");
48 while ((opt = poptGetNextOpt(pc)) != -1) {
49 printf("Got option %d = %c\n", opt, opt);
50 switch (opt) {
54 if (smbc_init(get_auth_data_fn, debug) != 0)
56 printf("Could not initialize smbc_ library\n");
57 return 1;
60 for (fputs("url: ", stdout), p = fgets(buf, sizeof(buf), stdin);
61 p != NULL && *p != '\n' && *p != '\0';
62 fputs("url: ", stdout), p = fgets(buf, sizeof(buf), stdin))
64 if ((p = strchr(buf, '\n')) != NULL)
66 *p = '\0';
69 printf("Opening (%s)...\n", buf);
71 if ((dir = smbc_opendir(buf)) < 0)
73 printf("Could not open directory [%s] (%d:%s)\n",
74 buf, errno, strerror(errno));
75 continue;
78 while ((dirent = smbc_readdir(dir)) != NULL)
80 printf("%-30s", dirent->name);
81 printf("%-30s", dirent->comment);
83 switch(dirent->smbc_type)
85 case SMBC_WORKGROUP:
86 printf("WORKGROUP");
87 break;
89 case SMBC_SERVER:
90 printf("SERVER");
91 break;
93 case SMBC_FILE_SHARE:
94 printf("FILE_SHARE");
95 break;
97 case SMBC_PRINTER_SHARE:
98 printf("PRINTER_SHARE");
99 break;
101 case SMBC_COMMS_SHARE:
102 printf("COMMS_SHARE");
103 break;
105 case SMBC_IPC_SHARE:
106 printf("IPC_SHARE");
107 break;
109 case SMBC_DIR:
110 printf("DIR");
111 break;
113 case SMBC_FILE:
114 printf("FILE");
116 q = buf + strlen(buf);
117 strcat(q, "/");
118 strcat(q+1, dirent->name);
119 if (smbc_stat(buf, &stat) < 0)
121 printf(" unknown size (reason %d: %s)",
122 errno, strerror(errno));
124 else
126 printf(" size %lu", (unsigned long) stat.st_size);
128 *p = '\0';
130 break;
132 case SMBC_LINK:
133 printf("LINK");
134 break;
137 printf("\n");
140 smbc_closedir(dir);
143 exit(0);