Changeset 989
- Timestamp:
- 03/01/08 21:34:57 (6 months ago)
- Files:
-
- trunk/ext/http11/ext_help.h (modified) (1 diff)
- trunk/ext/http11/http11.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ext/http11/ext_help.h
r4 r989 5 5 #define DATA_GET(from,type,name) Data_Get_Struct(from,type,name); RAISE_NOT_NULL(name); 6 6 #define REQUIRE_TYPE(V, T) if(TYPE(V) != T) rb_raise(rb_eTypeError, "Wrong argument type for " # V " required " # T); 7 #define ASCII_UPCASE_CHAR(ch) (ch & ~0x20) 8 7 9 8 10 #ifdef DEBUG trunk/ext/http11/http11.c
r944 r989 8 8 #include <string.h> 9 9 #include "http11_parser.h" 10 #include <ctype.h>11 10 12 11 #ifndef RSTRING_PTR … … 70 69 void http_field(void *data, const char *field, size_t flen, const char *value, size_t vlen) 71 70 { 72 char *ch, *end; 71 char *ch; 72 const char *fch; 73 73 VALUE req = (VALUE)data; 74 74 VALUE v = Qnil; … … 79 79 80 80 v = rb_str_new(value, vlen); 81 f = rb_str_dup(global_http_prefix); 82 f = rb_str_buf_cat(f, field, flen); 83 84 for(ch = RSTRING_PTR(f), end = ch + RSTRING_LEN(f); ch < end; ch++) { 85 if(*ch == '-') { 86 *ch = '_'; 87 } else { 88 *ch = toupper(*ch); 89 } 81 82 /* 83 * using rb_str_new(NULL, len) here is faster than rb_str_buf_new(len) 84 * in my testing, because: there's no minimum allocation length (and 85 * no check for it, either), RSTRING_LEN(f) does not need to be 86 * written twice, and and RSTRING_PTR(f) will already be 87 * null-terminated for us. 88 */ 89 f = rb_str_new(NULL, RSTRING_LEN(global_http_prefix) + flen); 90 memcpy(RSTRING_PTR(f), 91 RSTRING_PTR(global_http_prefix), 92 RSTRING_LEN(global_http_prefix)); 93 94 ch = RSTRING_PTR(f) + RSTRING_LEN(global_http_prefix); 95 for(fch = field; flen-- != 0; ++fch) { 96 *ch++ = (*fch >= 'a' && *fch <= 'z') ? 97 ASCII_UPCASE_CHAR(*fch) : 98 (*fch == '-' ? '_' : *fch); 90 99 } 91 100
