wmclockmon: remove obsolete `GTK_CALENDAR_WEEK_START_MONDAY`
[dockapps.git] / wmget / cancel.c
blob3c776620a6340c5dc455fbd2404f3c4a999a2ae8
1 /*
2 wmget - A background download manager as a Window Maker dock app
3 Copyright (c) 2001-2003 Aaron Trickey <aaron@amtrickey.net>
5 Permission is hereby granted, free of charge, to any person
6 obtaining a copy of this software and associated documentation files
7 (the "Software"), to deal in the Software without restriction,
8 including without limitation the rights to use, copy, modify, merge,
9 publish, distribute, sublicense, and/or sell copies of the Software,
10 and to permit persons to whom the Software is furnished to do so,
11 subject to the following conditions:
13 The above copyright notice and this permission notice shall be
14 included in all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
20 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 ********************************************************************
25 cancel.c - Client code for canceling download requests
27 When invoked with the ``cancel'' argument, main() calls cancel(),
28 defined below. This code expects a job ID and forms and submits
29 a CANCEL request to the server.
32 #include <stdio.h>
33 #include <string.h>
34 #include <stdlib.h>
36 #include "wmget.h"
38 int cancel (int argc, char **argv)
40 char line[MAXCMDLEN + 1];
41 char *word_break;
42 FILE *fp;
43 job_id_t job_id;
45 /* The argument vector we receive is guaranteed to start with
46 * { <program-name>, cancel }. Currently, we don't support any
47 * options or anything; we just expect a single nonzero job ID.
49 if (argc < 3) {
50 error ("What do you want me to cancel? (Missing job number)");
51 return 1;
52 } else if (argc > 3) {
53 error ("Extra arguments: cancel takes only a job number");
54 return 1;
55 } else if (!(job_id = strtoul (argv[2], &word_break, 0))
56 || *word_break) {
57 error ("Invalid job number (must be an integer > 0)");
58 return 1;
61 if (!(fp = iq_client_connect ()))
62 return 1;
64 if (fprintf (fp, "CANCEL JOBID(%lu)\r\n", job_id) == EOF) {
65 error_sys ("Could not submit command to server");
66 fclose (fp);
67 return 1;
70 if (!fgets (line, sizeof line - 1, fp)) {
71 error ("Server did not respond to command!");
72 fclose (fp);
73 return 1;
76 /* Extract the first word and compare. */
77 word_break = line + strcspn (line, " \t\r\n");
79 if (*word_break)
80 *word_break++ = 0;
82 if (strcasecmp (line, RESPONSE_JOB_CANCELED)) {
83 error ("Server responded with error: %s", word_break);
84 fclose (fp);
85 return 1;
88 fclose (fp);
90 return 0;