import HEAD into svn+ssh://svn.samba.org/home/svn/samba/trunk
[metze/old/v3-2-winbind-ndr.git] / testsuite / libsmbclient / src / list_print_jobs / list_print_jobs_6.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <errno.h>
5 #include <libsmbclient.h>
6
7 #define MAX_BUFF_SIZE   255
8 char g_workgroup[MAX_BUFF_SIZE];
9 char g_username[MAX_BUFF_SIZE];
10 char g_password[MAX_BUFF_SIZE];
11 char g_server[MAX_BUFF_SIZE];
12 char g_share[MAX_BUFF_SIZE];
13
14 char g_print_user[MAX_BUFF_SIZE];
15 char g_print_name[MAX_BUFF_SIZE];
16 unsigned int g_print_id;
17 unsigned int g_print_priority;
18 unsigned int g_print_size;
19
20 int print_fn_call_flag;
21
22 void auth_fn(const char *server, const char *share, char *workgroup, int wgmaxlen, 
23                 char *username, int unmaxlen, char *password, int pwmaxlen)
24 {
25
26         strncpy(workgroup, g_workgroup, wgmaxlen - 1);
27
28         strncpy(username, g_username, unmaxlen - 1);
29
30         strncpy(password, g_password, pwmaxlen - 1);
31
32         strcpy(g_server, server);
33         strcpy(g_share, share);
34
35 }
36
37 void print_list_fn(struct print_job_info *pji)
38 {
39
40         g_print_id = pji->id;
41         g_print_priority = pji->priority;
42         g_print_size = pji->size;
43         strcpy(g_print_user,pji->user);
44         strcpy(g_print_name,pji->name);
45
46         /* fprintf(stdout, "Print job: ID: %u, Prio: %u, Size: %u, User: %s, Name: %s\n",
47                                   pji->id, pji->priority, pji->size, pji->user, pji->name); */
48
49
50         print_fn_call_flag = 1;
51         
52 }
53
54 int main(int argc, char** argv)
55 {
56
57         int err = -1;
58         int fd = 0;
59         int msg_len = 0;
60         char * message;
61         char url[MAX_BUFF_SIZE];
62
63         bzero(g_workgroup,MAX_BUFF_SIZE);
64         bzero(url,MAX_BUFF_SIZE);
65         bzero(g_print_user,MAX_BUFF_SIZE);
66         bzero(g_print_name,MAX_BUFF_SIZE);
67
68         g_print_id = 0;
69         g_print_priority = 0;
70         g_print_size = 0;
71
72         print_fn_call_flag = 0;
73
74         if ( argc == 5 )
75         {
76                 
77                 strncpy(g_workgroup,argv[1],strlen(argv[1]));
78                 strncpy(g_username,argv[2],strlen(argv[2]));
79                 strncpy(g_password,argv[3],strlen(argv[3]));
80                 strncpy(url,argv[4],strlen(argv[4]));
81
82                 msg_len = strlen(argv[5])+1;
83                 message = malloc(msg_len);
84                 message[msg_len - 1] = 0;       
85                 strncpy(message,argv[5],msg_len);
86                 /* printf("Message: %s\n",message); */
87                 /* printf("Message len: %i\n",msg_len); */
88
89                 smbc_init(auth_fn, 0);
90                 smbc_unlink(url);
91                 fd = smbc_open(url,O_RDWR | O_CREAT, 0666);
92                 smbc_write(fd, message, msg_len);
93                 smbc_close(fd);
94
95                 free(message);
96                 smbc_print_file(url,argv[6]);
97                 smbc_list_print_jobs(url,print_list_fn);
98
99                 if ( print_fn_call_flag == 0 )
100                         err = 1;
101
102                 else
103                         err = 0;
104
105         }
106
107         return err;
108
109 }
110