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.
40
2004
/
01
/27
15
:
01
:
05
grubba Exp $
+
|| $Id: roxen.c,v 1.
41
2005
/
10
/27
16
:
54
:
10
grubba Exp $
*/ #define NO_PIKE_SHORTHAND #include "global.h" #include "config.h" #include "machine.h"
pike.git/src/modules/_Roxen/roxen.c:240:
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; 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:276:
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 = (char *)res->str; #define STRADD(X)\ for( l=X.u.string->len,s=X.u.string->str,c=0; c<l; c++ )\ *(pnt++)=*(s++); NEW_MAPPING_LOOP( m->data ) { char *s;
pike.git/src/modules/_Roxen/roxen.c:304:
{ 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:536:
push_string( low_end_shared_string( res ) ); } } /*! @endmodule */ PIKE_MODULE_INIT { pike_add_function("make_http_headers", f_make_http_headers,
-
"function(mapping(string:string|array(string)):string)", 0 );
+
"function(mapping(string:string|array(string))
, int|void
:string)", 0 );
pike_add_function("http_decode_string", f_http_decode_string, "function(string:string)", 0 ); pike_add_function("html_encode_string", f_html_encode_string, "function(mixed:string)", 0 ); start_new_program(); ADD_STORAGE( struct header_buf ); set_init_callback( f_hp_init ); set_exit_callback( f_hp_exit ); pike_add_function( "feed", f_hp_feed, "function(string:array(string|mapping))",0 ); pike_add_function( "create", f_hp_create, "function(:void)", ID_STATIC ); end_class( "HeaderParser", 0 ); } PIKE_MODULE_EXIT { }