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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
|
/* Copyright 2000-2004 The Apache Software Foundation
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
#define PERL_NO_GET_CONTEXT /* we want efficiency */
#ifdef WIN32
#ifdef uid_t
#define apache_uid_t uid_t
#undef uid_t
#endif
#define uid_t apache_uid_t
#ifdef gid_t
#define apache_gid_t gid_t
#undef gid_t
#endif
#define gid_t apache_gid_t
#ifdef stat
#define apache_stat stat
#undef stat
#endif
#ifdef lstat
#define apache_lstat lstat
#undef lstat
#endif
#ifdef isnan
#define apache_isnan isnan
#undef isnan
#endif
#ifdef sleep
#define apache_sleep sleep
#undef sleep
#endif
#endif /* WIN32 */
#undef __attribute__
#include "mod_perl.h"
#include "apache_cookie.h"
#ifdef WIN32
#undef uid_t
#ifdef apache_uid_t
#define uid_t apache_uid_t
#undef apache_uid_t
#endif
#undef gid_t
#ifdef apache_gid_t
#define gid_t apache_gid_t
#undef apache_gid_t
#endif
#ifdef apache_isnan
#undef isnan
#define isnan apache_isnan
#undef apache_isnan
#endif
#ifdef apache_lstat
#undef lstat
#define lstat apache_lstat
#undef apache_lstat
#endif
#ifdef apache_stat
#undef stat
#define stat apache_stat
#undef apache_stat
#endif
#ifdef apache_sleep
#undef sleep
#define sleep apache_sleep
#undef apache_sleep
#endif
#endif /* WIN32 */
typedef ApacheCookie * Apache__Cookie;
static SV *cookie_bless(pTHX_ ApacheCookie *c)
{
SV *sv = newSV(0);
sv_setref_pv(sv, "Apache::Cookie", (void*)c);
return sv;
}
static ApacheCookie *sv_2cookie(pTHX_ SV *sv)
{
if (SvROK(sv) && sv_derived_from(sv, "Apache::Cookie")) {
return (ApacheCookie *)SvIV((SV*)SvRV(sv));
}
else {
return ApacheCookie_new(perl_request_rec(NULL), NULL);
}
}
#define cookie_push(c) \
XPUSHs(sv_2mortal(newSVpv(c->name,0))); \
XPUSHs(sv_2mortal(cookie_bless(aTHX_ c)))
#define ApacheCookie_name(c, val) \
ApacheCookie_attr(c, "name", val)
#define ApacheCookie_domain(c, val) \
ApacheCookie_attr(c, "domain", val)
#define ApacheCookie_path(c, val) \
ApacheCookie_attr(c, "path", val)
#define ApacheCookie_secure(c, val) \
ApacheCookie_attr(c, "secure", val)
MODULE = Apache::Cookie PACKAGE = Apache::Cookie PREFIX = ApacheCookie_
PROTOTYPES: DISABLE
Apache::Cookie
ApacheCookie_new(class, r, ...)
SV *class
Apache r
PREINIT:
I32 i;
CODE:
class = class; /* -Wall */
RETVAL = ApacheCookie_new(r, NULL);
for (i=2; i<items; i+=2) {
char *key = SvPV(ST(i),na);
SV *val = ST(i+1);
if (SvROK(val)) {
if (SvTYPE(SvRV(val)) == SVt_PVAV) {
I32 n;
AV *av = (AV*)SvRV(val);
for (n=0; n<=AvFILL(av); n++) {
(void)ApacheCookie_attr(RETVAL, key,
SvPV(*av_fetch(av, n, FALSE),na));
}
}
else if (SvTYPE(SvRV(val)) == SVt_PVHV) {
HV *hv = (HV*)SvRV(val);
SV *sv;
char *value;
I32 len;
(void)hv_iterinit(hv);
while ((sv = hv_iternextsv(hv, &value, &len))) {
(void)ApacheCookie_attr(RETVAL, key, value);
(void)ApacheCookie_attr(RETVAL, key,
sv == &PL_sv_undef ?
"" : SvPV(sv,na));
}
}
else {
croak("not an ARRAY or HASH reference!");
}
}
else {
(void)ApacheCookie_attr(RETVAL, key, SvPV(val,na));
}
}
OUTPUT:
RETVAL
char *
ApacheCookie_as_string(c)
Apache::Cookie c
void
ApacheCookie_parse(sv, string=NULL)
SV *sv
char *string
ALIAS:
Apache::Cookie::fetch = 1
PREINIT:
ApacheCookieJar *cookies;
ApacheCookie *c;
int i;
PPCODE:
if ((ix = XSANY.any_i32) == 1) {
request_rec *r = perl_request_rec(NULL);
c = ApacheCookie_new(r, NULL);
}
else {
c = sv_2cookie(aTHX_ sv);
}
cookies = ApacheCookie_parse(c->r, string);
if (!ApacheCookieJarItems(cookies)) {
XSRETURN_EMPTY;
}
if (GIMME == G_SCALAR) {
HV *hv = newHV();
SV *sv;
for (i=0; i<ApacheCookieJarItems(cookies); i++) {
ApacheCookie *c = ApacheCookieJarFetch(cookies, i);
if (c && c->name) {
hv_store(hv, c->name, strlen(c->name),
cookie_bless(aTHX_ c), FALSE);
}
}
sv = newRV_noinc((SV*)hv);
XPUSHs(sv_2mortal(sv));
}
else {
for (i=0; i<cookies->nelts; i++) {
cookie_push(ApacheCookieJarFetch(cookies, i));
}
}
void
ApacheCookie_value(c, val=Nullsv)
Apache::Cookie c
SV *val
PREINIT:
int i;
I32 gimmes = (GIMME == G_SCALAR);
PPCODE:
for (i = 0; i<ApacheCookieItems(c); i++) {
XPUSHs(sv_2mortal(newSVpv(ApacheCookieFetch(c,i),0)));
if (gimmes) {
break;
}
}
if (val) {
STRLEN len;
char *value;
ApacheCookieItems(c) = 0;
if (SvROK(val)) {
AV *av = (AV*)SvRV(val);
for (i=0; i<=AvFILL(av); i++) {
SV *sv = *av_fetch(av, i, FALSE);
value = SvPV(sv,len);
ApacheCookieAddLen(c, value, len);
}
}
else {
value = SvPV(val,len);
ApacheCookieAddLen(c, value, len);
}
}
char *
ApacheCookie_name(c, val=NULL)
Apache::Cookie c
char *val
char *
ApacheCookie_domain(c, val=NULL)
Apache::Cookie c
char *val
char *
ApacheCookie_path(c, val=NULL)
Apache::Cookie c
char *val
char *
ApacheCookie_expires(c, val=NULL)
Apache::Cookie c
char *val
char *
ApacheCookie_secure(c, val=NULL)
Apache::Cookie c
char *val
void
ApacheCookie_bake(c)
Apache::Cookie c
|