wmomikuzi: Use shared libdockapp.
[dockapps.git] / wmget / wmget.h
blobd71d18c6de2d015e9a806b11b8398d20faf2ccde
1 #ifndef I_WMGET_H
2 #define I_WMGET_H
3 /*
4 wmget - A background download manager as a Window Maker dock app
5 Copyright (c) 2001-2003 Aaron Trickey <aaron@amtrickey.net>
7 Permission is hereby granted, free of charge, to any person
8 obtaining a copy of this software and associated documentation files
9 (the "Software"), to deal in the Software without restriction,
10 including without limitation the rights to use, copy, modify, merge,
11 publish, distribute, sublicense, and/or sell copies of the Software,
12 and to permit persons to whom the Software is furnished to do so,
13 subject to the following conditions:
15 The above copyright notice and this permission notice shall be
16 included in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 ********************************************************************
27 wmget.h - Common definitions for all wmget modules
29 This file defines the public entry points in each *.c file in the
30 main wmget program, as well as some common constants, global
31 variables, and the structure of the shared memory segment.
35 #include <sys/param.h>
36 #include <curl/curl.h>
38 #define WMGET_VERSION PACKAGE_VERSION
39 #define WMGET_VERSION_BANNER "wmget " WMGET_VERSION \
40 ", compiled with libcurl " \
41 LIBCURL_VERSION
42 #define WMGET_COPYRIGHT "Copyright (c) 2001-2003 " \
43 "Aaron Trickey <aaron@amtrickey.net>" \
44 "; ABSOLUTELY NO WARRANTY"
47 #define DEFAULT_USER_AGENT \
48 "wmget/" WMGET_VERSION " (libcurl/" LIBCURL_VERSION ")"
50 #define MAXRCLINELEN 1024
51 #define MAXURL 1024
52 #define MAXUA 255
53 #define MAXAUTH 100
54 #define MAXIF 255
55 #define MAXCMDLEN 2048
56 #define MAXCMDARGS 20
57 #define MAX_DISPLAY 9
59 #define MAX_ACTIVE_JOBS 4 /* a number constrained by the UI */
60 #define MAX_QUEUED_JOBS 20
62 /* Command language */
64 /* The GET command and its arguments: */
65 #define CMD_GET "GET"
66 #define ARG_GET_SOURCE_URL "FROM"
67 #define ARG_GET_DISPLAY "DISP"
68 #define ARG_GET_SAVE_TO "TO"
69 #define ARG_GET_OVERWRITE "OVER"
70 #define ARG_GET_CONTINUE_FROM "CONT"
71 #define ARG_GET_PROXY "PROXY"
72 #define ARG_GET_FOLLOW "FOLLOW"
73 #define ARG_GET_UA "UA"
74 #define ARG_GET_USE_ASCII "ASCII"
75 #define ARG_GET_REFERER "REF"
76 #define ARG_GET_INCLUDE "INCL"
77 #define ARG_GET_INTERFACE "IF"
78 #define ARG_GET_PROXY_AUTH "PROXY-AUTH"
79 #define ARG_GET_AUTH "AUTH"
81 #define CMD_CANCEL "CANCEL"
82 #define ARG_CANCEL_JOBID "JOBID"
84 #define CMD_LIST "LIST"
86 #define RESPONSE_JOB_ACCEPTED "ACCEPTED"
87 #define RESPONSE_JOB_CANCELED "CANCELED"
88 #define RESPONSE_LIST_COMING "JOBLIST"
89 #define RESPONSE_ERROR "ERROR"
92 /* Debug trace text output levels */
93 typedef enum {
94 OL_SILENT,
95 OL_NORMAL,
96 OL_DEBUG,
97 } OutputLevel;
100 /* The various states an individual job may be in.
102 typedef enum {
103 J_EMPTY, /* this job slot is empty */
104 J_INIT, /* slot has been taken, job not yet started */
105 J_RUNNING, /* this job is running */
106 J_PAUSED, /* this job is paused */
107 J_STOPPING, /* a stop request has come from the user */
108 J_COMPLETE, /* job complete, cleaning up */
109 J_FAILED, /* job failed! */
110 } JobStatus;
113 /* The type of a job ID; these are allocated by the dockapp and are
114 * never reused within its lifetime.
116 typedef unsigned long job_id_t;
119 /* User-configurable job options.
121 typedef struct {
122 char display[MAX_DISPLAY + 1]; /* Text to display */
123 char save_to[MAXPATHLEN + 1]; /* Full pathname to save to */
124 /* (For srvr, this MUST be a dir) */
125 int overwrite; /* Allow overwrite of save_to? */
126 int continue_from; /* Byte# to resume from */
127 char proxy[MAXURL + 1]; /* Proxy to use (or empty string) */
128 int follow; /* How many redirects to follow */
129 char user_agent[MAXUA + 1]; /* User-agent string to provide */
131 int use_ascii; /* Force FTP to ASCII */
132 char referer[MAXURL + 1]; /* Specify referer */
133 int include; /* Include HTTP headers in output */
134 char interface[MAXIF + 1]; /* Limit to given interface */
135 char proxy_auth[MAXAUTH + 1]; /* Proxy authentication */
136 char auth[MAXAUTH + 1]; /* Site authentication */
138 } JobOptions;
141 /* A command-line download request. Strings are NULL if defaulted;
142 * integers are -1.
144 typedef struct {
145 const char *source_url; /* MANDATORY. Duh. */
146 const char *display;
147 const char *save_to;
148 int overwrite;
149 int continue_from;
150 const char *proxy;
151 int follow;
152 const char *user_agent;
154 int use_ascii;
155 const char *referer;
156 int include;
157 const char *interface;
158 const char *proxy_auth;
159 const char *auth;
161 } Request;
164 /* The totality of a running or queued job:
166 typedef struct {
167 job_id_t job_id;
168 JobStatus status;
169 char error[CURL_ERROR_SIZE + 1];
170 unsigned long progress;
171 unsigned long prog_max;
172 int stop_request;
173 char source_url[MAXURL + 1]; /* URL to fetch */
175 JobOptions options;
176 } Job;
179 /* The shared-memory structure containing the active job list. (Pending
180 * jobs are queued in the dockapp's private data segment.)
182 typedef struct {
183 Job jobs[MAX_ACTIVE_JOBS];
184 } Shmem;
187 /* Specifies the server configuration. This is used only by server.c,
188 * and gets populated by config_server() in config.c.
190 typedef struct {
191 JobOptions job_defaults;
192 } ServerConfig;
195 /* Convenience macro
197 #define STRCPY_TO_ARRAY(to,from) \
198 do { \
199 strncpy (to, from, sizeof to); \
200 to[sizeof to - 1] = '\0'; \
201 } while (0)
204 /* configure.c */
205 extern void config_server (int argc, char **argv, ServerConfig *cfg);
206 extern void clear_request (Request *req);
207 extern void config_request (int argc, char **argv, Request *req);
209 /* usage.c */
210 extern void usage (void);
212 /* iq.c */
213 extern int iq_server_init (void); /* called once, by server */
214 extern FILE *iq_server_accept (void); /* returns new cxn or NULL */
215 extern FILE *iq_client_connect (void); /* called by each client */
216 extern int iq_get_listen_fd (void); /* so you can select/poll */
218 /* server.c */
219 extern Shmem *shmem;
220 extern int server (int argc, char **argv);
222 /* request.c */
223 extern int request (int argc, char **argv);
225 /* cancel.c */
226 extern int cancel (int argc, char **argv);
228 /* list.c */
229 extern int list (int argc, char **argv);
231 /* retrieve.c */
232 extern int retrieve (Job *job);
234 /* wmget.c */
235 extern const char *home_directory (void);
236 extern void debug_dump_job (Job *job);
238 /* messages.c */
239 extern void set_output_level (OutputLevel lev);
240 extern OutputLevel output_level (void);
241 extern void error (const char *fmt, ...);
242 extern void error_sys (const char *fmt, ...);
243 extern void info (const char *fmt, ...);
244 extern void debug (const char *fmt, ...);
245 extern void debug_sys (const char *fmt, ...);
248 #endif /* I_WMGET_H */