~ubuntu-branches/debian/wheezy/eperl/wheezy

« back to all changes in this revision

Viewing changes to eperl_http.c

  • Committer: Bazaar Package Importer
  • Author(s): Denis Barbier
  • Date: 2001-12-18 20:40:24 UTC
  • Revision ID: james.westby@ubuntu.com-20011218204024-k0oaqq2eaw733v30
Tags: 2.2.14-4
* Remove emacs crap from debian/changelog
* Fix misspelling in debian/copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
**
16
16
**  ======================================================================
17
17
**
18
 
**  Copyright (c) 1996,1997,1998 Ralf S. Engelschall <rse@engelschall.com>
 
18
**  Copyright (c) 1996,1997,1998,1999 Ralf S. Engelschall <rse@engelschall.com>
19
19
**
20
20
**  This program is free software; it may be redistributed and/or modified
21
21
**  only under the terms of either the Artistic License or the GNU General
37
37
#include "eperl_global.h"
38
38
#include "eperl_proto.h"
39
39
 
 
40
#define _EPERL_VERSION_C_AS_HEADER_
 
41
#include "eperl_version.c"
 
42
#undef  _EPERL_VERSION_C_AS_HEADER_
40
43
 
41
44
/*
42
45
**  
43
46
**  print a standard HTTP reponse of header lines
44
47
**
45
48
*/
46
 
void HTTP_PrintResponseHeaders(char *cpBuf)
 
49
char *HTTP_PrintResponseHeaders(char *cpBuf)
47
50
{
48
51
    char *cp;
49
52
 
50
 
    if ((cp = getenv("SERVER_PROTOCOL")) == NULL)
51
 
        cp = "HTTP/1.0";
52
 
    printf("%s 200 OK\n", cp);
 
53
    if ((strncmp(cpBuf, "HTTP/1.0 ", 9) == 0
 
54
        || (strncmp(cpBuf, "HTTP/1.1 ", 9) == 0))
 
55
        && (cpBuf[9] >= '1' && cpBuf[9] <= '5')
 
56
        && (cpBuf[10] >= '0' && cpBuf[10] <= '9')
 
57
        && (cpBuf[11] >= '0' && cpBuf[11] <= '9')
 
58
        && (cpBuf[12] == ' ')
 
59
        && ((cp = strchr(cpBuf + 12, '\n')) != NULL)) {
 
60
        /* found HTTP status code */
 
61
        if (*(cp-1) == '\r') {
 
62
            *(cp-1) = '\0';
 
63
        }
 
64
        *cp++ = '\0';
 
65
        printf("%s\r\n", cpBuf);
 
66
        cpBuf = cp;
 
67
    } else {
 
68
        /* no HTTP status code */
 
69
        if ((cp = getenv("SERVER_PROTOCOL")) == NULL)
 
70
            cp = "HTTP/1.0";
 
71
        printf("%s 200 OK\r\n", cp);
 
72
    }
53
73
 
54
74
    if (!HTTP_HeaderLineExists(cpBuf, "Server")) {
55
75
        if ((cp = getenv("SERVER_SOFTWARE")) == NULL)
56
76
            cp = "unknown-server/0.0";
57
 
        printf("Server: %s %s Perl/%s\n", cp, ePerl_WebID, AC_perl_vers);
 
77
        printf("Server: %s %s Perl/%s\r\n", cp, eperl_version.v_web, AC_perl_vers);
58
78
    }
59
79
 
60
80
    if (!HTTP_HeaderLineExists(cpBuf, "Date"))
61
 
        printf("Date: %s\n", WebTime());
 
81
        printf("Date: %s\r\n", WebTime());
62
82
 
63
83
    if (!HTTP_HeaderLineExists(cpBuf, "Connection"))
64
 
        printf("Connection: close\n");
 
84
        printf("Connection: close\r\n");
65
85
 
66
 
    return;
 
86
    return cpBuf;
67
87
}
68
88
 
69
89
/*
242
262
    if (cps == NUL) 
243
263
        strcpy(file, "/");
244
264
    else 
245
 
        strcpy(file, cps);
 
265
        strncpy(file, cps, sizeof(file));
 
266
    file[sizeof(file)-1] = NUL;
246
267
    return file;
247
268
}
248
269
 
254
275
    struct hostent *he;
255
276
    struct sockaddr_in sar;
256
277
    struct protoent *pe;
257
 
    char cmd[1024];
 
278
    char *cmd;
258
279
    char buf[1024];
259
280
    char newurl[8192];
260
281
    char *host;
292
313
        return NULL;
293
314
 
294
315
    /* form the HTTP/1.0 request */
295
 
    sprintf(cmd, "GET %s HTTP/1.0\n", file);
296
 
    sprintf(cmd+strlen(cmd), "Host: %s:%s\n", host, port);
297
 
    sprintf(cmd+strlen(cmd), "User-Agent: %s\n", ePerl_WebID);
298
 
    sprintf(cmd+strlen(cmd), "\n");
 
316
    cmd = malloc(64 + strlen(file) + strlen(host) +
 
317
                      strlen(port) + strlen(eperl_version.v_web));
 
318
    if (cmd == NULL)
 
319
        return NULL;
 
320
    /* cmd has enough space */
 
321
    sprintf(cmd, "GET %s HTTP/1.0\r\n", file);
 
322
    sprintf(cmd+strlen(cmd), "Host: %s:%s\r\n", host, port);
 
323
    sprintf(cmd+strlen(cmd), "User-Agent: %s\r\n", eperl_version.v_web);
 
324
    sprintf(cmd+strlen(cmd), "\r\n");
299
325
 
300
326
    /* send the request */
301
327
    write(s, cmd, strlen(cmd));
 
328
    free(cmd);
302
329
 
303
330
    /* convert the file descriptor to a FILE pointer */
304
331
    fp = fdopen(s, "r");
330
357
                    for (cp2 = cp; *cp2 != ' ' && *cp2 != '\t' && *cp2 != '\n' && *cp2 != NUL; cp2++)
331
358
                        ;
332
359
                    *cp2 = NUL;
333
 
                    strcpy(newurl, cp);
 
360
                    strncpy(newurl, cp, sizeof(newurl));
 
361
                    newurl[sizeof(newurl)-1] = NUL;
334
362
                    break;
335
363
                }
336
364
            }