~zulcss/samba/server-dailies-3.4

« back to all changes in this revision

Viewing changes to testsuite/libsmbclient/src/list_print_jobs/list_print_jobs_3.c

  • Committer: Chuck Short
  • Date: 2010-09-28 20:38:39 UTC
  • Revision ID: zulcss@ubuntu.com-20100928203839-pgjulytsi9ue63x1
Initial version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
21
void auth_fn(const char *server, const char *share, char *workgroup, int wgmaxlen, 
 
22
                char *username, int unmaxlen, char *password, int pwmaxlen)
 
23
{
 
24
 
 
25
        strncpy(workgroup, g_workgroup, wgmaxlen - 1);
 
26
 
 
27
        strncpy(username, g_username, unmaxlen - 1);
 
28
 
 
29
        strncpy(password, g_password, pwmaxlen - 1);
 
30
 
 
31
        strcpy(g_server, server);
 
32
        strcpy(g_share, share);
 
33
 
 
34
}
 
35
 
 
36
void print_list_fn(struct print_job_info *pji)
 
37
{
 
38
 
 
39
        g_print_id = pji->id;
 
40
        g_print_priority = pji->priority;
 
41
        g_print_size = pji->size;
 
42
        strcpy(g_print_user,pji->user);
 
43
        strcpy(g_print_name,pji->name);
 
44
 
 
45
        /* fprintf(stdout, "Print job: ID: %u, Prio: %u, Size: %u, User: %s, Name: %s\n",
 
46
                          pji->id, pji->priority, pji->size, pji->user, pji->name); */
 
47
        
 
48
}
 
49
 
 
50
int main(int argc, char** argv)
 
51
{
 
52
        int err = -1;
 
53
        int fd = 0;
 
54
        int msg_len = 0;
 
55
        char url[MAX_BUFF_SIZE];
 
56
        char* message;
 
57
 
 
58
        bzero(g_workgroup,MAX_BUFF_SIZE);
 
59
        bzero(url,MAX_BUFF_SIZE);
 
60
        bzero(g_print_user,MAX_BUFF_SIZE);
 
61
        bzero(g_print_name,MAX_BUFF_SIZE);
 
62
 
 
63
        g_print_id = 0;
 
64
        g_print_priority = 0;
 
65
        g_print_size = 0;
 
66
 
 
67
        if ( argc == 7 )
 
68
        {
 
69
                
 
70
                strncpy(g_workgroup,argv[1],strlen(argv[1]));
 
71
                strncpy(g_username,argv[2],strlen(argv[2]));
 
72
                strncpy(g_password,argv[3],strlen(argv[3]));
 
73
                strncpy(url,argv[4],strlen(argv[4]));
 
74
 
 
75
                msg_len = strlen(argv[5])+1;
 
76
                message = malloc(msg_len);
 
77
                message[msg_len - 1] = 0;       
 
78
                strncpy(message,argv[5],msg_len);
 
79
                /* printf("Message: %s\n",message); */ 
 
80
                /* printf("Message len: %i\n",msg_len); */
 
81
 
 
82
                smbc_init(auth_fn, 0);
 
83
                smbc_unlink(url);
 
84
                fd = smbc_open(url,O_RDWR | O_CREAT, 0666);
 
85
                smbc_write(fd, message, msg_len);
 
86
                smbc_close(fd);
 
87
 
 
88
                free(message);
 
89
                smbc_print_file(url,argv[6]);
 
90
                err = smbc_list_print_jobs(argv[6],print_list_fn);
 
91
 
 
92
                if ( err < 0 )
 
93
                        err = 1;
 
94
 
 
95
                else
 
96
                        err = 0;
 
97
 
 
98
        }
 
99
 
 
100
        return err;
 
101
 
 
102
}
 
103