2
* Copyright (c) Karl Dahlke, 2008
3
* This file is part of the edbrowse project, released under GPL.
9
/* the symbol DOSLIKE is used to conditionally compile those constructs
10
* that are common to DOS and NT, but not typical of Unix. */
18
/* System V or system BSD? */
19
#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD)
23
/* seems like everybody needs these header files */
24
#include <sys/types.h>
51
/* WARNING: the following typedef is pseudo-standard in C.
52
* Some systems will define ushort in sys/types.h, others will not.
53
* Unfortunately there is no #define symbol to key on;
54
* no way to conditionally compile the following statement. */
56
typedef unsigned short ushort;
57
typedef unsigned long ulong;
59
/* sys/types.h defines unsigned char as unchar. I prefer uchar.
60
* It is consistent with ushort uint and ulong, and doesn't remind
61
* me of the uncola, a char that isn't really a char. */
62
typedef unsigned char uchar;
64
/* We use uchar for boolean fields. */
69
typedef ushort idNameCode;
71
#define stringEqual !strcmp
73
/* ctype macros, when you're passing a byte,
74
* and you don't want to worry about whether it's char or uchar.
75
* Call the regular routines when c is an int, from fgetc etc. */
76
#define isspaceByte(c) isspace((uchar)c)
77
#define isalphaByte(c) isalpha((uchar)c)
78
#define isalnumByte(c) isalnum((uchar)c)
79
#define islowerByte(c) islower((uchar)c)
80
#define isupperByte(c) isupper((uchar)c)
81
#define isdigitByte(c) isdigit((uchar)c)
82
#define ispunctByte(c) ispunct((uchar)c)
83
#define isprintByte(c) isprint((uchar)c)
85
/* http encoding, content type, content transfer encoding */
86
enum { ENC_PLAIN, ENC_COMPRESS, ENC_GZIP, ENC_URL, ENC_MFD };
87
enum { CT_OTHER, CT_TEXT, CT_HTML, CT_RICH, CT_APPLIC, CT_MULTI, CT_ALT };
88
enum { CE_7BIT, CE_8BIT, CE_QP, CE_64 };
90
/* This program was originally written in perl.
91
* So I got use to perl strings, which admit nulls.
92
* In our case, they will be terminated by newline. */
93
typedef uchar *pst; /* perl string */
95
/* A specific nonascii char denotes an html tag
96
* in the rendered html text.
97
* See the comments in bufsub.c for the rationale. */
98
#define InternalCodeChar '\2'
99
#define InternalCodeCharAlternate '\1'
101
/* How long can a regular expression be? */
103
/* How long can an entered line be? */
104
#define MAXTTYLINE 256
105
/* Longest line that can take the substitute command */
106
#define REPLACELINELEN 50000
107
/* How many pages can we fetch, through frames etc. */
109
/* The longest string, in certain contexts. */
110
#define MAXSTRLEN 1024
111
/* How about user login and password? */
112
#define MAXUSERPASS 40
113
/* Number of pop3 mail accounts */
114
#define MAXACCOUNT 100
115
/* Number of mime types */
117
/* number of db tables */
120
/* How many sessions open concurrently */
121
#define MAXSESSION 1000
122
/* Allocation increment for a growing string, that we don't expect
123
* to get too large. This must be a power of 2. */
124
#define ALLOC_GR 0x100
133
/* left and top borders for dialog box, stubs. */
136
#define COLOR_DIALOG_TEXT 0
137
#define G_BFU_FONT_SIZE 0
139
/* .trash is small or capital t, on different systems */
141
#define TRASHDIR ".Trash"
144
/* the version of edbrowse */
145
extern const char *version;
146
extern const char eol[]; /* internet end of line */
147
extern char EMPTYSTRING[]; /* use this whenever you would use "" */
149
/* Here are the strings you can send out to identify this browser.
150
* Most of the time we will send out the first string, edbrowse-2.15.3.
151
* But sometimes we have to lie.
152
* When you deal with clickbank, for instance, they won't let you in the
153
* door unless you are one of three approved browsers.
154
* I've written to them about this particular flavor of stupidity,
155
* but they obviously don't care. So lie!
156
* Tell them you're Explorer, and walk right in.
157
* Anyways, this array holds up to 10 user agent strings. */
158
extern char *userAgents[10], *currentAgent;
160
struct MACCOUNT { /* pop3 account */
161
char *login, *password, *from, *reply;
162
char *inurl, *outurl;
169
char *suffix, *prot, *program;
174
char *name, *shortname;
175
char *cols[MAXTCOLS];
181
/* various globals */
182
extern int debugLevel; /* 0 to 9 */
183
extern int webTimeout, mailTimeout;
184
extern int browseLine; /* line number, for error reporting */
185
extern bool ismc; /* Is the program running as a mail client? */
186
extern bool cons_utf8; /* does the console expect utf8? */
187
extern bool iuConvert; /* perform iso utf8 conversions automatically */
188
extern bool zapMail; /* just get rid of the mail */
189
extern bool js_redirects; /* window.location = new_url */
190
extern uchar browseLocal; /* browsing a local file */
191
extern bool parsePage; /* parsing the html page, and any java therein */
192
extern bool htmlAttrVal_nl; /* allow nl in the attribute of an html tag */
193
extern bool unformatMail; /* suppress formatting */
194
extern bool passMail; /* pass mail across the filters */
195
extern bool errorExit; /* exit on any error, for scripting purposes */
196
extern bool isInteractive;
197
extern volatile bool intFlag; /* set this when interrupt signal is caught */
198
extern bool binaryDetect;
199
extern bool listNA; /* list nonascii chars */
200
extern bool inInput; /* reading line from standard in */
201
extern int fileSize; /* when reading/writing files */
202
extern int maxFileSize; /* max size of an editable file */
203
extern int mssock; /* mail server socket */
204
extern int hcode; /* http code, like 404 file not found */
205
extern char herror[]; /* html error */
206
extern char errorMsg[]; /* generated error message */
207
extern char serverLine[MAXTTYLINE]; /* lines to and from the mail server */
208
extern void *jcx; /* javascript context */
209
extern void *jwin; /* javascript window object */
210
extern void *jdoc; /* javascript document object */
211
extern void *jwloc; /* javascript window.location */
212
extern void *jdloc; /* javascript document.location */
213
extern int maxAccount; /* how many email accounts specified */
214
extern int localAccount; /* this is the smtp server for outgoing mail */
215
extern char *mailDir; /* move to this directory when fetching mail */
216
extern struct MACCOUNT accounts[]; /* all the email accounts */
217
extern int maxMime; /* how many mime types specified */
218
extern struct MIMETYPE mimetypes[];
219
extern char *dbarea, *dblogin, *dbpw; /* to log into the database */
220
extern char *proxy_host;
221
extern int proxy_port;
222
extern bool caseInsensitive, searchStringsAll;
223
extern bool textAreaDosNewlines; /* when transmitting a textarea */
224
extern bool undoable; /* an undoable operation is taking place */
225
extern bool allowRedirection; /* from http code 301, or http refresh */
226
extern bool sendReferrer; /* in the http header */
227
extern bool allowJS; /* javascript on */
228
extern bool helpMessagesOn; /* no need to type h */
230
extern bool showHiddenFiles; /* during directory scan */
231
extern uchar dirWrite; /* directory write mode, e.g. rename files */
232
extern uchar endMarks; /* do we print ^ $ at the start and end of lines? */
233
extern int context; /* which session (buffer) are we in? */
234
extern uchar linePending[];
235
extern char *changeFileName;
236
extern char *addressFile; /* your address book */
237
extern char *ipbFile; /* file holding ip blacklist */
238
extern char *serverData;
239
extern int serverDataLen;
240
extern char replaceLine[];
241
extern char *currentReferrer;
242
extern char *home; /* home directory */
243
extern char *recycleBin; /* holds deleted files */
244
extern char *configFile, *sigFile;
245
extern char *cookieFile; /* persistent cookies */
246
extern char *spamCan; /* dump spam emails */
247
extern char *edbrowseTempFile;
248
extern char *edbrowseTempPDF;
249
extern char *edbrowseTempHTML;
251
/* Ok, this is kinda simple and stupid.
252
* Every line in every window in every session is a string, without the
253
* newline, and all these strings are managed by an array of pointers.
254
* So your particular buffer may have 3 lines in it,
255
* and these are represented internally by three numbers, 12 29 and 83.
256
* So the text is textLines[12], textLines[29], textLines[83].
257
* Now, if you copy a line of text, I actually copy the string.
258
* This is a waste I suppose, but then I don't have to worry about
259
* what happens if you edit one line and not the other.
260
* They're already separate strings, so we're ok. */
261
extern pst *textLines;
262
extern int textLinesMax, textLinesCount; /* size of textLines array */
264
/* If a file has 30 lines, it is represented by 30 numbers,
265
* indexes into textLines[] above.
266
* Should we use an array of numbers, or a string of numbers
267
* represented by decimal digits?
268
* Both are painful, in different ways.
269
* Consider inserting a block of text, a very common operation.
270
* In a list, we would have to slide all the following numbers down.
271
* Granted, that's better than moving all those lines of text,
272
* but it's still a pain to program, and somewhat inefficient.
273
* If we use strings, we take the original string of numbers,
274
* break it at the insert point, and make a new string
275
* by concatenating these two pieces with the new block.
276
* The same issues arise when deleting text near the top of a file.
277
* This and other considerations push me towards strings.
278
* I currently use 6 characters for a line number,
279
* a seventh for the g// flag.
281
* and 9 and 10 hold the directory suffix.
282
* You know, the slash that we put on the end of a directory,
283
* or the | on the end of a fifo etc.
284
* Thus the following definitions. */
285
#define LNMAX 1000000
288
#define LNFORMAT "%06d "
295
/* Macros to loop through the items in a list. */
296
#define foreach(e,l) for((e)=(l).next; \
297
(e) != (void*)&(l); \
298
(e) = ((struct listHead *)e)->next)
299
#define foreachback(e,l) for((e)=(l).prev; \
300
(e) != (void*)&(l); \
301
(e) = ((struct listHead *)e)->prev)
303
/* an edbrowse window */
305
/* windows stack up as you open new files or follow hyperlinks.
306
* Use the back command to pop the stack.
307
* The back command follows this link, which is 0 if you are at the top. */
308
struct ebWindow *prev;
309
/* This is right out of the source for ed. Current and last line numbers. */
311
/* remember dot and dol for the raw text, when in browse mode */
313
char *fileName; /* name of file or url */
315
char *baseDirName; /* when scanning a directory */
316
char *ft, *fd, *fk; /* title, description, keywords */
318
char lhs[MAXRE], rhs[MAXRE]; /* remembered substitution strings */
319
char *map; /* indexes into textLines[] */
321
/* The labels that you set with the k command, and access via 'x.
322
* Basically, that's 26 line numbers.
323
* Number 0 means the label is not set. */
324
int labels[26], r_labels[26];
325
/* Yeah, these could be bit fields in the structure :1; but who cares. */
326
bool lhs_yes, rhs_yes;
327
bool binMode; /* binary file */
328
bool nlMode; /* newline at the end */
330
/* Two text modes; these are incompatible with binMode */
333
bool browseMode; /* browsing html */
334
bool changeMode; /* something has changed in this file */
335
bool dirMode; /* directory mode */
336
bool firstOpMode; /* first change has been made, undo is possible */
337
bool jsdead; /* javascript is dead, for this window */
338
bool sqlMode; /* accessing a table */
339
char *dw; /* document.write string */
340
int dw_l; /* length of the above */
341
void *tags; /* array of html tags, when browsing */
342
IP32bit *iplist; /* ip addresses referenced by this page */
343
void *jsc; /* js context, if in browse mode, and running javascript */
344
struct DBTABLE *table; /* if in sqlMode */
346
extern struct ebWindow *cw; /* current window */
348
/* An edit session */
350
struct ebWindow *fw, *lw; /* first window, last window */
352
extern struct ebSession sessionList[];
353
extern struct ebSession *cs; /* current session */
356
/* function prototypes */
359
/* Symbolic constants for language independent messages */
360
#include "messages.h"