~ubuntu-branches/ubuntu/natty/edbrowse/natty

« back to all changes in this revision

Viewing changes to main.c

  • Committer: Bazaar Package Importer
  • Author(s): Kapil Hari Paranjape
  • Date: 2007-05-09 07:33:04 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070509073304-ywptg9g6iiitsg17
Tags: 3.2.1-1
* New upstream version (3.2.1). Closes: #421451.
  - can fetch and execute a local javascript file
    if required by local html file.
  - provide COPYING and CHANGES files.
* debian/rules:
  - add CHANGES to dh_installchangelogs line.
  - add dh_installman entry to install the man page.
* debian/copyright: updated to include the COPYING file.
* debian/edbrowse.1: added a basic man page.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 */
6
6
 
7
7
#include "eb.h"
8
 
#include "tcp.h"
9
8
 
10
9
#include <signal.h>
11
10
#include <pcre.h>
13
12
/* Define the globals that are declared in eb.h. */
14
13
/* See eb.h for descriptive comments. */
15
14
 
16
 
const char *version = "3.1.2";
 
15
const char *version = "3.2.1";
17
16
char *userAgents[10], *currentAgent, *currentReferrer;
18
17
const char eol[] = "\r\n";
19
18
char EMPTYSTRING[] = "";
27
26
struct MACCOUNT accounts[MAXACCOUNT];
28
27
int maxMime;
29
28
struct MIMETYPE mimetypes[MAXMIME];
 
29
static int maxTables;
 
30
static struct DBTABLE dbtables[MAXDBT];
 
31
char *dbarea, *dblogin, *dbpw;  /* to log into the database */
 
32
char *proxy_host;
 
33
int proxy_port;
30
34
bool caseInsensitive, searchStringsAll;
31
35
bool textAreaDosNewlines = true, undoable;
32
36
bool allowRedirection = true, allowJS = true, sendReferrer = false;
146
150
    bool cmt = false;
147
151
    bool startline = true;
148
152
    bool cfgmodify = false;
149
 
    uchar mailblock = 0, mimeblock = 0;
 
153
    uchar mailblock = 0, mimeblock = 0, tabblock = 0;
150
154
    int nest, ln, j;
151
155
    int sn = 0;                 /* script number */
152
156
    char stack[MAXNEST];
154
158
    int lidx = 0;
155
159
    struct MACCOUNT *act;
156
160
    struct MIMETYPE *mt;
 
161
    struct DBTABLE *td;
157
162
    static const char *const keywords[] = {
158
163
        "inserver", "outserver", "login", "password", "from", "reply",
159
164
        "inport", "outport",
160
165
        "type", "desc", "suffix", "protocol", "program",
 
166
        "tname", "tshort", "cols", "keycol",
161
167
        "adbook", "ipblack", "maildir", "agent",
162
168
        "jar", "nojs", "spamcan",
163
 
        "webtimer", "mailtimer", "certfile",
 
169
        "webtimer", "mailtimer", "certfile", "database", "proxy",
164
170
        0
165
171
    };
166
172
 
214
220
                v[1] = 'e';
215
221
                t = v + 2;
216
222
            }
 
223
            if(stringEqual(last, "table{")) {
 
224
                *v = '\x81';
 
225
                v[1] = 'b';
 
226
                t = v + 2;
 
227
            }
