| 320 | | |
|---|
| 321 | | static int encode_version(const char *s) { |
|---|
| 322 | | unsigned int v1 = 0; |
|---|
| 323 | | unsigned int v2 = 0; |
|---|
| 324 | | unsigned int v3 = 0; |
|---|
| 325 | | unsigned int c; |
|---|
| 326 | | char m = '.'; |
|---|
| 327 | | sscanf(s, "%u.%u%c%u",&v1,&v2,&m,&v3); |
|---|
| 328 | | switch (m) { |
|---|
| 329 | | case 'a': c = 0; break; |
|---|
| 330 | | case 'b': c = 1; break; |
|---|
| 331 | | case '.': c = 2; break; |
|---|
| 332 | | case 's': c = 15; break; |
|---|
| 333 | | default: c = 2; |
|---|
| 334 | | } |
|---|
| 335 | | return ((v1 & 0xf) << 20) | |
|---|
| 336 | | ((v2 & 0xff) << 12) | |
|---|
| 337 | | ((c & 0xf) << 8) | |
|---|
| 338 | | (v3 & 0xff); |
|---|
| 339 | | } |
|---|
| 340 | | |
|---|
| 341 | | /* This function isn't used. So disable it for now |
|---|
| 342 | | static void decode_version(char *version, int v) { |
|---|
| 343 | | int t = (v & 0x000f00) >> 8; |
|---|
| 344 | | char c; |
|---|
| 345 | | switch (t) { |
|---|
| 346 | | case 0: c = 'a'; break; |
|---|
| 347 | | case 1: c = 'b'; break; |
|---|
| 348 | | case 2: c = '.'; break; |
|---|
| 349 | | case 15: c = 's'; break; |
|---|
| 350 | | default: c = '.'; |
|---|
| 351 | | } |
|---|
| 352 | | snprintf(version, 16, "%d.%d%c%d", (v & 0xf00000) >> 20, |
|---|
| 353 | | (v & 0x0ff000) >> 12, |
|---|
| 354 | | c, |
|---|
| 355 | | (v & 0x0000ff)); |
|---|
| 356 | | } |
|---|
| 357 | | */ |
|---|
| | 320 | void encode_version(const char *str, int *version, int *extra) |
|---|
| | 321 | { |
|---|
| | 322 | unsigned int a = 0; |
|---|
| | 323 | unsigned int b = 0; |
|---|
| | 324 | unsigned int c = 0; |
|---|
| | 325 | unsigned int d = 0; |
|---|
| | 326 | size_t len; |
|---|
| | 327 | char s[255]; |
|---|
| | 328 | char buf[255]; |
|---|
| | 329 | |
|---|
| | 330 | len = strlen(str); |
|---|
| | 331 | memcpy(buf, str, (len > 255) ? 255 : len); |
|---|
| | 332 | buf[255] = '\0'; |
|---|
| | 333 | |
|---|
| | 334 | memset(s, 0, 255); |
|---|
| | 335 | sscanf(str, "%u.%u.%u%s", &a, &b, &c, s); |
|---|
| | 336 | |
|---|
| | 337 | if (s[0] == '.') { |
|---|
| | 338 | sscanf(s, ".%u-%s", &d, buf); |
|---|
| | 339 | } else if (s[0] == '-') { |
|---|
| | 340 | memcpy(buf, &s[1], 254); |
|---|
| | 341 | } else { |
|---|
| | 342 | memcpy(buf, s, 255); |
|---|
| | 343 | } |
|---|
| | 344 | |
|---|
| | 345 | *version = ((a & 0xff) << 24) | ((b & 0xff) << 16) | ((c & 0xff) << 8) | (d & 0xff); |
|---|
| | 346 | |
|---|
| | 347 | if (buf[0] == 0) { |
|---|
| | 348 | a = 0; |
|---|
| | 349 | b = 0; |
|---|
| | 350 | } else if (strncasecmp(buf, "rev", 3) == 0) { |
|---|
| | 351 | a = 1; |
|---|
| | 352 | sscanf(buf, "rev%u", &b); |
|---|
| | 353 | } else if (strncasecmp(buf, "rc", 2) == 0) { |
|---|
| | 354 | a = 2; |
|---|
| | 355 | sscanf(buf, "rc%u", &b); |
|---|
| | 356 | } else if (strncasecmp(buf, "beta", 4) == 0) { |
|---|
| | 357 | a = 3; |
|---|
| | 358 | sscanf(buf, "beta%u", &b); |
|---|
| | 359 | } else { |
|---|
| | 360 | a = 0xf; |
|---|
| | 361 | // just encode the first 4 bytes |
|---|
| | 362 | b = ((buf[0] & 0x7f) << 21) | ((buf[1] & 0x7f) << 14) | ((buf[2] & 0x7f) << 7) | (buf[3] & 0x7f); |
|---|
| | 363 | } |
|---|
| | 364 | |
|---|
| | 365 | *extra = ((a & 0xf) << 28) | (0x0fffffff & b); |
|---|
| | 366 | } |
|---|
| | 367 | |
|---|
| | 368 | static void decode_version(int version, int extra, char *str, size_t len) |
|---|
| | 369 | { |
|---|
| | 370 | int number; |
|---|
| | 371 | |
|---|
| | 372 | if ((version & 0xff) == 0) { |
|---|
| | 373 | number = snprintf(str, len, "%u.%u.%u", (version >> 24), ((version >> 16) & 0xff), ((version >> 8) & 0xff)); |
|---|
| | 374 | } else { |
|---|
| | 375 | number = snprintf(str, len, "%u.%u.%u.%u", (version >> 24), ((version >> 16) & 0xff), ((version >> 8) & 0xff), (version & 0xff)); |
|---|
| | 376 | } |
|---|
| | 377 | |
|---|
| | 378 | if (extra != 0) { |
|---|
| | 379 | unsigned int type = ((extra >> 28) & 0xf); |
|---|
| | 380 | extra = (extra & 0x0fffffff); |
|---|
| | 381 | switch (type) { |
|---|
| | 382 | case 1: |
|---|
| | 383 | snprintf(&str[number], len, "-rev%u", extra); |
|---|
| | 384 | break; |
|---|
| | 385 | case 2: |
|---|
| | 386 | snprintf(&str[number], len, "-rc%u", extra); |
|---|
| | 387 | break; |
|---|
| | 388 | case 3: |
|---|
| | 389 | snprintf(&str[number], len, "-beta%u", extra); |
|---|
| | 390 | break; |
|---|
| | 391 | case 15: |
|---|
| | 392 | if (len >= number + 5) { |
|---|
| | 393 | str[number] = '-'; |
|---|
| | 394 | str[number + 1] = (extra >> 21) & 0x7f; |
|---|
| | 395 | str[number + 2] = (extra >> 14) & 0x7f; |
|---|
| | 396 | str[number + 3] = (extra >> 7) & 0x7f; |
|---|
| | 397 | str[number + 4] = extra & 0x7f; |
|---|
| | 398 | str[number + 5] = '\0'; |
|---|
| | 399 | } |
|---|
| | 400 | break; |
|---|
| | 401 | default: |
|---|
| | 402 | break; |
|---|
| | 403 | } |
|---|
| | 404 | } |
|---|
| | 405 | } |
|---|
| | 618 | /* A function to check if the header of a cache file valid is. |
|---|
| | 619 | */ |
|---|
| | 620 | inline int check_header(ea_file_header *hdr) |
|---|
| | 621 | { |
|---|
| | 622 | #ifdef DEBUG |
|---|
| | 623 | char current[255]; |
|---|
| | 624 | char cache[255]; |
|---|
| | 625 | #endif |
|---|
| | 626 | |
|---|
| | 627 | if (strncmp(hdr->magic, EA_MAGIC, 8) != 0) { |
|---|
| | 628 | #ifdef DEBUG |
|---|
| | 629 | ea_debug_printf(EA_DEBUG, "Magic header mismatch."); |
|---|
| | 630 | #endif |
|---|
| | 631 | return 0; |
|---|
| | 632 | } |
|---|
| | 633 | if (hdr->eaccelerator_version[0] != binary_eaccelerator_version[0] |
|---|
| | 634 | || hdr->eaccelerator_version[1] != binary_eaccelerator_version[1]) { |
|---|
| | 635 | #ifdef DEBUG |
|---|
| | 636 | decode_version(hdr->eaccelerator_version[0], hdr->eaccelerator_version[1], cache, 255); |
|---|
| | 637 | decode_version(binary_eaccelerator_version[0], binary_eaccelerator_version[1], current, 255); |
|---|
| | 638 | ea_debug_printf(EA_DEBUG, "eAccelerator version mismatch, cache file %s and current version %s\n", cache, current); |
|---|
| | 639 | #endif |
|---|
| | 640 | return 0; |
|---|
| | 641 | } |
|---|
| | 642 | if (hdr->zend_version[0] != binary_zend_version[0] |
|---|
| | 643 | || hdr->zend_version[1] != binary_zend_version[1]) { |
|---|
| | 644 | #ifdef DEBUG |
|---|
| | 645 | decode_version(hdr->zend_version[0], hdr->zend_version[1], cache, 255); |
|---|
| | 646 | decode_version(binary_zend_version[0], binary_zend_version[1], current, 255); |
|---|
| | 647 | ea_debug_printf(EA_DEBUG, "Zend version mismatch, cache file %s and current version %s\n", cache, current); |
|---|
| | 648 | #endif |
|---|
| | 649 | return 0; |
|---|
| | 650 | } |
|---|
| | 651 | if (hdr->php_version[0] != binary_php_version[0] |
|---|
| | 652 | || hdr->php_version[1] != binary_php_version[1]) { |
|---|
| | 653 | #ifdef DEBUG |
|---|
| | 654 | decode_version(hdr->php_version[0], hdr->php_version[1], cache, 255); |
|---|
| | 655 | decode_version(binary_php_version[0], binary_php_version[1], current, 255); |
|---|
| | 656 | ea_debug_printf(EA_DEBUG, "PHP version mismatch, cache file %s and current version %s\n", cache, current); |
|---|
| | 657 | #endif |
|---|
| | 658 | return 0; |
|---|
| | 659 | } |
|---|
| | 660 | return 1; |
|---|
| | 661 | } |
|---|
| | 662 | |
|---|
| | 663 | /* A function to create the header for a cache file. |
|---|
| | 664 | */ |
|---|
| | 665 | inline void init_header(ea_file_header *hdr) |
|---|
| | 666 | { |
|---|
| | 667 | strncpy(hdr->magic, EA_MAGIC, 8); |
|---|
| | 668 | hdr->eaccelerator_version[0] = binary_eaccelerator_version[0]; |
|---|
| | 669 | hdr->eaccelerator_version[1] = binary_eaccelerator_version[1]; |
|---|
| | 670 | hdr->zend_version[0] = binary_zend_version[0]; |
|---|
| | 671 | hdr->zend_version[1] = binary_zend_version[1]; |
|---|
| | 672 | hdr->php_version[0] = binary_php_version[0]; |
|---|
| | 673 | hdr->php_version[1] = binary_php_version[1]; |
|---|
| | 674 | } |
|---|