Fix calls to smbc_init in testsmbc.c and tree.c
authorRichard Sharpe <sharpe@samba.org>
Mon, 12 Feb 2001 12:31:05 +0000 (12:31 +0000)
committerRichard Sharpe <sharpe@samba.org>
Mon, 12 Feb 2001 12:31:05 +0000 (12:31 +0000)
(This used to be commit 244edad065a48c110d73617e6c76bdae0ab6885d)

source3/client/testsmbc.c
source3/client/tree.c

index 49d969217623ae96813c0b6a473bfd39ea3a88cf..d2dce7ccab678f66be2d5df6914aca56f2478fd2 100644 (file)
 
 #include <stdio.h>
 #include <errno.h>
+#include <sys/time.h>
 #include <libsmbclient.h>
 
-void auth_fn(char *server, char *share,
+void auth_fn(const char *server, const char *share,
             char *workgroup, int wgmaxlen, char *username, int unmaxlen,
             char *password, int pwmaxlen)
 {
@@ -59,18 +60,29 @@ void auth_fn(char *server, char *share,
 
 }
 
+int global_id = 0;
+
+void print_list_fn(struct print_job_info *pji)
+{
+
+  fprintf(stdout, "Print job: ID: %u, Prio: %u, Size: %u, User: %s, Name: %s\n",
+         pji->id, pji->priority, pji->size, pji->user, pji->name);
+
+  global_id = pji->id;
+
+}
+
 int main(int argc, char *argv[])
 {
   int err, fd, dh1, dh2, dh3, dsize, dirc;
   const char *file = "smb://samba/public/testfile.txt";
   const char *file2 = "smb://samba/public/testfile2.txt";
-  const char *workgroup = "sambanet";
   char buff[256];
   char dirbuf[512];
   struct smbc_dirent *dirp;
   struct stat st1, st2;
 
-  err = smbc_init(auth_fn, workgroup,  10); /* Initialize things */
+  err = smbc_init(auth_fn,  10); /* Initialize things */
 
   if (err < 0) {
 
@@ -80,6 +92,52 @@ int main(int argc, char *argv[])
 
   if (argc > 1) {
 
+    /* Try to list the print jobs ... */
+
+    if (smbc_list_print_jobs("smb://samba/pclp", print_list_fn) < 0) {
+
+      fprintf(stderr, "Could not list print jobs: %s, %d\n", strerror(errno), errno);
+      exit(1);
+
+    }
+
+    /* Try to delete the last job listed */
+
+    if (global_id > 0) {
+
+      fprintf(stdout, "Trying to delete print job %u\n", global_id);
+
+      if (smbc_unlink_print_job("smb://samba/pclp", global_id) < 0) {
+
+       fprintf(stderr, "Failed to unlink job id %u, %s, %u\n", global_id, 
+               strerror(errno), errno);
+
+       exit(1);
+
+      }
+
+    }
+
+    /* Try to print a file ... */
+
+    if (smbc_print_file("smb://samba/public/testfile2.txt", "smb://samba/pclp") < 0) {
+
+      fprintf(stderr, "Failed to print job: %s %u\n", strerror(errno), errno);
+      exit(1);
+
+    }
+
+    /* Try to delete argv[1] as a file ... */
+    
+    if (smbc_unlink(argv[1]) < 0) {
+
+      fprintf(stderr, "Could not unlink: %s, %s, %d\n",
+             argv[1], strerror(errno), errno);
+
+      exit(0);
+
+    }
+
     if ((dh1 = smbc_opendir("smb://"))<1) {
 
       fprintf(stderr, "Could not open directory: smb://: %s\n",
@@ -341,4 +399,45 @@ int main(int argc, char *argv[])
          st1.st_size, st1.st_mode);
   fprintf(stdout, "    time: %s\n", ctime(&st1.st_atime));
 
+  /* Now, make a directory ... */
+
+  fprintf(stdout, "Making directory smb://samba/public/make-dir\n");
+
+  if (smbc_mkdir("smb://samba/public/make-dir", 0666) < 0) {
+
+    fprintf(stderr, "Error making directory: smb://samba/public/make-dir: %s\n", 
+           strerror(errno));
+
+    if (errno == EEXIST) { /* Try to delete the directory */
+
+      fprintf(stdout, "Trying to delete directory: smb://samba/public/make-dir\n");
+
+      if (smbc_rmdir("smb://samba/public/make-dir") < 0) { /* Error */
+
+       fprintf(stderr, "Error removing directory: smb://samba/public/make-dir: %s\n", strerror(errno));
+
+       exit(0);
+
+      }
+
+      fprintf(stdout, "Making directory: smb://samba/public/make-dir\n");
+
+      if (smbc_mkdir("smb://samba/public/make-dir", 666) < 0) {
+
+       fprintf(stderr, "Error making directory: smb://samba/public/make-dir: %s\n",
+               strerror(errno));
+
+       fprintf(stderr, "I give up!\n");
+
+       exit(1);
+
+      }
+
+    }
+
+    exit(0);
+    
+  }
+
+  fprintf(stdout, "Made dir: make-dir\n");
 }
index eb95511934a64108227cb4cb47b852ad2fcd75c6..941a09667740fc58e8f565166d71cef862dba048 100644 (file)
@@ -518,7 +518,7 @@ static void cb_wholenet(GtkWidget *item, gchar *signame)
 /* Should put up a dialog box to ask the user for username and password */
 
 static void 
-auth_fn(char *server, char *share,
+auth_fn(const char *server, const char *share,
        char *workgroup, int wgmaxlen, char *username, int unmaxlen,
        char *password, int pwmaxlen)
 {
@@ -546,7 +546,7 @@ int main( int   argc,
 
   /* Init the smbclient library */
 
-  err = smbc_init(auth_fn, "", 10);
+  err = smbc_init(auth_fn, 10);
 
   /* a generic toplevel window */
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);