217
228
            if(stringEqual(last, "fromfilter{")) {
218
229
                *v = '\x81';
219
230
                v[1] = 'r';
408
419
               ("1.ebrc: line %d, attribute %s canot be set outside of a mime descriptor",
409
420
               ln, s);
410
421
 
 
422
        if(n >= 13 && n < 17 && tabblock != 1)
 
423
            errorPrint
 
424
               ("1.ebrc: line %d, attribute %s canot be set outside of a table descriptor",
 
425
               ln, s);
 
426
 
411
427
        if(n >= 8 && mailblock)
412
428
            errorPrint
413
429
               ("1.ebrc: line %d, attribute %s canot be set inside a mail descriptor or filter block",
418
434
               ("1.ebrc: line %d, attribute %s canot be set inside a mime descriptor",
419
435
               ln, s);
420
436
 
 
437
        if((n < 13 || n >= 17) && tabblock)
 
438
            errorPrint
 
439
               ("1.ebrc: line %d, attribute %s canot be set inside a table descriptor",
 
440
               ln, s);
 
441
 
421
442
/* act upon the keywords */
422
443
        ++v;
423
444
        if(c != '=') {
487
508
            continue;
488
509
 
489
510
        case 13:
 
511
            td->name = v;
 
512
            continue;
 
513
 
 
514
        case 14:
 
515
            td->shortname = v;
 
516
            continue;
 
517
 
 
518
        case 15:
 
519
            while(*v) {
 
520
                if(td->ncols == MAXTCOLS)
 
521
                    errorPrint("1.ebrc: line %d, too many columns, limit %d",
 
522
                       ln, MAXTCOLS);
 
523
                td->cols[td->ncols++] = v;
 
524
                q = strchr(v, ',');
 
525
                if(!q)
 
526
                    break;
 
527
                *q = 0;
 
528
                v = q + 1;
 
529
            }
 
530
            continue;
 
531
 
 
532
        case 16:
 
533
            if(!isdigitByte(*v))
 
534
                errorPrint
 
535
                   ("1.ebrc: line %d, keycol should be number or number,number",
 
536
                   ln);
 
537
            td->key1 = strtol(v, &v, 10);
 
538
            if(*v == ',' && isdigitByte(v[1]))
 
539
                td->key2 = strtol(v + 1, &v, 10);
 
540
            if(td->key1 > td->ncols || td->key2 > td->ncols)
 
541
                errorPrint
 
542
                   ("1.ebrc: line %d, keycol is out of range; only %d columns specified",
 
543
                   ln, td->ncols);
 
544
            continue;
 
545
 
 
546
        case 17:
490
547
            addressFile = v;
491
548
            ftype = fileTypeByName(v, false);
492
549
            if(ftype && ftype != 'f')
493
550
                errorPrint("1.ebrc: address book %s is not a regular file", v);
494
551
            continue;
495
552
 
496
 
        case 14:
 
553
        case 18:
497
554
            ipbFile = v;
498
555
            ftype = fileTypeByName(v, false);
499
556
            if(ftype && ftype != 'f')
500
557
                errorPrint("1.ebrc: ip blacklist %s is not a regular file", v);
501
558
            continue;
502
559
 
503
 
        case 15:
 
560
        case 19:
504
561
            mailDir = v;
505
562
            if(fileTypeByName(v, false) != 'd')
506
563
                errorPrint("1.ebrc: %s is not a directory", v);
507
564
            continue;
508
565
 
509
 
        case 16:
 
566
        case 20:
510
567
            for(j = 0; j < 10; ++j)
511
568
                if(!userAgents[j])
512
569
                    break;
516
573
            userAgents[j] = v;
517
574
            continue;
518
575
 
519
 
        case 17:
 
576
        case 21:
520
577
            cookieFile = v;
521
578
            ftype = fileTypeByName(v, false);
522
579
            if(ftype && ftype != 'f')
528
585
            close(j);
529
586
            continue;
530
587
 
531
 
        case 18:
 
588
        case 22:
532
589
            if(javaDisCount == MAXNOJS)
533
590
                errorPrint("1.ebrc: too many no js directives, limit %d",
534
591
                   MAXNOJS);
541
598
            javaDis[javaDisCount++] = v;
542
599
            continue;
543
600
 
544
 
        case 19:
 
601
        case 23:
545
602
            spamCan = v;
546
603
            ftype = fileTypeByName(v, false);
547
604
            if(ftype && ftype != 'f')
549
606
                   v);
550
607
            continue;
551
608
 
552
 
        case 20:
 
609
        case 24:
553
610
            webTimeout = atoi(v);
554
611
            continue;
555
612
 
556
 
        case 21:
 
613
        case 25:
557
614
            mailTimeout = atoi(v);
558
615
            continue;
559
616
 
560
 
        case 22:
 
617
        case 26:
561
618
            sslCerts = v;
562
619
            ftype = fileTypeByName(v, false);
563
620
            if(ftype && ftype != 'f')
571
628
            close(j);
572
629
            continue;
573
630
 
 
631
        case 27:
 
632
            dbarea = v;
 
633
            v = strchr(v, ',');
 
634
            if(!v)
 
635
                continue;
 
636
            *v++ = 0;
 
637
            dblogin = v;
 
638
            v = strchr(v, ',');
 
639
            if(!v)
 
640
                continue;
 
641
            *v++ = 0;
 
642
            dbpw = v;
 
643
            continue;
 
644
 
 
645
        case 28:                /* proxy */
 
646
            proxy_host = v;
 
647
            proxy_port = 80;
 
648
            v = strchr(v, ':');
 
649
            if(v) {
 
650
                *v++ = 0;
 
651
                proxy_port = atoi(v);
 
652
            }
 
653
            continue;
 
654
 
574
655
        default:
575
656
            errorPrint("1.ebrc: line %d, keyword %s is not yet implemented", ln,
576
657
               s);
631
712
                continue;
632
713
            }
633
714
 
 
715
            if(tabblock == 1) {
 
716
                ++maxTables;
 
717
                tabblock = 0;
 
718
                if(!td->name)
 
719
                    errorPrint("1.ebrc: missing table name at line %d", ln);
 
720
                if(!td->shortname)
 
721
                    errorPrint("1.ebrc: missing short name at line %d", ln);
 
722
                if(!td->ncols)
 
723
                    errorPrint("1.ebrc: missing columns at line %d", ln);
 
724
                continue;
 
725
            }
 
726
 
634
727
            if(--nest < 0)
635
728
                errorPrint("1.ebrc: unexpected } at line %d", ln);
636
729
            if(nest)
672
765
               ln, curblock);
