Changeset 602
- Timestamp:
- 01/13/07 14:40:04 (2 years ago)
- Files:
-
- cherokee/trunk/ChangeLog (modified) (1 diff)
- cherokee/trunk/cherokee/buffer.c (modified) (13 diffs)
- cherokee/trunk/cherokee/buffer.h (modified) (1 diff)
- cherokee/trunk/cherokee/connection.c (modified) (8 diffs)
- cherokee/trunk/cherokee/nonce.c (modified) (2 diffs)
- cherokee/trunk/cherokee/request.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
cherokee/trunk/ChangeLog
r601 r602 1 2007-01-13 A.D.F <adefacc@tin.it> 2 3 * cherokee/buffer.h: 4 - added prototype for new function 5 cherokee_buffer_add_char(). 6 7 * cherokee/buffer.c: 8 - added new function 9 cherokee_buffer_add_char() to add a single char 10 to buffer. 11 12 * cherokee/connection.c: 13 - small formatting cleanups; 14 - fixed capitalization of header keywords 15 (Keep-alive -> Keep-Alive and Close -> close) 16 in order to make them to look exactly as written 17 in RFC specifications 18 (even if header keywords must be read 19 in a case insensitive way); 20 - substituted a couple of cherokee_buffer_add_str(s) 21 with equivalent cherokee_buffer_add_char() calls. 22 23 * cherokee/nonce.c: 24 - substituted a few cherokee_buffer_add_va() 25 with equivalent cherokee_buffer_add_*() calls 26 (micro speedup). 27 28 * cherokee/request.c: 29 - small cleanups; 30 - substituted cherokee_buffer_add(buf, constant_string, len) 31 with equivalent cherokee_buffer_add_str() calls; 32 - substituted a few cherokee_buffer_add_va() 33 with equivalent cherokee_buffer_add_*() calls 34 (micro speedup); 35 - removed the allocation / deallocation 36 of a local new_once buffer in favour of the standard 37 THREAD_TMP_BUF1() temporary buffer 38 (micro speedup). 39 1 40 2007-01-11 Alvaro Lopez Ortega <alvaro@alobbs.com> 2 41 cherokee/trunk/cherokee/buffer.c
r597 r602 242 242 */ 243 243 newlen = buf->len + (int) ((IOS_NUMBUF - 1) - i); 244 if (unlikely ( newlen >= buf->size)) {244 if (unlikely (newlen >= buf->size)) { 245 245 if (unlikely (realloc_new_bufsize(buf, newlen)) != ret_ok) 246 246 return ret_nomem; … … 288 288 */ 289 289 newlen = buf->len + (int) ((IOS_NUMBUF - 1) - i); 290 if (unlikely ( newlen >= buf->size)) {290 if (unlikely (newlen >= buf->size)) { 291 291 if (unlikely (realloc_new_bufsize(buf, newlen)) != ret_ok) 292 292 return ret_nomem; … … 322 322 */ 323 323 newlen = buf->len + (int) ((IOS_NUMBUF - 1) - i); 324 if (unlikely ( newlen >= buf->size)) {324 if (unlikely (newlen >= buf->size)) { 325 325 if (unlikely (realloc_new_bufsize(buf, newlen)) != ret_ok) 326 326 return ret_nomem; … … 356 356 */ 357 357 newlen = buf->len + (int) ((IOS_NUMBUF - 1) - i); 358 if (unlikely ( newlen >= buf->size)) {358 if (unlikely (newlen >= buf->size)) { 359 359 if (unlikely (realloc_new_bufsize(buf, newlen)) != ret_ok) 360 360 return ret_nomem; … … 395 395 */ 396 396 newlen = buf->len + (int) ((IOS_NUMBUF - 1) - i); 397 if (unlikely ( newlen >= buf->size)) {397 if (unlikely (newlen >= buf->size)) { 398 398 if (unlikely (realloc_new_bufsize(buf, newlen)) != ret_ok) 399 399 return ret_nomem; … … 434 434 */ 435 435 newlen = buf->len + (int) ((IOS_NUMBUF - 1) - i); 436 if (unlikely ( newlen >= buf->size)) {436 if (unlikely (newlen >= buf->size)) { 437 437 if (unlikely (realloc_new_bufsize(buf, newlen)) != ret_ok) 438 438 return ret_nomem; … … 509 509 510 510 511 ret_t 512 cherokee_buffer_add_char (cherokee_buffer_t *buf, char c) 513 { 514 /* Add char (fast path) 515 */ 516 if (likely (buf->len + 1 < buf->size)) { 517 buf->buf[buf->len++] = c; 518 buf->buf[buf->len] = '\0'; 519 return ret_ok; 520 } 521 522 /* Get memory 523 */ 524 if (unlikely (realloc_inc_bufsize(buf, 1)) != ret_ok) 525 return ret_nomem; 526 527 /* Add char 528 */ 529 buf->buf[buf->len++] = c; 530 buf->buf[buf->len] = '\0'; 531 532 return ret_ok; 533 } 534 535 511 536 ret_t 512 537 cherokee_buffer_add_char_n (cherokee_buffer_t *buf, char c, int num) … … 530 555 return ret_ok; 531 556 } 532 533 557 534 558 … … 820 844 */ 821 845 ret = cherokee_buffer_ensure_size (buf, buf->len + info.st_size + 1); 822 if (unlikely (ret != ret_ok))846 if (unlikely (ret != ret_ok)) 823 847 return ret; 824 848 … … 1084 1108 */ 1085 1109 ret = cherokee_buffer_new (maybe_new); 1086 if (unlikely (ret != ret_ok))1110 if (unlikely (ret != ret_ok)) 1087 1111 return ret; 1088 1112 1089 1113 ret = cherokee_buffer_ensure_size (*maybe_new, buf->len + extra + 1); 1090 if (unlikely (ret != ret_ok))1114 if (unlikely (ret != ret_ok)) 1091 1115 return ret; 1092 1116 1093 1117 ret = cherokee_buffer_add_buffer (*maybe_new, buf); 1094 if (unlikely (ret != ret_ok))1118 if (unlikely (ret != ret_ok)) 1095 1119 return ret; 1096 1120 … … 1299 1323 cherokee_buffer_ensure_size (buf, 34); 1300 1324 1301 for (i =0; i<16; i++) {1325 for (i = 0; i < 16; ++i) { 1302 1326 int tmp; 1303 1327 … … 1384 1408 return ret_ok; 1385 1409 } 1386 #endif 1410 #endif /* ! CHEROKEE_EMBEDDED */ 1387 1411 1388 1412 … … 1469 1493 1470 1494 ret = cherokee_buffer_add_str (buf, "0x"); 1471 if (unlikely (ret < ret_ok))1495 if (unlikely (ret < ret_ok)) 1472 1496 return ret_ok; 1473 1497 1474 1498 ret = cherokee_buffer_add_ulong16(buf, (culong_t) size); 1475 if (unlikely (ret < ret_ok))1499 if (unlikely (ret < ret_ok)) 1476 1500 return ret_ok; 1477 1501 1478 1502 ret = cherokee_buffer_add_str (buf, CRLF); 1479 if (unlikely (ret < ret_ok))1503 if (unlikely (ret < ret_ok)) 1480 1504 return ret_ok; 1481 1505 cherokee/trunk/cherokee/buffer.h
r597 r602 73 73 ret_t cherokee_buffer_add_va_fixed (cherokee_buffer_t *buf, char *format, ...); 74 74 ret_t cherokee_buffer_add_va_list (cherokee_buffer_t *buf, char *format, va_list args); 75 ret_t cherokee_buffer_add_char (cherokee_buffer_t *buf, char c); 75 76 ret_t cherokee_buffer_add_char_n (cherokee_buffer_t *buf, char c, int n); 76 77 ret_t cherokee_buffer_add_buffer (cherokee_buffer_t *buf, cherokee_buffer_t *buf2); cherokee/trunk/cherokee/connection.c
r597 r602 254 254 } 255 255 256 if (conn->polling_fd != -1) {257 close (conn->polling_fd);258 conn->polling_fd = -1;259 }256 if (conn->polling_fd != -1) { 257 close (conn->polling_fd); 258 conn->polling_fd = -1; 259 } 260 260 261 261 cherokee_post_mrproper (&conn->post); … … 428 428 */ 429 429 if (conn->auth_type & http_auth_digest) { 430 cherokee_buffer_t new_nonce = CHEROKEE_BUF_INIT; 430 cherokee_thread_t *thread = CONN_THREAD(conn); 431 cherokee_buffer_t *new_nonce = THREAD_TMP_BUF1(thread); 431 432 432 433 cherokee_buffer_ensure_addlen (buffer, … … 441 442 /* Nonce 442 443 */ 443 cherokee_nonce_table_generate (CONN_SRV(conn)->nonces, conn, &new_nonce);444 cherokee_nonce_table_generate (CONN_SRV(conn)->nonces, conn, new_nonce); 444 445 /* "nonce=\"%s\", " 445 446 */ 446 447 cherokee_buffer_add_str (buffer, "nonce=\""); 447 cherokee_buffer_add_buffer (buffer, &new_nonce);448 cherokee_buffer_add_buffer (buffer, new_nonce); 448 449 cherokee_buffer_add_str (buffer, "\", "); 449 450 … … 452 453 */ 453 454 cherokee_buffer_add_str (buffer, "qop=\"auth\", algorithm=\"MD5\""CRLF); 454 455 cherokee_buffer_mrproper (&new_nonce);456 455 } 457 456 } … … 494 493 495 494 } else { 496 cherokee_buffer_add_str (buffer, "Connection: Close"CRLF);495 cherokee_buffer_add_str (buffer, "Connection: close"CRLF); 497 496 } 498 497 … … 1217 1216 */ 1218 1217 cherokee_buffer_add (&conn->local_directory, pwd.pw_dir, strlen(pwd.pw_dir)); 1219 cherokee_buffer_add_ str (&conn->local_directory, "/");1218 cherokee_buffer_add_char (&conn->local_directory, '/'); 1220 1219 cherokee_buffer_add_buffer (&conn->local_directory, &vsrv->userdir); 1221 1220 … … 1344 1343 */ 1345 1344 cherokee_buffer_add_buffer (&conn->redirect, &conn->request); 1346 cherokee_buffer_add_ str (&conn->redirect, "/");1345 cherokee_buffer_add_char (&conn->redirect, '/'); 1347 1346 1348 1347 conn->error_code = http_moved_permanently; … … 1797 1796 cuint_t ptr_len; 1798 1797 1799 /* Look for "Connection: Keep-Alive / Close"1798 /* Look for "Connection: Keep-Alive / close" 1800 1799 */ 1801 1800 ret = cherokee_header_get_known (&conn->header, header_connection, &ptr, &ptr_len); 1802 if (ret == ret_ok) 1803 { 1801 if (ret == ret_ok) { 1802 1804 1803 if (strncasecmp (ptr, "close", 5) == 0) { 1805 1804 conn->keepalive = 0; cherokee/trunk/cherokee/nonce.c
r597 r602 94 94 cherokee_nonce_table_generate (cherokee_nonce_table_t *nonces, cherokee_connection_t *conn, cherokee_buffer_t *nonce) 95 95 { 96 cherokee_buffer_t crc = CHEROKEE_BUF_INIT;97 98 96 /* Generate nonce string 99 97 */ 100 cherokee_buffer_add_va (&crc, "%x", POINTER_TO_INT(conn)); 101 cherokee_buffer_add_va (nonce, "%x%x%s", CONN_SRV(conn)->bogo_now, rand(), crc.buf); 98 cherokee_buffer_add_ullong16(nonce, (cullong_t) CONN_SRV(conn)->bogo_now); 99 cherokee_buffer_add_ulong16 (nonce, (culong_t) rand()); 100 cherokee_buffer_add_ulong16 (nonce, (culong_t) POINTER_TO_INT(conn)); 101 102 /* Compute MD5 and overwrite buffer content without reallocating it ! 103 */ 102 104 cherokee_buffer_encode_md5_digest (nonce); 103 105 … … 108 110 CHEROKEE_MUTEX_UNLOCK (&nonces->access); 109 111 110 /* Clean up112 /* Return 111 113 */ 112 cherokee_buffer_mrproper (&crc);113 114 return ret_ok; 114 115 } cherokee/trunk/cherokee/request.c
r597 r602 81 81 cherokee_url_t *url = REQUEST_URL(request); 82 82 83 /* 100 bytes is enoughtfor a small header83 /* 200 bytes should be enough for a small header 84 84 */ 85 cherokee_buffer_ensure_size (buf, 100);85 cherokee_buffer_ensure_size (buf, 200); 86 86 87 87 /* Add main request line: … … 90 90 switch (request->method) { 91 91 case http_get: 92 cherokee_buffer_add (buf, "GET ", 4);92 cherokee_buffer_add_str (buf, "GET "); 93 93 break; 94 94 case http_post: 95 cherokee_buffer_add (buf, "POST ", 5);95 cherokee_buffer_add_str (buf, "POST "); 96 96 break; 97 97 case http_head: 98 cherokee_buffer_add (buf, "HEAD ", 5);98 cherokee_buffer_add_str (buf, "HEAD "); 99 99 break; 100 100 case http_put: 101 cherokee_buffer_add (buf, "PUT ", 4);101 cherokee_buffer_add_str (buf, "PUT "); 102 102 break; 103 103 default: … … 124 124 */ 125 125 if (REQUEST_VERSION(request) == http_version_11) { 126 cherokee_buffer_add (buf, "Host: ", 6);126 cherokee_buffer_add_str (buf, "Host: "); 127 127 cherokee_buffer_add_buffer (buf, URL_HOST(url)); 128 cherokee_buffer_add_str (buf, CRLF);128 cherokee_buffer_add_str (buf, CRLF); 129 129 } 130 130 … … 132 132 */ 133 133 if (request->post_len != 0) { 134 135 cherokee_buffer_add_va (buf, "Content-Length: "FMT_OFFSET CRLF, request->post_len); 134 /* "Content-Length: " FMT_OFFSET CRLF, request->post_len; 135 */ 136 cherokee_buffer_add_str (buf, "Content-Length: "); 137 cherokee_buffer_add_ullong10(buf, (cullong_t) request->post_len); 138 cherokee_buffer_add_str (buf, CRLF); 136 139 } 137 140 … … 139 142 */ 140 143 if (REQUEST_KEEPALIVE(request)) { 141 cherokee_buffer_add_str (buf, "Connection: Keep- alive"CRLF);144 cherokee_buffer_add_str (buf, "Connection: Keep-Alive"CRLF); 142 145 } else { 143 cherokee_buffer_add_str (buf, "Connection: Close"CRLF);146 cherokee_buffer_add_str (buf, "Connection: close"CRLF); 144 147 } 145 148 … … 147 150 */ 148 151 if (!cherokee_buffer_is_empty(&url->user) || 149 !cherokee_buffer_is_empty(&url->passwd)) 150 { 152 !cherokee_buffer_is_empty(&url->passwd)) { 153 151 154 cherokee_buffer_t tmp = CHEROKEE_BUF_INIT; 152 155 … … 175 178 cherokee_request_header_add_header (cherokee_request_header_t *request, char *ptr, cuint_t len) 176 179 { 177 cherokee_buffer_ensure_ size (&request->extra_headers, request->extra_headers.len + len + 2);180 cherokee_buffer_ensure_addlen (&request->extra_headers, len + CSZLEN(CRLF)); 178 181 cherokee_buffer_add (&request->extra_headers, ptr, len); 179 cherokee_buffer_add (&request->extra_headers, CRLF, 2);182 cherokee_buffer_add_str (&request->extra_headers, CRLF); 180 183 181 184 return ret_ok;