summaryrefslogtreecommitdiff
path: root/source3/rpcclient/display_at.c
blob: 29daf9f3336ed249b43d0c5f7dd27d0897bb75a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/* 
   Unix SMB/Netbios implementation.
   Version 1.9.
   Samba utility functions
   Copyright (C) Andrew Tridgell 1992-1999
   Copyright (C) Luke Kenneth Casson Leighton 1996 - 1999
   
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful, 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include "includes.h"

static char *get_at_time_str(uint32 t)
{
	static fstring timestr;
	unsigned int hours, minutes, seconds;

	hours = t / 1000;
	seconds = hours % 60;
	hours /= 60;
	minutes = hours % 60;
	hours /= 60;

	slprintf(timestr, sizeof(timestr)-1, "%2d:%02d:%02d", 
		 hours, minutes, seconds);

	return timestr;
}

extern char *daynames_short[];

static char *get_at_days_str(uint32 monthdays, uint8 weekdays, uint8 flags)
{
	static fstring days;
	fstring numstr;
	int day, bit;
	BOOL first = True;

	if (monthdays == 0 && weekdays == 0)
		return "Once";

	if (flags & JOB_PERIODIC)
	{
		if (IS_BITS_SET_ALL(weekdays, 0x7F))
			return "Every Day";

		fstrcpy(days, "Every ");
	}
	else
	{
		fstrcpy(days, "Next ");
	}

	for (day = 1, bit = 1; day < 32; day++, bit <<= 1)
	{
		if (monthdays & bit)
		{
			if (first)
				first = False;
			else
				fstrcat(days, ", ");

			slprintf(numstr, sizeof(numstr)-1, "%d", day);
			fstrcat(days, numstr);
		}
	}

	for (day = 0, bit = 1; day < 7; day++, bit <<= 1)
	{
		if (weekdays & bit)
		{
			if (first)
				first = False;
			else
				fstrcat(days, ", ");

			fstrcat(days, daynames_short[day]);
		}
	}

	return days;
}

/****************************************************************************
 display scheduled jobs
 ****************************************************************************/
void display_at_enum_info(FILE *out_hnd, enum action_type action, 
				uint32 num_jobs, const AT_ENUM_INFO *const jobs,
				char *const *const commands)
{
	switch (action)
	{
		case ACTION_HEADER:
		{
			if (num_jobs == 0)
			{
				report(out_hnd, "\tNo Jobs.\n");
			}
			else
			{
				report(out_hnd, "\tJobs:\n");
				report(out_hnd, "\t-----\n");
			}
			break;
		}
		case ACTION_ENUMERATE:
		{
			int i;

			for (i = 0; i < num_jobs; i++)
			{
				const AT_JOB_INFO *const job = &jobs[i].info;

				report(out_hnd, "\t%d\t%s\t%s\t%s\n", 
					jobs[i].jobid, 
					get_at_time_str(job->time), 
					get_at_days_str(job->monthdays, 
							job->weekdays, 
							job->flags), 
					commands[i]);
			}

			break;
		}
		case ACTION_FOOTER:
		{
			report(out_hnd, "\n");
			break;
		}
	}
}

/****************************************************************************
 display information about a scheduled job
 ****************************************************************************/
void display_at_job_info(FILE *out_hnd, enum action_type action, 
		     AT_JOB_INFO *const job, fstring command)
{
	switch (action)
	{
		case ACTION_HEADER:
		{
			report(out_hnd, "\tJob Information:\n");
			report(out_hnd, "\t----------------\n");
			break;
		}
		case ACTION_ENUMERATE:
		{
			report(out_hnd, "\tTime:        %s\n", 
				get_at_time_str(job->time));

			report(out_hnd, "\tSchedule:    %s\n", 
				get_at_days_str(job->monthdays, job->weekdays, 
						job->flags));

			report(out_hnd, "\tStatus:      %s", 
				(job->flags & JOB_EXEC_ERR) ? "Failed" : "OK");

			if (job->flags & JOB_RUNS_TODAY)
			{
				report(out_hnd, ", Runs Today");
			}

			report(out_hnd, "\n\tInteractive: %s\n", 
				(job->flags & JOB_NONINTERACTIVE) ? "No"
				: "Yes");

			report(out_hnd, "\tCommand:     %s\n", command);
			break;
		}
		case ACTION_FOOTER:
		{
			report(out_hnd, "\n");
			break;
		}
	}
}