673
766
        }
674
767
 
675
 
        if(!strchr("fmerts", c) && !nest)
 
768
        if(!strchr("fmertsb", c) && !nest)
676
769
            errorPrint
677
770
               ("1.ebrc: statement at line %d must appear inside a function",
678
771
               ln);
697
790
            continue;
698
791
        }
699
792
 
 
793
        if(c == 'b') {
 
794
            tabblock = 1;
 
795
            if(maxTables == MAXDBT)
 
796
                errorPrint
 
797
                   ("1too many sql tables in your config file, limit %d",
 
798
                   MAXDBT);
 
799
            td = dbtables + maxTables;
 
800
            continue;
 
801
        }
 
802
 
700
803
        if(c == 'r') {
701
804
            mailblock = 2;
702
805
            continue;
888
991
}                               /* catchSig */
889
992
 
890
993
void
 
994
ebClose(int n)
 
995
{
 
996
    dbClose();
 
997
    exit(n);
 
998
}                               /* ebClose */
 
999
 
 
1000
void
891
1001
eeCheck(void)
892
1002
{
893
1003
    if(errorExit)
894
 
        exit(1);
 
1004
        ebClose(1);
895
1005
}
896
1006
 
897
1007
/* I'm not going to expand wild card arguments here.
1062
1172
        showError();
1063
1173
        exit(1);
1064
1174
    }
1065
 
    /* mail client */
 
1175
 
1066
1176
    cookiesFromJar();
1067
1177
 
1068
1178
    signal(SIGINT, catchSig);
 
1179
    siginterrupt(SIGINT, 1);
1069
1180
    signal(SIGPIPE, SIG_IGN);
1070
1181
 
1071
1182
 
1081
1192
            runEbFunction("init");
1082
1193
        changeFileName = 0;
1083
1194
        fetchHistory(0, 0);     /* reset history */
 
1195
        cw->fileName = cloneString(file);
 
1196
        if(isSQL(file))
 
1197
            cw->sqlMode = true;
1084
1198
        rc = readFile(file, "");
1085
 
        debugPrint(1, "%d", fileSize);
 
1199
        if(fileSize >= 0)
 
1200
            debugPrint(1, "%d", fileSize);
1086
1201
        fileSize = -1;
1087
1202
        if(!rc) {
1088
1203
            showError();
1089
 
            cw->fileName = cloneString(file);
1090
 
        } else {
1091
 
            cw->fileName =
1092
 
               (changeFileName ? changeFileName : cloneString(file));
 
1204
        } else if(changeFileName) {
 
1205
            nzFree(cw->fileName);
 
1206
            cw->fileName = changeFileName;
1093
1207
            changeFileName = 0;
1094
1208
        }
1095
 
        if(memEqualCI(cw->fileName, "ftp://", 6)) {
 
1209
        if(cw->fileName && memEqualCI(cw->fileName, "ftp://", 6)) {
1096
1210
            nzFree(cw->fileName);
1097
1211
            cw->fileName = 0;
1098
1212
        }
1099
1213
        cw->firstOpMode = cw->changeMode = false;
1100
1214
/* Browse the text if it's a url */
1101
1215
        if(rc && !(cw->binMode | cw->dirMode) && cw->dol && isURL(cw->fileName)) {
1102
 
#if 1
1103
1216
            if(runCommand("b"))
1104
1217
                debugPrint(1, "%d", fileSize);
1105
 
#else
1106
 
            if(browseCurrentBuffer())
1107
 
                debugPrint(1, "%d", fileSize);
1108
 
#endif
1109
1218
            else
1110
1219
                showError();
1111
1220
        }
1404
1513
    return true;
1405
1514
}                               /* bufferToProgram */
1406
1515
 
 
1516
struct DBTABLE *
 
1517
findTableDescriptor(const char *sn)
 
1518
{
 
1519
    int i;
 
1520
    struct DBTABLE *td = dbtables;
 
1521
    for(i = 0; i < maxTables; ++i, ++td)
 
1522
        if(stringEqual(td->shortname, sn))
 
1523
            return td;
 
1524
    return 0;
 
1525
}                               /* findTableDescriptor */
 
1526
 
 
1527
struct DBTABLE *
 
1528
newTableDescriptor(const char *name)
 
1529
{
 
1530
    struct DBTABLE *td;
 
1531
    if(maxTables == MAXDBT) {
 
1532
        setError("too many sql tables in cache, limit %d", MAXDBT);
 
1533
        return 0;
 
1534
    }
 
1535
    td = dbtables + maxTables++;
 
1536
    td->name = td->shortname = cloneString(name);
 
1537
    td->ncols = 0;              /* it's already 0 */
 
1538
    return td;
 
1539
}                               /* newTableDescriptor */
 
1540
 
1407
1541
struct MIMETYPE *
1408
1542
findMimeBySuffix(const char *suffix)
1409
1543
{