~ubuntu-branches/ubuntu/jaunty/edbrowse/jaunty

« back to all changes in this revision

Viewing changes to http.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:
19
19
 */
20
20
 
21
21
#include "eb.h"
22
 
#include "tcp.h"
 
22
 
23
23
/* You need the open ssl library for secure connections. */
24
24
/* Hence the openSSL exception above. */
25
25
#include <openssl/ssl.h>
426
426
{
427
427
    int port;                   /* usually 80 */
428
428
    const char *portloc;
429
 
    long hip;                   /* host IP */
 
429
    IP32bit hip;                /* host IP */
430
430
    const char *host, *post, *s;
431
431
    char *hdr;                  /* http header */
432
432
    char *u;
471
471
    host = getHostURL(url);
472
472
    if(!host)
473
473
        errorPrint("@empty host in httpConnect");
474
 
    hip = tcp_name_ip(host);
 
474
    if(proxy_host) {
 
475
        if(secure) {
 
476
            setError("secure proxy not yet implemented");
 
477
            return false;
 
478
        }
 
479
        hip = tcp_name_ip(proxy_host);
 
480
    } else {
 
481
        hip = tcp_name_ip(host);
 
482
    }
475
483
    if(hip == -1) {
476
484
        setError(intFlag ? opint : "cannot identify %s on the network", host);
477
485
        return false;
478
486
    }
479
 
    debugPrint(4, "%s -> %s", host, tcp_ip_dots(hip));
 
487
    debugPrint(4, "%s -> %s",
 
488
       (proxy_host ? proxy_host : host), tcp_ip_dots(hip));
480
489
 
481
490
/* See if the protocol is a recognized stream */
482
491
    if(stringEqualCI(prot, "http") || stringEqualCI(prot, "https")) {
539
548
    newurl = false;
540
549
 
541
550
    getPortLocURL(url, &portloc, &port);
542
 
    hsock = tcp_connect(hip, port, webTimeout);
 
551
    hsock = tcp_connect(hip, (proxy_host ? proxy_port : port), webTimeout);
543
552
    if(hsock < 0) {
544
553
        setError(intFlag ? opint : "cannot connect to %s", host);
545
554
        return false;
546
555
    }
547
 
    debugPrint(4, "connected to port %d", port);
 
556
    if(proxy_host)
 
557
        debugPrint(4, "connected to port %d/%d", proxy_port, port);
 
558
    else
 
559
        debugPrint(4, "connected to port %d", port);
548
560
    if(secure) {
549
561
        hssl = SSL_new(sslcx);
550
562
        SSL_set_fd(hssl, hsock);
574
586
        post++;
575
587
 
576
588
    hdr = initString(&l);
577
 
    stringAndString(&hdr, &l, post ? "POST /" : "GET /");
 
589
    stringAndString(&hdr, &l, post ? "POST " : "GET ");
 
590
    if(proxy_host) {
 
591
        stringAndString(&hdr, &l, prot);
 
592
        stringAndString(&hdr, &l, "://");
 
593
        stringAndString(&hdr, &l, host);
 
594
/* Some proxy servers won't accept :80 after the hostname.  Dunno why. */
 
595
        if(secure || port != 80) {
 
596
            stringAndChar(&hdr, &l, ':');
 
597
            stringAndNum(&hdr, &l, port);
 
598
        }
 
599
    }
 
600
    stringAndChar(&hdr, &l, '/');
 
601
 
578
602
    s = getDataURL(url);
579
603
    while(true) {
580
604
        char c, buf[4];
583
607
        c = *s;
584
608
        if(!c)
585
609
            break;
 
610
        if(c == '#')
 
611
            break;
586
612
        if(c == '\\')
587
613
            c = '/';
588
614
        if(c <= ' ') {
632
658
/* Web caching not yet implemented. */
633
659
    stringAndString(&hdr, &l,
634
660
       "Pragma: no-cache\r\nCache-Control: no-cache\r\n");
635
 
    stringAndString(&hdr, &l, "Accept-Encoding: gzip, compress, deflate\r\n");
 
661
    stringAndString(&hdr, &l, "Accept-Encoding: gzip, compress\r\n");
636
662
    stringAndString(&hdr, &l, "Accept-Language: en\r\n");
637
663
    if(u = getAuthString(url)) {
638
664
        stringAndString(&hdr, &l, u);
807
833
            fflush(stdout);
808
834
            fflush(stdin);
809
835
            if(!fgets(user, sizeof (user), stdin))
810
 
                exit(0);
 
836
                ebClose(0);
811
837
            n = strlen(user);
812
838
            if(n >= sizeof (user) - 1) {
813
839
                printf("user name too long, limit %d characters",
824
850
            fflush(stdout);
825
851
            fflush(stdin);
826
852
            if(!fgets(pass, sizeof (pass), stdin))
827
 
                exit(0);
 
853
                ebClose(0);
828
854
            n = strlen(pass);
829
855
            if(n >= sizeof (pass) - 1) {
830
856
                printf("user name too long, limit %d characters",
1058
1084
            break;
1059
1085
    if(j == 10 && line[j] == ' ') {     /* long list */
1060
1086
        int fsize, nlinks;
1061
 
        char user[40], group[40];
 
1087
        char user[42], group[42];
1062
1088
        char *q;
1063
 
        sscanf(line + j, " %d %s %s %d", &nlinks, user, group, &fsize);
 
1089
        sscanf(line + j, " %d %40s %40s %d", &nlinks, user, group, &fsize);
1064
1090
        q = strchr(line, ':');
1065
1091
        if(q) {
1066
1092
            for(++q; isdigitByte(*q) || *q == ':'; ++q) ;
1239
1265
void
1240
1266
allIPs(void)
1241
1267
{
1242
 
    static long iplist[5 + 1];
 
1268
    static IP32bit iplist[5 + 1];
1243
1269
    char *domlist[8];
1244
1270
    int iptotal = 0, domtotal = 0;
1245
 
    long ip;
 
1271
    IP32bit ip;
1246
1272
    int ntags, tagno;
1247
1273
    char *href;
1248
1274
    const char *dom;
1253
1279
    for(ln = 1; ln <= cw->dol; ++ln) {
1254
1280
        p = (char *)fetchLine(ln, -1);
1255
1281
        ftype = 0;              /* input stuff doesn't work */
1256
 
        findField(p, ftype, 0, &nf, 0, 0, 0);
 
1282
        findField(p, ftype, 0, &nf, 0, 0, 0, 0);
1257
1283
        for(j = 1; j <= nf; ++j) {
1258
 
            findField(p, ftype, j, &nf, &tagno, &href, 0);
 
1284
            findField(p, ftype, j, &nf, 0, &tagno, &href, 0);
1259
1285
            if(!href)
1260
1286
                continue;
1261
1287
            if(dom = getHostURL(href)) {
1277
1303
                        ip = tcp_dots_ip(dom);
1278
1304
                    else
1279
1305
                        ip = tcp_name_ip(dom);
1280
 
                    if(ip != -1) {
 
1306
                    if(ip != NULL_IP) {
1281
1307
/* could be a repeat */
1282
1308
                        for(k = 0; k < iptotal; ++k)
1283
1309
                            if(iplist[k] == ip)
1301
1327
    }                           /* loop over lines */
1302
1328
 
1303
1329
  done:
1304
 
    iplist[iptotal] = -1;
 
1330
    iplist[iptotal] = NULL_IP;
1305
1331
    cw->iplist = iplist;
1306
1332
    for(k = 0; k < domtotal; ++k)
1307
1333
        nzFree(domlist[k]);