first pass at updating head branch to be to be the same as the SAMBA_2_0 branch
[kai/samba-autobuild/.git] / source / rpcclient / display_at.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 1.9.
4    Samba utility functions
5    Copyright (C) Andrew Tridgell 1992-1999
6    Copyright (C) Luke Kenneth Casson Leighton 1996 - 1999
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful, 
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24
25 static char *get_at_time_str(uint32 t)
26 {
27         static fstring timestr;
28         unsigned int hours, minutes, seconds;
29
30         hours = t / 1000;
31         seconds = hours % 60;
32         hours /= 60;
33         minutes = hours % 60;
34         hours /= 60;
35
36         slprintf(timestr, sizeof(timestr)-1, "%2d:%02d:%02d", 
37                  hours, minutes, seconds);
38
39         return timestr;
40 }
41
42 extern char *daynames_short[];
43
44 static char *get_at_days_str(uint32 monthdays, uint8 weekdays, uint8 flags)
45 {
46         static fstring days;
47         fstring numstr;
48         int day, bit;
49         BOOL first = True;
50
51         if (monthdays == 0 && weekdays == 0)
52                 return "Once";
53
54         if (flags & JOB_PERIODIC)
55         {
56                 if (IS_BITS_SET_ALL(weekdays, 0x7F))
57                         return "Every Day";
58
59                 fstrcpy(days, "Every ");
60         }
61         else
62         {
63                 fstrcpy(days, "Next ");
64         }
65
66         for (day = 1, bit = 1; day < 32; day++, bit <<= 1)
67         {
68                 if (monthdays & bit)
69                 {
70                         if (first)
71                                 first = False;
72                         else
73                                 fstrcat(days, ", ");
74
75                         slprintf(numstr, sizeof(numstr)-1, "%d", day);
76                         fstrcat(days, numstr);
77                 }
78         }
79
80         for (day = 0, bit = 1; day < 7; day++, bit <<= 1)
81         {
82                 if (weekdays & bit)
83                 {
84                         if (first)
85                                 first = False;
86                         else
87                                 fstrcat(days, ", ");
88
89                         fstrcat(days, daynames_short[day]);
90                 }
91         }
92
93         return days;
94 }
95
96 /****************************************************************************
97  display scheduled jobs
98  ****************************************************************************/
99 void display_at_enum_info(FILE *out_hnd, enum action_type action, 
100                                 uint32 num_jobs, const AT_ENUM_INFO *const jobs,
101                                 char *const *const commands)
102 {
103         switch (action)
104         {
105                 case ACTION_HEADER:
106                 {
107                         if (num_jobs == 0)
108                         {
109                                 report(out_hnd, "\tNo Jobs.\n");
110                         }
111                         else
112                         {
113                                 report(out_hnd, "\tJobs:\n");
114                                 report(out_hnd, "\t-----\n");
115                         }
116                         break;
117                 }
118                 case ACTION_ENUMERATE:
119                 {
120                         int i;
121
122                         for (i = 0; i < num_jobs; i++)
123                         {
124                                 const AT_JOB_INFO *const job = &jobs[i].info;
125
126                                 report(out_hnd, "\t%d\t%s\t%s\t%s\n", 
127                                         jobs[i].jobid, 
128                                         get_at_time_str(job->time), 
129                                         get_at_days_str(job->monthdays, 
130                                                         job->weekdays, 
131                                                         job->flags), 
132                                         commands[i]);
133                         }
134
135                         break;
136                 }
137                 case ACTION_FOOTER:
138                 {
139                         report(out_hnd, "\n");
140                         break;
141                 }
142         }
143 }
144
145 /****************************************************************************
146  display information about a scheduled job
147  ****************************************************************************/
148 void display_at_job_info(FILE *out_hnd, enum action_type action, 
149                      AT_JOB_INFO *const job, fstring command)
150 {
151         switch (action)
152         {
153                 case ACTION_HEADER:
154                 {
155                         report(out_hnd, "\tJob Information:\n");
156                         report(out_hnd, "\t----------------\n");
157                         break;
158                 }
159                 case ACTION_ENUMERATE:
160                 {
161                         report(out_hnd, "\tTime:        %s\n", 
162                                 get_at_time_str(job->time));
163
164                         report(out_hnd, "\tSchedule:    %s\n", 
165                                 get_at_days_str(job->monthdays, job->weekdays, 
166                                                 job->flags));
167
168                         report(out_hnd, "\tStatus:      %s", 
169                                 (job->flags & JOB_EXEC_ERR) ? "Failed" : "OK");
170
171                         if (job->flags & JOB_RUNS_TODAY)
172                         {
173                                 report(out_hnd, ", Runs Today");
174                         }
175
176                         report(out_hnd, "\n\tInteractive: %s\n", 
177                                 (job->flags & JOB_NONINTERACTIVE) ? "No"
178                                 : "Yes");
179
180                         report(out_hnd, "\tCommand:     %s\n", command);
181                         break;
182                 }
183                 case ACTION_FOOTER:
184                 {
185                         report(out_hnd, "\n");
186                         break;
187                 }
188         }
189 }
190