pike.git
/
src
/
modules
/
_Roxen
/
roxen.c
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/src/modules/_Roxen/roxen.c:1:
/* || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information.
-
|| $Id: roxen.c,v 1.
45
2005/
05
/
06
00
:
46
:
06
nilsson
Exp $
+
|| $Id: roxen.c,v 1.
46
2005/
10
/
27
16
:
49
:
54
grubba
Exp $
*/ #define NO_PIKE_SHORTHAND #include "global.h" #include "config.h" #include "machine.h"
pike.git/src/modules/_Roxen/roxen.c:241:
THP->spc = THP->slash_n = 0; pop_n_elems(args); push_int(0); } /*! @endclass */ static void f_make_http_headers( INT32 args ) /*! @decl string @
-
*! make_http_headers(mapping(string:string|array(string)) headers)
+
*! make_http_headers(mapping(string:string|array(string)) headers
, @
+
*! int(0..1
)
|void no_terminator)
*/ { int total_len = 0, e; unsigned char *pnt; struct mapping *m; struct keypair *k; struct pike_string *res;
-
if( Pike_sp[-
1
].type != PIKE_T_MAPPING )
+
int terminator = 2;
+
+
if( Pike_sp[-
args
].type != PIKE_T_MAPPING )
Pike_error("Wrong argument type to make_http_headers(mapping heads)\n");
-
+
m = Pike_sp[-args].u.mapping;
-
m
=
Pike_sp[-1].u.
mapping
;
+
if
(args > 1) {
+
if (Pike_sp[1-args].type !
=
PIKE_T_INT)
+
Pike_
error("Bad argument 2 to make_http_headers(). Expected int.\n");
+
if (Pike_
sp[
1
-
args
].u.
integer)
+
terminator = 0
;
+
}
+
/* loop to check len */ NEW_MAPPING_LOOP( m->data ) { if( k->ind.type != PIKE_T_STRING || k->ind.u.string->size_shift ) Pike_error("Wrong argument type to make_http_headers(" "mapping(string(8bit):string(8bit)|array(string(8bit))) heads)\n"); if( k->val.type == PIKE_T_STRING && !k->val.u.string->size_shift ) total_len += k->val.u.string->len + 2 + k->ind.u.string->len + 2; else if( k->val.type == PIKE_T_ARRAY ) {
pike.git/src/modules/_Roxen/roxen.c:277:
Pike_error("Wrong argument type to make_http_headers(" "mapping(string(8bit):string(8bit)|" "array(string(8bit))) heads)\n"); else total_len += kl + a->item[i].u.string->len + 2; } else Pike_error("Wrong argument type to make_http_headers(" "mapping(string(8bit):string(8bit)|" "array(string(8bit))) heads)\n"); }
-
total_len +=
2
;
+
total_len +=
terminator
;
res = begin_shared_string( total_len ); pnt = STR0(res); #define STRADD(X) \ for( l=(X).u.string->len, s=STR0((X).u.string), c=0; c<l; c++ ) \ *(pnt++)=*(s++) NEW_MAPPING_LOOP( m->data ) { unsigned char *s;
pike.git/src/modules/_Roxen/roxen.c:305:
{ struct array *a = k->val.u.array; ptrdiff_t i, kl = k->ind.u.string->len + 2; for( i = 0; i<a->size; i++ ) { STRADD( k->ind ); *(pnt++) = ':'; *(pnt++) = ' '; STRADD( a->item[i] );*(pnt++) = '\r';*(pnt++) = '\n'; } } }
+
if (terminator) {
*(pnt++) = '\r'; *(pnt++) = '\n';
-
+
}
pop_n_elems( args ); push_string( end_shared_string( res ) ); } static void f_http_decode_string(INT32 args) /*! @decl string http_decode_string(string encoded) *! *! Decodes an http transport-encoded string. */
pike.git/src/modules/_Roxen/roxen.c:537:
push_string( low_end_shared_string( res ) ); } } /*! @endmodule */ PIKE_MODULE_INIT { ADD_FUNCTION("make_http_headers", f_make_http_headers,
-
tFunc(tMap(tStr,tOr(tStr,tArr(tStr))),tStr),
0
);
+
tFunc(tMap(tStr,tOr(tStr,tArr(tStr)))
tOr(tInt01
,
tVoid),
tStr),
+
0);
ADD_FUNCTION("http_decode_string", f_http_decode_string, tFunc(tStr,tStr), 0 ); ADD_FUNCTION("html_encode_string", f_html_encode_string, tFunc(tMix,tStr), 0 ); start_new_program(); ADD_STORAGE( struct header_buf ); set_init_callback( f_hp_init ); set_exit_callback( f_hp_exit ); ADD_FUNCTION( "feed", f_hp_feed, tFunc(tStr,tArr(tOr(tStr,tMapping))), 0 ); ADD_FUNCTION( "create", f_hp_create, tFunc(tNone,tVoid), ID_STATIC ); end_class( "HeaderParser", 0 ); } PIKE_MODULE_EXIT { }