Changeset 228
- Timestamp:
- 07/19/06 11:13:56 (2 years ago)
- Files:
-
- eaccelerator/trunk/ChangeLog (modified) (1 diff)
- eaccelerator/trunk/content.c (modified) (10 diffs)
- eaccelerator/trunk/ea_dasm.c (modified) (4 diffs)
- eaccelerator/trunk/ea_restore.c (modified) (6 diffs)
- eaccelerator/trunk/ea_store.c (modified) (4 diffs)
- eaccelerator/trunk/eaccelerator.c (modified) (1 diff)
- eaccelerator/trunk/opcodes.c (modified) (1 diff)
- eaccelerator/trunk/session.c (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
eaccelerator/trunk/ChangeLog
r227 r228 1 2006-07-19 Bart Vanbrabant <bart.vanbrabant at zoeloelip.be> 2 3 * Use some more zval macro's to cleanup things a bit 4 1 5 2006-07-02 Bart Vanbrabant <bart.vanbrabant at zoeloelip.be> 2 6 eaccelerator/trunk/content.c
r201 r228 138 138 sapi_add_header("Status: 304 Not Modified", sizeof("Status: 304 Not Modified") - 1, 1) == SUCCESS) { 139 139 zval_dtor(return_value); 140 return_value->value.str.val= empty_string;141 return_value->value.str.len= 0;140 Z_STRVAL_P(return_value) = empty_string; 141 Z_STRLEN_P(return_value) = 0; 142 142 /*fprintf(stderr,"\nnot-modified\n");*/ 143 143 return 1; … … 281 281 gzstring.type == IS_STRING) { 282 282 if (gzip) { 283 char* ret = emalloc( gzstring.value.str.len+13);283 char* ret = emalloc(Z_STRLEN(gzstring) + 13); 284 284 unsigned long crc32 = eaccelerator_crc32(Z_STRVAL_P(return_value),Z_STRLEN_P(return_value)); 285 285 ret[0] = '\x1f'; … … 293 293 ret[8] = '\x00'; 294 294 ret[9] = '\x03'; 295 memcpy(ret +10,gzstring.value.str.val+2,gzstring.value.str.len-6);296 ret[ gzstring.value.str.len+4] = (char)(crc32 & 0xff);297 ret[ gzstring.value.str.len+5] = (char)((crc32 >> 8) & 0xff);298 ret[ gzstring.value.str.len+6] = (char)((crc32 >> 16) & 0xff);299 ret[ gzstring.value.str.len+7] = (char)((crc32 >> 24) & 0xff);300 ret[ gzstring.value.str.len+8] = (char)(return_value->value.str.len& 0xff);301 ret[ gzstring.value.str.len+9] = (char)((return_value->value.str.len>> 8) & 0xff);302 ret[ gzstring.value.str.len+10] = (char)((return_value->value.str.len>> 16) & 0xff);303 ret[ gzstring.value.str.len+11] = (char)((return_value->value.str.len>> 24) & 0xff);304 ret[ gzstring.value.str.len+12] = '\x00';305 STR_FREE( gzstring.value.str.val);306 gzstring.value.str.val= ret;307 gzstring.value.str.len+= 12;295 memcpy(ret + 10, Z_STRVAL(gzstring) + 2, Z_STRLEN(gzstring) - 6); 296 ret[Z_STRLEN(gzstring)+4] = (char)(crc32 & 0xff); 297 ret[Z_STRLEN(gzstring)+5] = (char)((crc32 >> 8) & 0xff); 298 ret[Z_STRLEN(gzstring)+6] = (char)((crc32 >> 16) & 0xff); 299 ret[Z_STRLEN(gzstring)+7] = (char)((crc32 >> 24) & 0xff); 300 ret[Z_STRLEN(gzstring)+8] = (char)(Z_STRLEN_P(return_value) & 0xff); 301 ret[Z_STRLEN(gzstring)+9] = (char)((Z_STRLEN_P(return_value) >> 8) & 0xff); 302 ret[Z_STRLEN(gzstring)+10] = (char)((Z_STRLEN_P(return_value) >> 16) & 0xff); 303 ret[Z_STRLEN(gzstring)+11] = (char)((Z_STRLEN_P(return_value) >> 24) & 0xff); 304 ret[Z_STRLEN(gzstring)+12] = '\x00'; 305 STR_FREE(Z_STRVAL(gzstring)); 306 Z_STRVAL(gzstring) = ret; 307 Z_STRLEN(gzstring) += 12; 308 308 } 309 309 eaccelerator_put_page(zkey, zkey_len, &gzstring, ttl TSRMLS_CC); … … 346 346 } 347 347 memcpy(return_value, content, sizeof(zval)); 348 s = key = return_value->value.str.val;348 s = key = Z_STRVAL_P(return_value); 349 349 if ((status & PHP_OUTPUT_HANDLER_START) != 0) { 350 350 while (*s) {++s;} 351 351 ttl = atoi(key); 352 352 s = key = s+1; 353 if (s - return_value->value.str.val > return_value->value.str.len) {353 if (s - Z_STRVAL_P(return_value) > Z_STRLEN_P(return_value)) { 354 354 zval_copy_ctor(return_value); 355 355 eaccelerator_destroy_headers(TSRMLS_C); … … 359 359 key_len = atoi(key); 360 360 s = key = s+1; 361 if (s - return_value->value.str.val > return_value->value.str.len) {361 if (s - Z_STRVAL_P(return_value) > Z_STRLEN_P(return_value)) { 362 362 zval_copy_ctor(return_value); 363 363 eaccelerator_destroy_headers(TSRMLS_C); … … 366 366 while (*s) {++s;} 367 367 ++s; 368 if (s - return_value->value.str.val > return_value->value.str.len) {368 if (s - Z_STRVAL_P(return_value) > Z_STRLEN_P(return_value)) { 369 369 zval_copy_ctor(return_value); 370 370 eaccelerator_destroy_headers(TSRMLS_C); … … 372 372 } 373 373 } 374 return_value->value.str.len -= (s-return_value->value.str.val);375 return_value->value.str.val= s;374 Z_STRLEN_P(return_value) -= (s-Z_STRVAL_P(return_value)); 375 Z_STRVAL_P(return_value) = s; 376 376 zval_copy_ctor(return_value); 377 377 if ((status & PHP_OUTPUT_HANDLER_START) != 0 && … … 438 438 sapi_add_header(enc, strlen(enc), 1) == SUCCESS && 439 439 sapi_add_header("Vary: Accept-Encoding", sizeof("Vary: Accept-Encoding") - 1, 1) == SUCCESS) { 440 ZEND_WRITE( return_value->value.str.val, return_value->value.str.len);440 ZEND_WRITE(Z_STRVAL_P(return_value), Z_STRLEN_P(return_value)); 441 441 } 442 442 efree(zkey); … … 454 454 eaccelerator_compress(key, key_len, return_value, ttl TSRMLS_CC); 455 455 } 456 ZEND_WRITE( return_value->value.str.val, return_value->value.str.len);456 ZEND_WRITE(Z_STRVAL_P(return_value), Z_STRLEN_P(return_value)); 457 457 zend_bailout(); 458 458 RETURN_TRUE; … … 549 549 return_value->type == IS_STRING) { 550 550 /* Output is cached. Print it. */ 551 ZEND_WRITE( return_value->value.str.val, return_value->value.str.len);551 ZEND_WRITE(Z_STRVAL_P(return_value), Z_STRLEN_P(return_value)); 552 552 zval_dtor(return_value); 553 553 RETURN_TRUE; eaccelerator/trunk/ea_dasm.c
r208 r228 126 126 size_t size; 127 127 128 switch ( v->type& ~IS_CONSTANT_INDEX) {128 switch (Z_TYPE_P(v) & ~IS_CONSTANT_INDEX) { 129 129 case IS_NULL: 130 130 str = emalloc(sizeof("null")); … … 132 132 break; 133 133 case IS_LONG: 134 snprintf(buf, sizeof(buf), "long(%ld)", v->value.lval);134 snprintf(buf, sizeof(buf), "long(%ld)", Z_LVAL_P(v)); 135 135 str = emalloc(strlen(buf) + 1); 136 136 strcpy(str, buf); 137 137 break; 138 138 case IS_DOUBLE: 139 snprintf(buf, sizeof(buf), "double(%e)", v->value.dval);139 snprintf(buf, sizeof(buf), "double(%e)", Z_DVAL_P(v)); 140 140 str = emalloc(strlen(buf) + 1); 141 141 strcpy(str, buf); 142 142 break; 143 143 case IS_STRING: 144 size = v->value.str.len+ 1 + sizeof("string('')");144 size = Z_STRLEN_P(v) + 1 + sizeof("string('')"); 145 145 str = emalloc(size); 146 snprintf(str, size, "string('%s')", v->value.str.val);146 snprintf(str, size, "string('%s')", Z_STRVAL_P(v)); 147 147 break; 148 148 case IS_BOOL: … … 168 168 break; 169 169 case IS_CONSTANT: 170 size = v->value.str.len+ 1 + sizeof("constant('')");170 size = Z_STRLEN(v) + 1 + sizeof("constant('')"); 171 171 str = emalloc(size); 172 snprintf(str, size, "constant('%s')", v->value.str.val);172 snprintf(str, size, "constant('%s')", Z_STRVAL_P(v)); 173 173 break; 174 174 case IS_CONSTANT_ARRAY: … … 177 177 break; 178 178 default: 179 snprintf(buf, sizeof(buf), "unknown(type=%d)", v->type);179 snprintf(buf, sizeof(buf), "unknown(type=%d)", Z_TYPE_P(v)); 180 180 str = emalloc(strlen(buf) + 1); 181 181 strcpy(str, buf); eaccelerator/trunk/ea_restore.c
r212 r228 142 142 void fixup_zval(zval * zv TSRMLS_DC) 143 143 { 144 switch ( zv->type& ~IS_CONSTANT_INDEX) {144 switch (Z_TYPE_P(zv) & ~IS_CONSTANT_INDEX) { 145 145 case IS_CONSTANT: /* fallthrough */ 146 146 case IS_STRING: 147 if ( zv->value.str.val == NULL || zv->value.str.len== 0) {148 zv->value.str.val= empty_string;149 zv->value.str.len= 0;147 if (Z_STRVAL_P(zv) == NULL || Z_STRLEN_P(zv) == 0) { 148 Z_STRVAL_P(zv) = empty_string; 149 Z_STRLEN_P(zv) = 0; 150 150 } else { 151 FIXUP( zv->value.str.val);151 FIXUP(Z_STRVAL_P(zv)); 152 152 } 153 153 break; 154 154 case IS_ARRAY: /* fallthrough */ 155 155 case IS_CONSTANT_ARRAY: 156 if ( zv->value.ht == NULL || zv->value.ht== &EG(symbol_table)) {156 if (Z_ARRVAL_P(zv) == NULL || Z_ARRVAL_P(zv) == &EG(symbol_table)) { 157 157 } else { 158 FIXUP( zv->value.ht);159 fixup_zval_hash( zv->value.ht);158 FIXUP(Z_ARRVAL_P(zv)); 159 fixup_zval_hash(Z_ARRVAL_P(zv)); 160 160 } 161 161 break; … … 165 165 } 166 166 #ifndef ZEND_ENGINE_2 167 FIXUP( zv->value.obj.ce);168 if ( zv->value.obj.properties != NULL) {169 FIXUP( zv->value.obj.properties);170 fixup_zval_hash( zv->value.obj.properties);167 FIXUP(Z_OBJVAL_P(zv).ce); 168 if (Z_OBJVAL_P(zv).properties != NULL) { 169 FIXUP(Z_OBJVAL_P(zv).properties); 170 fixup_zval_hash(Z_OBJVAL_P(zv).properties); 171 171 } 172 172 #endif … … 379 379 case IS_CONSTANT: 380 380 case IS_STRING: 381 if ( zv->value.str.val == NULL || zv->value.str.val == "" || zv->value.str.len== 0) {382 zv->value.str.len= 0;383 zv->value.str.val= empty_string;381 if (Z_STRVAL_P(zv) == NULL || Z_STRVAL_P(zv) == "" || Z_STRLEN_P(zv) == 0) { 382 Z_STRLEN_P(zv) = 0; 383 Z_STRVAL_P(zv) = empty_string; 384 384 return; 385 385 } else { 386 char *p = emalloc( zv->value.str.len+ 1);387 memcpy(p, zv->value.str.val, zv->value.str.len+ 1);388 zv->value.str.val= p;386 char *p = emalloc(Z_STRLEN_P(zv) + 1); 387 memcpy(p, Z_STRVAL_P(zv), Z_STRLEN_P(zv) + 1); 388 Z_STRVAL_P(zv) = p; 389 389 } 390 390 return; … … 392 392 case IS_ARRAY: 393 393 case IS_CONSTANT_ARRAY: 394 if ( zv->value.ht != NULL && zv->value.ht!= &EG(symbol_table)) {395 zv->value.ht = restore_zval_hash(NULL, zv->value.ht);396 zv->value.ht->pDestructor = ZVAL_PTR_DTOR;394 if (Z_ARRVAL_P(zv) != NULL && Z_ARRVAL_P(zv) != &EG(symbol_table)) { 395 Z_ARRVAL_P(zv) = restore_zval_hash(NULL, Z_ARRVAL_P(zv)); 396 Z_ARRVAL_P(zv)->pDestructor = ZVAL_PTR_DTOR; 397 397 } 398 398 return; … … 402 402 #ifndef ZEND_ENGINE_2 403 403 zend_bool incomplete_class = 0; 404 char *class_name = (char *) zv->value.obj.ce;404 char *class_name = (char *) Z_OBJVAL_P(zv).ce; 405 405 int name_len = 0; 406 406 if (!EAG(compress)) { … … 418 418 } else { 419 419 efree(lowercase_name); 420 zv->value.obj.ce = ce;420 Z_OBJVAL_P(zv).ce = ce; 421 421 incomplete_class = 1; 422 422 } 423 423 } else { 424 zv->value.obj.ce = ce;424 Z_OBJVAL_P(zv).ce = ce; 425 425 } 426 426 } 427 if ( zv->value.obj.properties != NULL) {428 zv->value.obj.properties = restore_zval_hash(NULL, zv->value.obj.properties);429 zv->value.obj.properties->pDestructor = ZVAL_PTR_DTOR;427 if (Z_OBJVAL_P(zv).properties != NULL) { 428 Z_OBJVAL_P(zv).properties = restore_zval_hash(NULL, Z_OBJVAL_P(zv).properties); 429 Z_OBJVAL_P(zv).properties->pDestructor = ZVAL_PTR_DTOR; 430 430 /* Clearing references */ 431 431 { 432 Bucket *p = zv->value.obj.properties->pListHead;432 Bucket *p = Z_OBJVAL_P(zv).properties->pListHead; 433 433 while (p != NULL) { 434 434 ((zval *) (p->pDataPtr))->refcount = 1; eaccelerator/trunk/ea_store.c
r205 r228 114 114 void calc_zval(zval * zv TSRMLS_DC) 115 115 { 116 switch ( zv->type& ~IS_CONSTANT_INDEX) {116 switch (Z_TYPE_P(zv) & ~IS_CONSTANT_INDEX) { 117 117 case IS_CONSTANT: 118 118 case IS_STRING: 119 /* if (zv->value.str.val == NULL || zv->value.str.len == 0) { 120 } else {*/ 121 calc_string(zv->value.str.val, zv->value.str.len + 1 TSRMLS_CC); 122 /* }*/ 119 calc_string(Z_STRVAL_P(zv), Z_STRLEN_P(zv) + 1 TSRMLS_CC); 123 120 break; 124 121 case IS_ARRAY: 125 122 case IS_CONSTANT_ARRAY: 126 if ( zv->value.ht != NULL && zv->value.ht!= &EG(symbol_table)) {123 if (Z_ARRVAL_P(zv) != NULL && Z_ARRVAL_P(zv) != &EG(symbol_table)) { 127 124 EACCELERATOR_ALIGN(EAG(mem)); 128 125 EAG(mem) += sizeof(HashTable); 129 calc_zval_hash( zv->value.ht);126 calc_zval_hash(Z_ARRVAL_P(zv)); 130 127 } 131 128 break; 132 129 case IS_OBJECT: 133 130 #ifndef ZEND_ENGINE_2 134 if ( zv->value.obj.ce != NULL) {135 zend_class_entry *ce = zv->value.obj.ce;131 if (Z_OBJVAL_P(zv).ce != NULL) { 132 zend_class_entry *ce = Z_OBJVAL_P(zv).ce; 136 133 if (!EAG(compress)) { 137 134 DBG(ea_debug_error, ("[%d] EACCELERATOR can't cache objects\n", getpid())); … … 145 142 ce = ce->parent; 146 143 } 147 calc_string( zv->value.obj.ce->name, zv->value.obj.ce->name_length + 1 TSRMLS_CC);148 } 149 if ( zv->value.obj.properties != NULL) {144 calc_string(Z_OBJVAL_P(zv).ce->name, Z_OBJVAL_P(zv).ce->name_length + 1 TSRMLS_CC); 145 } 146 if (Z_OBJVAL_P(zv).properties != NULL) { 150 147 EACCELERATOR_ALIGN(EAG(mem)); 151 148 EAG(mem) += sizeof(HashTable); 152 calc_zval_hash( zv->value.obj.properties);149 calc_zval_hash(Z_OBJVAL_P(zv).properties); 153 150 } 154 151 #endif … … 479 476 void store_zval(zval * zv TSRMLS_DC) 480 477 { 481 switch ( zv->type& ~IS_CONSTANT_INDEX) {478 switch (Z_TYPE_P(zv) & ~IS_CONSTANT_INDEX) { 482 479 case IS_CONSTANT: 483 480 case IS_STRING: 484 zv->value.str.val = store_string(zv->value.str.val, zv->value.str.len+ 1 TSRMLS_CC);481 Z_STRVAL_P(zv) = store_string(Z_STRVAL_P(zv), Z_STRLEN_P(zv) + 1 TSRMLS_CC); 485 482 break; 486 483 case IS_ARRAY: 487 484 case IS_CONSTANT_ARRAY: 488 if ( zv->value.ht != NULL && zv->value.ht!= &EG(symbol_table)) {485 if (Z_ARRVAL_P(zv) != NULL && Z_ARRVAL_P(zv) != &EG(symbol_table)) { 489 486 HashTable *p; 490 487 EACCELERATOR_ALIGN(EAG(mem)); 491 488 p = (HashTable *) EAG(mem); 492 489 EAG(mem) += sizeof(HashTable); 493 store_zval_hash(p, zv->value.ht);494 zv->value.ht= p;490 store_zval_hash(p, Z_ARRVAL_P(zv)); 491 Z_ARRVAL_P(zv) = p; 495 492 } 496 493 break; … … 500 497 } 501 498 #ifndef ZEND_ENGINE_2 502 if ( zv->value.obj.ce != NULL) {503 char *s = store_string( zv->value.obj.ce->name, zv->value.obj.ce->name_length + 1 TSRMLS_CC);504 zend_str_tolower(s, zv->value.obj.ce->name_length);505 zv->value.obj.ce = (zend_class_entry *) s;506 } 507 if ( zv->value.obj.properties != NULL) {499 if (Z_OBJVAL_P(zv).ce != NULL) { 500 char *s = store_string(Z_OBJVAL_P(zv).ce->name, Z_OBJVAL_P(zv).ce->name_length + 1 TSRMLS_CC); 501 zend_str_tolower(s, Z_OBJVAL_P(zv).ce->name_length); 502 Z_OBJVAL_P(zv).ce = (zend_class_entry *) s; 503 } 504 if (Z_OBJVAL_P(zv).properties != NULL) { 508 505 HashTable *p; 509 506 EACCELERATOR_ALIGN(EAG(mem)); 510 507 p = (HashTable *) EAG(mem); 511 508 EAG(mem) += sizeof(HashTable); 512 store_zval_hash(p, zv->value.obj.properties);513 zv->value.obj.properties = p;509 store_zval_hash(p, Z_OBJVAL_P(zv).properties); 510 Z_OBJVAL_P(zv).properties = p; 514 511 } 515 512 #endif eaccelerator/trunk/eaccelerator.c
r224 r228 435 435 ZVAL_STRING(params[0], (char*)key, 0); 436 436 if (call_user_function(CG(function_table), (zval**)NULL, &md5, &retval, 1, params TSRMLS_CC) == SUCCESS && 437 retval.type == IS_STRING && 438 retval.value.str.len == 32) { 437 Z_TYPE(retval) == IS_STRING && Z_STRLEN(retval) == 32) { 439 438 strncpy(s, EAG(cache_dir), MAXPATHLEN-1); 440 439 strlcat(s, prefix, MAXPATHLEN); 441 strlcat(s, retval.value.str.val, MAXPATHLEN);440 strlcat(s, Z_STRVAL(retval), MAXPATHLEN); 442 441 zval_dtor(&retval); 443 442 return 1; eaccelerator/trunk/opcodes.c
r182 r228 294 294 str.is_ref = 1; 295 295 str.refcount = 2; 296 str.value.str.val = "return 1;"; 297 str.value.str.len = 9; 296 297 Z_STRVAL(str) = "return 1;"; 298 Z_STRLEN(str) = 9; 298 299 old = ext->op_array_handler; 299 300 ext->op_array_handler = retrive_opcode_handlers_handler; eaccelerator/trunk/session.c
r182 r228 49 49 50 50 /* set the updated ini value of the cache place */ 51 PHP_INI_MH (eaccelerator_OnUpdateSessionCachePlace)52 { 53 if (strncasecmp ("shm_and_disk", new_value, sizeof ("shm_and_disk")) == 0) {51 PHP_INI_MH(eaccelerator_OnUpdateSessionCachePlace) 52 { 53 if (strncasecmp("shm_and_disk", new_value, sizeof ("shm_and_disk")) == 0) { 54 54 eaccelerator_sessions_cache_place = eaccelerator_shm_and_disk; 55 } else if (strncasecmp ("shm", new_value, sizeof ("shm")) == 0) {55 } else if (strncasecmp("shm", new_value, sizeof ("shm")) == 0) { 56 56 eaccelerator_sessions_cache_place = eaccelerator_shm; 57 } else if (strncasecmp ("shm_only", new_value, sizeof ("shm_only")) == 0) {57 } else if (strncasecmp("shm_only", new_value, sizeof ("shm_only")) == 0) { 58 58 eaccelerator_sessions_cache_place = eaccelerator_shm_only; 59 } else if (strncasecmp ("disk_only", new_value, sizeof ("disk_only")) == 0) {59 } else if (strncasecmp("disk_only", new_value, sizeof ("disk_only")) == 0) { 60 60 eaccelerator_sessions_cache_place = eaccelerator_disk_only; 61 } else if (strncasecmp ("none", new_value, sizeof ("none")) == 0) {61 } else if (strncasecmp("none", new_value, sizeof ("none")) == 0) { 62 62 eaccelerator_sessions_cache_place = eaccelerator_none; 63 63 } … … 66 66 67 67 /* session unlock */ 68 static int do_session_unlock (TSRMLS_D)68 static int do_session_unlock(TSRMLS_D) 69 69 { 70 70 if (EAG (session) != NULL) { 71 eaccelerator_unlock (EAG (session), strlen (EAG(session)) TSRMLS_CC);72 efree (EAG(session));73 EAG (session) = NULL;71 eaccelerator_unlock(EAG(session), strlen(EAG(session)) TSRMLS_CC); 72 efree(EAG(session)); 73 EAG(session) = NULL; 74 74 } 75 75 return 1; … … 77 77 78 78 /* session locking */ 79 static int do_session_lock (const char *sess_name TSRMLS_DC)80 { 81 if (EAG (session) != NULL) {82 if (strcmp (EAG(session), sess_name) == 0) {79 static int do_session_lock(const char *sess_name TSRMLS_DC) 80 { 81 if (EAG(session) != NULL) { 82 if (strcmp(EAG(session), sess_name) == 0) { 83 83 return 1; 84 84 } else { 85 do_session_unlock (TSRMLS_C);85 do_session_unlock(TSRMLS_C); 86 86 } 87 87 } 88 if (eaccelerator_lock (sess_name, strlen(sess_name) TSRMLS_CC)) {89 EAG (session) = estrdup(sess_name);88 if (eaccelerator_lock(sess_name, strlen(sess_name) TSRMLS_CC)) { 89 EAG(session) = estrdup(sess_name); 90 90 return 1; 91 91 } else { … … 99 99 /******************************************************************************/ 100 100 101 PS_OPEN_FUNC (eaccelerator)101 PS_OPEN_FUNC(eaccelerator) 102 102 { 103 103 if (eaccelerator_mm_instance == NULL) { 104 104 return FAILURE; 105 105 } 106 PS_SET_MOD_DATA ((void *) 1);106 PS_SET_MOD_DATA((void *) 1); 107 107 return SUCCESS; 108 108 } 109 109 110 PS_CLOSE_FUNC (eaccelerator)110 PS_CLOSE_FUNC(eaccelerator) 111 111 { 112 112 if (eaccelerator_mm_instance == NULL) { 113 113 return FAILURE; 114 114 } 115 do_session_unlock (TSRMLS_C);115 do_session_unlock(TSRMLS_C); 116 116 return SUCCESS; 117 117 } 118 118 119 PS_READ_FUNC (eaccelerator)119 PS_READ_FUNC(eaccelerator) 120 120 { 121 121 char *skey; … … 123 123 zval ret; 124 124 125 len = sizeof ("sess_") + strlen (key); 126 skey = do_alloca (len + 1); 127 strcpy (skey, "sess_"); 128 strcat (skey, key); 129 do_session_lock (skey TSRMLS_CC); 130 if (eaccelerator_get 131 (skey, len, &ret, eaccelerator_sessions_cache_place TSRMLS_CC) 132 && ret.type == IS_STRING) { 133 *val = estrdup (ret.value.str.val); 134 *vallen = ret.value.str.len; 135 zval_dtor (&ret); 136 } else { 137 *val = emalloc (1); 125 len = sizeof("sess_") + strlen(key); 126 skey = do_alloca(len + 1); 127 strcpy(skey, "sess_"); 128 strcat(skey, key); 129 do_session_lock(skey TSRMLS_CC); 130 if (eaccelerator_get(skey, len, &ret, eaccelerator_sessions_cache_place TSRMLS_CC) 131 && ret.type == IS_STRING) { 132 *val = estrdup(Z_STRVAL(ret)); 133 *vallen = Z_STRLEN(ret); 134 zval_dtor(&ret); 135 } else { 136 *val = emalloc(1); 138 137 (*val)[0] = '\0'; 139 138 *vallen = 0; 140 139 } 141 free_alloca (skey);140 free_alloca(skey); 142 141 return SUCCESS; 143 142 } 144 143 145 PS_WRITE_FUNC (eaccelerator)144 PS_WRITE_FUNC(eaccelerator) 146 145 { 147 146 char *skey; … … 151 150 char *tmp; 152 151 153 len = sizeof ("sess_") + strlen(key);154 skey = do_alloca (len + 1);155 strcpy (skey, "sess_");156 strcat (skey, key);157 if (cfg_get_string ("session.gc_maxlifetime", &tmp) == FAILURE) {152 len = sizeof("sess_") + strlen(key); 153 skey = do_alloca(len + 1); 154 strcpy(skey, "sess_"); 155 strcat(skey, key); 156 if (cfg_get_string("session.gc_maxlifetime", &tmp) == FAILURE) { 158 157 ttl = 1440; 159 158 } else { 160 ttl = atoi (tmp); 161 } 162 sval.type = IS_STRING; 163 sval.value.str.val = (char *) val; 164 sval.value.str.len = vallen; 165 166 do_session_lock (skey TSRMLS_CC); 167 if (eaccelerator_put 168 (skey, len, &sval, ttl, eaccelerator_sessions_cache_place TSRMLS_CC)) { 169 free_alloca (skey); 159 ttl = atoi(tmp); 160 } 161 Z_TYPE(sval) = IS_STRING; 162 Z_STRVAL(sval) = (char *) val; 163 Z_STRLEN(sval) = vallen; 164 165 do_session_lock(skey TSRMLS_CC); 166 if (eaccelerator_put(skey, len, &sval, ttl, eaccelerator_sessions_cache_place TSRMLS_CC)) { 167 free_alloca(skey); 170 168 return SUCCESS; 171 169 } else { 172 free_alloca (skey);170 free_alloca(skey); 173 171 return FAILURE; 174 172 } 175 173 } 176 174 177 PS_DESTROY_FUNC (eaccelerator)175 PS_DESTROY_FUNC(eaccelerator) 178 176 { 179 177 char *skey; 180 178 int len; 181 179 182 len = sizeof ("sess_") + strlen (key); 183 skey = do_alloca (len + 1); 184 strcpy (skey, "sess_"); 185 strcat (skey, key); 186 if (eaccelerator_rm 187 (skey, len, eaccelerator_sessions_cache_place TSRMLS_CC)) { 188 free_alloca (skey); 180 len = sizeof("sess_") + strlen(key); 181 skey = do_alloca(len + 1); 182 strcpy(skey, "sess_"); 183 strcat(skey, key); 184 if (eaccelerator_rm(skey, len, eaccelerator_sessions_cache_place TSRMLS_CC)) { 185 free_alloca(skey); 189 186 return SUCCESS; 190 187 } else { 191 free_alloca (skey);188 free_alloca(skey); 192 189 return FAILURE; 193 190 } 194 191 } 195 192 196 PS_GC_FUNC (eaccelerator)193 PS_GC_FUNC(eaccelerator) 197 194 { 198 195 if (eaccelerator_mm_instance == NULL) { 199 196 return FAILURE; 200 197 } 201 eaccelerator_gc (TSRMLS_C);198 eaccelerator_gc(TSRMLS_C); 202 199 return SUCCESS; 203 200 } 204 201 205 202 #ifdef PS_CREATE_SID_ARGS 206 PS_CREATE_SID_FUNC (eaccelerator)203 PS_CREATE_SID_FUNC(eaccelerator) 207 204 { 208 205 static char hexconvtab[] = "0123456789abcdef"; … … 218 215 char *entropy_file; 219 216 220 if (cfg_get_string ("session.entropy_length", &entropy_file) == FAILURE) {217 if (cfg_get_string("session.entropy_length", &entropy_file) == FAILURE) { 221 218 entropy_length = 0; 222 219 } else { 223 entropy_length = atoi (entropy_file);224 } 225 if (cfg_get_string ("session.entropy_file", &entropy_file) == FAILURE) {220 entropy_length = atoi(entropy_file); 221 } 222 if (cfg_get_string("session.entropy_file", &entropy_file) == FAILURE) { 226 223 entropy_file = empty_string; 227 224 } 228 225 229 gettimeofday (&tv, NULL); 230 PHP_MD5Init (&context); 231 232 sprintf (buf, "%ld%ld%0.8f", tv.tv_sec, tv.tv_usec, 233 php_combined_lcg (TSRMLS_C) * 10); 234 PHP_MD5Update (&context, (unsigned char *) buf, strlen (buf)); 226 gettimeofday(&tv, NULL); 227 PHP_MD5Init(&context); 228 229 sprintf(buf, "%ld%ld%0.8f", tv.tv_sec, tv.tv_usec, php_combined_lcg (TSRMLS_C) * 10); 230 PHP_MD5Update(&context, (unsigned char *)buf, strlen(buf)); 235 231 236 232 if (entropy_length > 0) { 237 233 int fd; 238 234 239 fd = VCWD_OPEN (entropy_file, O_RDONLY);235 fd = VCWD_OPEN(entropy_file, O_RDONLY); 240 236 if (fd >= 0) { 241 237 unsigned char buf[2048]; … … 244 240 245 241 while (to_read > 0) { 246 n = read (fd, buf, MIN (to_read, sizeof(buf)));242 n = read(fd, buf, MIN (to_read, sizeof(buf))); 247 243 if (n <= 0) 248 244 break; 249 PHP_MD5Update (&context, buf, n);245 PHP_MD5Update(&context, buf, n); 250 246 to_read -= n; 251 247 } 252 close (fd);248 close(fd); 253 249 } 254 250 } 255 251 256 PHP_MD5Final (digest, &context);252 PHP_MD5Final(digest, &context); 257 253 258 254 for (i = 0; i < 16; i++) { … … 275 271 /******************************************************************************/ 276 272 277 PHP_FUNCTION (_eaccelerator_session_open)273 PHP_FUNCTION(_eaccelerator_session_open) 278 274 { 279 275 if (eaccelerator_mm_instance == NULL) { … … 283 279 } 284 280 285 PHP_FUNCTION (_eaccelerator_session_close)286 { 287 if (eaccelerator_mm_instance == NULL) { 288 RETURN_FALSE; 289 } 290 do_session_unlock (TSRMLS_C);281 PHP_FUNCTION(_eaccelerator_session_close) 282 { 283 if (eaccelerator_mm_instance == NULL) { 284 RETURN_FALSE; 285 } 286 do_session_unlock(TSRMLS_C); 291 287 RETURN_TRUE; 292 288 } 293 289 294 PHP_FUNCTION (_eaccelerator_session_read)290 PHP_FUNCTION(_eaccelerator_session_read) 295 291 { 296 292 zval **arg_key; … … 298 294 int len; 299 295 300 if (ZEND_NUM_ARGS () != 1 301 || zend_get_parameters_ex (1, &arg_key) == FAILURE) { 296 if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg_key) == FAILURE) { 302 297 WRONG_PARAM_COUNT; 303 298 } 304 len = sizeof ("sess_") + (*arg_key)->value.str.len; 305 key = do_alloca (len + 1); 306 strcpy (key, "sess_"); 307 strcat (key, (*arg_key)->value.str.val); 308 do_session_lock (key TSRMLS_CC); 309 if (eaccelerator_get 310 (key, len, return_value, eaccelerator_sessions_cache_place TSRMLS_CC)) { 311 free_alloca (key); 299 len = sizeof("sess_") + Z_STRLEN_PP(arg_key); 300 key = do_alloca(len + 1); 301 strcpy(key, "sess_"); 302 strcat(key, Z_STRVAL_PP(arg_key)); 303 do_session_lock(key TSRMLS_CC); 304 if (eaccelerator_get(key, len, return_value, eaccelerator_sessions_cache_place TSRMLS_CC)) { 305 free_alloca(key); 312 306 return; 313 307 } else { 314 free_alloca (key);315 RETURN_EMPTY_STRIN G();316 } 317 } 318 319 PHP_FUNCTION (_eaccelerator_session_write)308 free_alloca(key); 309 RETURN_EMPTY_STRIN (); 310 } 311 } 312 313 PHP_FUNCTION(_eaccelerator_session_write) 320 314 { 321 315 zval **arg_key, **arg_val; … … 324 318 time_t ttl; 325 319 326 if (ZEND_NUM_ARGS () != 2 327 || zend_get_parameters_ex (2, &arg_key, &arg_val) == FAILURE) { 320 if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg_key, &arg_val) == FAILURE) { 328 321 WRONG_PARAM_COUNT; 329 322 } 330 len = sizeof ("sess_") + (*arg_key)->value.str.len;331 key = do_alloca (len + 1);332 strcpy (key, "sess_");333 strcat (key, (*arg_key)->value.str.val);334 ttl = PS (gc_maxlifetime);323 len = sizeof("sess_") + Z_STRLEN_PP(arg_key); 324 key = do_alloca(len + 1); 325 strcpy(key, "sess_"); 326 strcat(key, Z_STRVAL_PP(arg_key)); 327 ttl = PS(gc_maxlifetime); 335 328 if (ttl < 0) 336 329 ttl = 1440; 337 do_session_lock (key TSRMLS_CC); 338 if (eaccelerator_put 339 (key, len, *arg_val, ttl, 340 eaccelerator_sessions_cache_place TSRMLS_CC)) { 341 free_alloca (key); 330 do_session_lock(key TSRMLS_CC); 331 if (eaccelerator_put(key, len, *arg_val, ttl, eaccelerator_sessions_cache_place TSRMLS_CC)) { 332 free_alloca(key); 342 333 RETURN_TRUE; 343 334 } else { 344 free_alloca (key);345 RETURN_FALSE; 346 } 347 } 348 349 PHP_FUNCTIO N(_eaccelerator_session_destroy)335 free_alloca(key); 336 RETURN_FALSE; 337 } 338 } 339 340 PHP_FUNCTIO (_eaccelerator_session_destroy) 350 341 { 351 342 zval **arg_key; … … 353 344 int len; 354 345 355 if (ZEND_NUM_ARGS () != 1 356 || zend_get_parameters_ex (1, &arg_key) == FAILURE) { 346 if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex (1, &arg_key) == FAILURE) { 357 347 WRONG_PARAM_COUNT; 358 348 } 359 len = sizeof ("sess_") + (*arg_key)->value.str.len;360 key = do_alloca (len + 1);361 strcpy (key, "sess_");362 strcat (key, (*arg_key)->value.str.val);363 if (eaccelerator_rm (key, len, eaccelerator_sessions_cache_place TSRMLS_CC)) {364 free_alloca (key);349 len = sizeof("sess_") + Z_STRLEN_PP(arg_key); 350 key = do_alloca(len + 1); 351 strcpy(key, "sess_"); 352 strcat(key, Z_STRVAL_PP(arg_key)); 353 if (eaccelerator_rm(key, len, eaccelerator_sessions_cache_place TSRMLS_CC)) { 354 free_alloca(key); 365 355 RETURN_TRUE; 366 356 } else { 367 free_alloca (key);368 RETURN_FALSE; 369 } 370 } 371 372 PHP_FUNCTION (_eaccelerator_session_gc)373 { 374 if (eaccelerator_mm_instance == NULL) { 375 RETURN_FALSE; 376 } 377 eaccelerator_gc (TSRMLS_C);357 free_alloca(key); 358 RETURN_FALSE; 359 } 360 } 361 362 PHP_FUNCTION(_eaccelerator_session_gc) 363 { 364 if (eaccelerator_mm_instance == NULL) { 365 RETURN_FALSE; 366 } 367 eaccelerator_gc(TSRMLS_C); 378 368 RETURN_TRUE; 379 369 } … … 389 379 390 380 /* is the eA registered as session handler */ 391 int eaccelerator_session_registered ()381 int eaccelerator_session_registered() 392 382 { 393 383 return !(eaccelerator_sessions_cache_place != eaccelerator_none && … … 396 386 397 387 /* register ea as session handler */ 398 void eaccelerator_register_session ()399 { 400 php_session_register_module (&ps_mod_eaccelerator);388 void eaccelerator_register_session() 389 { 390 php_session_register_module(&ps_mod_eaccelerator); 401 391 eaccelerator_sessions_registered = 1; 402 392 } 403 393 404 394 /* register ea as the custom session handler */ 405 int eaccelerator_set_session_handlers (TSRMLS_D)395 int eaccelerator_set_session_handlers(TSRMLS_D) 406 396 { 407 397 zval func; … … 419 409 return 0; 420 410 } 421 ZVAL_STRING (&func, "session_module_name", 0);422 INIT_ZVAL (param);411 ZVAL_STRING(&func, "session_module_name", 0); 412 INIT_ZVAL(param);