File: headers.h

package info (click to toggle)
libperlbal-xs-httpheaders-perl 0.20-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 188 kB
  • sloc: cpp: 500; perl: 110; pascal: 69; makefile: 3
file content (82 lines) | stat: -rw-r--r-- 2,430 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/******************************************************************************
 * Perlbal XS HTTPHeaders class                                               *
 * Written by Mark Smith (junior@sixapart.com)                                *
 *                                                                            *
 * This program is free software; you can redistribute it and/or modify it    *
 * under the same terms as Perl itself.                                       *
 *                                                                            *
 * Copyright 2004 Danga Interactive, Inc.                                     *
 * Copyright 2005 Six Apart, Ltd.                                             *
 ******************************************************************************/

#ifndef __HEADERS_H
#define __HEADERS_H

extern "C" {
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
}

/* some general purpose defines we use */
#define H_REQUEST 1
#define H_RESPONSE 2

/* setup method constants */
#define M_GET 1
#define M_POST 2
#define M_OPTIONS 3
#define M_PUT 4
#define M_DELETE 5
#define M_HEAD 6

/* some structs we use for storing header information */
struct Header {
    int keylen;     /* 14 */
    char *key;      /* Content-length */
    SV *sv_value;   /* 5 */
    Header *prev, *next;
};

/* the main headers class */
class HTTPHeaders {

    private:
        int versionNumber, statusCode, headersType, method;
        SV *sv_uri, *sv_firstLine, *sv_methodString;

        Header *hdrs, *hdrtail;

        Header *findHeader(char *which, int len = 0);
        void freeHeader(Header *hdr);

    public:
        /* constructor and destructor */
        HTTPHeaders();
        ~HTTPHeaders();
        int parseHeaders(SV *headers);

        /* reconstructor */
        SV *getReconstructed();

        /* get and set header values */
        SV *getHeader(char *which);
        void setHeader(char *which, char *value);

        /* extra getters that we use to speed stuff up */
        int getMethod();
        SV *getMethodString();
        int getStatusCode();
        void setStatusCode(int code);
        void setVersionNumber(int version);
        int getVersionNumber();
        bool isRequest();
        bool isResponse();
        void setCodeText(int code, char *codetext);
        SV *getURI();
        SV *setURI(char *uri);
        SV *getHeadersList();
        
};

#endif