#include <stdio.h>#include <errno.h>#include <sys/time.h>#include <string.h>#include <unistd.h>#include <stdlib.h>#include <libsmbclient.h>#include "get_auth_data_fn.h"Go to the source code of this file.
Functions | |
| void | print_list_fn (struct print_job_info *pji) |
| int | main (int argc, char *argv[]) |
Variables | |
| int | global_id = 0 |
|
||||||||||||
|
Definition at line 44 of file testsmbc.c. References smbc_dirent::comment, err, errno, fd, fprintf(), get_auth_data_fn, name, SEEK_SET, smbc_close(), smbc_fstat(), smbc_getdents(), smbc_init(), smbc_lseek(), smbc_mkdir(), smbc_open(), smbc_opendir(), smbc_read(), smbc_rename(), smbc_rmdir(), smbc_stat(), smbc_dirent::smbc_type, smbc_unlink(), smbc_write(), stat(), strcpy, and strerror. 00045 { 00046 int err, fd, dh1, dh2, dh3, dsize, dirc; 00047 const char *file = "smb://samba/public/testfile.txt"; 00048 const char *file2 = "smb://samba/public/testfile2.txt"; 00049 char buff[256]; 00050 char dirbuf[512]; 00051 char *dirp; 00052 struct stat st1, st2; 00053 00054 err = smbc_init(get_auth_data_fn, 10); /* Initialize things */ 00055 00056 if (err < 0) { 00057 00058 fprintf(stderr, "Initializing the smbclient library ...: %s\n", strerror(errno)); 00059 00060 } 00061 00062 if (argc > 1) { 00063 00064 if ((dh1 = smbc_opendir(argv[1]))<1) { 00065 00066 fprintf(stderr, "Could not open directory: %s: %s\n", 00067 argv[1], strerror(errno)); 00068 00069 exit(1); 00070 00071 } 00072 00073 fprintf(stdout, "Directory handles: %u, %u, %u\n", dh1, dh2, dh3); 00074 00075 /* Now, list those directories, but in funny ways ... */ 00076 00077 dirp = (char *)dirbuf; 00078 00079 if ((dirc = smbc_getdents(dh1, (struct smbc_dirent *)dirp, 00080 sizeof(dirbuf))) < 0) { 00081 00082 fprintf(stderr, "Problems getting directory entries: %s\n", 00083 strerror(errno)); 00084 00085 exit(1); 00086 00087 } 00088 00089 /* Now, process the list of names ... */ 00090 00091 fprintf(stdout, "Directory listing, size = %u\n", dirc); 00092 00093 while (dirc > 0) { 00094 00095 dsize = ((struct smbc_dirent *)dirp)->dirlen; 00096 fprintf(stdout, "Dir Ent, Type: %u, Name: %s, Comment: %s\n", 00097 ((struct smbc_dirent *)dirp)->smbc_type, 00098 ((struct smbc_dirent *)dirp)->name, 00099 ((struct smbc_dirent *)dirp)->comment); 00100 00101 dirp += dsize; 00102 dirc -= dsize; 00103 00104 } 00105 00106 dirp = (char *)dirbuf; 00107 00108 exit(1); 00109 00110 } 00111 00112 /* For now, open a file on a server that is hard coded ... later will 00113 * read from the command line ... 00114 */ 00115 00116 fd = smbc_open(file, O_RDWR | O_CREAT | O_TRUNC, 0666); 00117 00118 if (fd < 0) { 00119 00120 fprintf(stderr, "Creating file: %s: %s\n", file, strerror(errno)); 00121 exit(0); 00122 00123 } 00124 00125 fprintf(stdout, "Opened or created file: %s\n", file); 00126 00127 /* Now, write some date to the file ... */ 00128 00129 bzero(buff, sizeof(buff)); 00130 strcpy(buff, "Some test data for the moment ..."); 00131 00132 err = smbc_write(fd, buff, sizeof(buff)); 00133 00134 if (err < 0) { 00135 00136 fprintf(stderr, "writing file: %s: %s\n", file, strerror(errno)); 00137 exit(0); 00138 00139 } 00140 00141 fprintf(stdout, "Wrote %d bytes to file: %s\n", sizeof(buff), buff); 00142 00143 /* Now, seek the file back to offset 0 */ 00144 00145 err = smbc_lseek(fd, SEEK_SET, 0); 00146 00147 if (err < 0) { 00148 00149 fprintf(stderr, "Seeking file: %s: %s\n", file, strerror(errno)); 00150 exit(0); 00151 00152 } 00153 00154 fprintf(stdout, "Completed lseek on file: %s\n", file); 00155 00156 /* Now, read the file contents back ... */ 00157 00158 err = smbc_read(fd, buff, sizeof(buff)); 00159 00160 if (err < 0) { 00161 00162 fprintf(stderr, "Reading file: %s: %s\n", file, strerror(errno)); 00163 exit(0); 00164 00165 } 00166 00167 fprintf(stdout, "Read file: %s\n", buff); /* Should check the contents */ 00168 00169 fprintf(stdout, "Now fstat'ing file: %s\n", file); 00170 00171 err = smbc_fstat(fd, &st1); 00172 00173 if (err < 0) { 00174 00175 fprintf(stderr, "Fstat'ing file: %s: %s\n", file, strerror(errno)); 00176 exit(0); 00177 00178 } 00179 00180 00181 /* Now, close the file ... */ 00182 00183 err = smbc_close(fd); 00184 00185 if (err < 0) { 00186 00187 fprintf(stderr, "Closing file: %s: %s\n", file, strerror(errno)); 00188 00189 } 00190 00191 /* Now, rename the file ... */ 00192 00193 err = smbc_rename(file, file2); 00194 00195 if (err < 0) { 00196 00197 fprintf(stderr, "Renaming file: %s to %s: %s\n", file, file2, strerror(errno)); 00198 00199 } 00200 00201 fprintf(stdout, "Renamed file %s to %s\n", file, file2); 00202 00203 /* Now, create a file and delete it ... */ 00204 00205 fprintf(stdout, "Now, creating file: %s so we can delete it.\n", file); 00206 00207 fd = smbc_open(file, O_RDWR | O_CREAT, 0666); 00208 00209 if (fd < 0) { 00210 00211 fprintf(stderr, "Creating file: %s: %s\n", file, strerror(errno)); 00212 exit(0); 00213 00214 } 00215 00216 fprintf(stdout, "Opened or created file: %s\n", file); 00217 00218 err = smbc_close(fd); 00219 00220 if (err < 0) { 00221 00222 fprintf(stderr, "Closing file: %s: %s\n", file, strerror(errno)); 00223 exit(0); 00224 00225 } 00226 00227 /* Now, delete the file ... */ 00228 00229 fprintf(stdout, "File %s created, now deleting ...\n", file); 00230 00231 err = smbc_unlink(file); 00232 00233 if (err < 0) { 00234 00235 fprintf(stderr, "Deleting file: %s: %s\n", file, strerror(errno)); 00236 exit(0); 00237 00238 } 00239 00240 /* Now, stat the file, file 2 ... */ 00241 00242 fprintf(stdout, "Now stat'ing file: %s\n", file); 00243 00244 err = smbc_stat(file2, &st2); 00245 00246 if (err < 0) { 00247 00248 fprintf(stderr, "Stat'ing file: %s: %s\n", file, strerror(errno)); 00249 exit(0); 00250 00251 } 00252 00253 fprintf(stdout, "Stat'ed file: %s. Size = %d, mode = %04X\n", file2, 00254 (int)st2.st_size, st2.st_mode); 00255 fprintf(stdout, " time: %s\n", ctime(&st2.st_atime)); 00256 fprintf(stdout, "Earlier stat: %s, Size = %d, mode = %04X\n", file, 00257 (int)st1.st_size, st1.st_mode); 00258 fprintf(stdout, " time: %s\n", ctime(&st1.st_atime)); 00259 00260 /* Now, make a directory ... */ 00261 00262 fprintf(stdout, "Making directory smb://samba/public/make-dir\n"); 00263 00264 if (smbc_mkdir("smb://samba/public/make-dir", 0666) < 0) { 00265 00266 fprintf(stderr, "Error making directory: smb://samba/public/make-dir: %s\n", 00267 strerror(errno)); 00268 00269 if (errno == EEXIST) { /* Try to delete the directory */ 00270 00271 fprintf(stdout, "Trying to delete directory: smb://samba/public/make-dir\n"); 00272 00273 if (smbc_rmdir("smb://samba/public/make-dir") < 0) { /* Error */ 00274 00275 fprintf(stderr, "Error removing directory: smb://samba/public/make-dir: %s\n", strerror(errno)); 00276 00277 exit(0); 00278 00279 } 00280 00281 fprintf(stdout, "Making directory: smb://samba/public/make-dir\n"); 00282 00283 if (smbc_mkdir("smb://samba/public/make-dir", 666) < 0) { 00284 00285 fprintf(stderr, "Error making directory: smb://samba/public/make-dir: %s\n", 00286 strerror(errno)); 00287 00288 fprintf(stderr, "I give up!\n"); 00289 00290 exit(1); 00291 00292 } 00293 00294 } 00295 00296 exit(0); 00297 00298 } 00299 00300 fprintf(stdout, "Made dir: make-dir\n"); 00301 return 0; 00302 }
|
|
|
Definition at line 34 of file testsmbc.c. References fprintf(), global_id, print_job_info::id, print_job_info::name, print_job_info::priority, print_job_info::size, and print_job_info::user. Referenced by main(). 00035 { 00036 00037 fprintf(stdout, "Print job: ID: %u, Prio: %u, Size: %u, User: %s, Name: %s\n", 00038 pji->id, pji->priority, pji->size, pji->user, pji->name); 00039 00040 global_id = pji->id; 00041 00042 }
|
|
|
Definition at line 32 of file testsmbc.c. Referenced by print_list_fn(). |