File: HTTPHeaders.xs

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 (197 lines) | stat: -rw-r--r-- 4,501 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/******************************************************************************
 * 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.                                             *
 ******************************************************************************/

#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

#include "ppport.h"

#include "headers.h"

#include "const-c.inc"

MODULE = Perlbal::XS::HTTPHeaders		PACKAGE = Perlbal::XS::HTTPHeaders		

INCLUDE: const-xs.inc

HTTPHeaders *
HTTPHeaders::new( headers, junk = 0 )
    SV *headers
    int junk
    CODE:
        RETVAL = new HTTPHeaders();
        if (!RETVAL) XSRETURN_UNDEF;
        if (!RETVAL->parseHeaders( headers )) {
            delete RETVAL;
            XSRETURN_UNDEF;
        }
    OUTPUT:
        RETVAL

void
HTTPHeaders::DESTROY()

SV *
HTTPHeaders::getReconstructed()

SV *
HTTPHeaders::getHeader( which )
    char *which

void
HTTPHeaders::setHeader( which, value )
    char *which
    char *value

int
HTTPHeaders::getMethod()

int
HTTPHeaders::getStatusCode()

int
HTTPHeaders::getVersionNumber()

void
HTTPHeaders::setVersionNumber( version )
    int version

bool
HTTPHeaders::isRequest()

bool
HTTPHeaders::isResponse()

void
HTTPHeaders::setStatusCode( code )
    int code

void
HTTPHeaders::setCodeText( code, codetext )
    int code
    char *codetext

SV *
HTTPHeaders::getURI()

SV *
HTTPHeaders::setURI( uri )
    char *uri

################################################################################
## setup functions that call through to our native functions; this is the
## interface definition that Perlbal expects to use when we're a replacement
## for the standard library

SV *
HTTPHeaders::header( which, value = NULL )
    char *which
    char *value
    PROTOTYPE: $;$
    CODE:
        // THIS is first argument, so we expect 2 or 3
        if (items > 2) {
            THIS->setHeader( which, value );
            if (GIMME_V != G_VOID && value) {
                RETVAL = THIS->getHeader( which );
            } else {
                XSRETURN_UNDEF;
            }
        } else
            RETVAL = THIS->getHeader( which );
    OUTPUT:
        RETVAL

SV *
HTTPHeaders::to_string()
    CODE:
        RETVAL = THIS->getReconstructed();
    OUTPUT:
        RETVAL

SV *
HTTPHeaders::to_string_ref()
    CODE:
        SV *temp = THIS->getReconstructed();
        RETVAL = newRV_noinc(temp);
    OUTPUT:
        RETVAL

SV *
HTTPHeaders::request_method()
    CODE:
        switch ( THIS->getMethod() ) {
            case M_GET:
                RETVAL = newSVpvn("GET", 3);
                break;
            case M_HEAD:
                RETVAL = newSVpvn("HEAD", 4);
                break;
            case M_POST:
                RETVAL = newSVpvn("POST", 4);
                break;
            case M_OPTIONS:
                RETVAL = newSVpvn("OPTIONS", 7);
                break;
            case M_PUT:
                RETVAL = newSVpvn("PUT", 3);
                break;
            case M_DELETE:
                RETVAL = newSVpvn("DELETE", 6);
                break;
            default:
                RETVAL = THIS->getMethodString();
        }
    OUTPUT:
        RETVAL

SV *
HTTPHeaders::request_uri()
    CODE:
        RETVAL = THIS->getURI();
    OUTPUT:
        RETVAL

SV *
HTTPHeaders::headers_list()
    CODE:
        RETVAL = THIS->getHeadersList();
    OUTPUT:
        RETVAL

SV *
HTTPHeaders::set_request_uri( uri = NULL )
    char *uri
    CODE:
        RETVAL = THIS->setURI(uri);
    OUTPUT:
        RETVAL

int
HTTPHeaders::response_code()
    CODE:
        RETVAL = THIS->getStatusCode();
    OUTPUT:
        RETVAL

int
HTTPHeaders::version_number( value = 0 )
    int value
    CODE:
        // do a set if we have 2 parameters
        if (items == 2) {
            THIS->setVersionNumber( value );
            RETVAL = value;
        } else
            RETVAL = THIS->getVersionNumber();
    OUTPUT:
        RETVAL