Exemplo n.º 1
0
/************************************************************************************
 * getHdrInfo:
 *
 * DESCRIPTION: 
 *  Function to store httpHdrBuffer (pointed by hdrBuf) information into pHdrInfo
 *
 * RETURN:
 *  void
 ************************************************************************************/
static void
getHdrInfo(HdrInfo_T * pHdrInfo, INKMBuffer hdrBuf, INKMLoc hdrLoc)
{
  LOG_SET_FUNCTION_NAME("getHdrInfo");
  INKMLoc urlLoc = NULL;

  const char *sHostName = NULL, *sHttpMethod = NULL, *sHttpHdrReason = NULL;
  int iHttpHdrReasonLength, iHttpMethodLength, iHostLength;

  if ((pHdrInfo->httpType = INKHttpHdrTypeGet(hdrBuf, hdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrTypeGet");
  }
  if ((pHdrInfo->hdrLength = INKHttpHdrLengthGet(hdrBuf, hdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrLengthGet");
  }
  if ((pHdrInfo->httpVersion = INKHttpHdrVersionGet(hdrBuf, hdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrVersionGet");
  }

  if (pHdrInfo->httpType == INK_HTTP_TYPE_REQUEST) {
    if ((sHttpMethod = INKHttpHdrMethodGet(hdrBuf, hdrLoc, &iHttpMethodLength)) == INK_ERROR_PTR) {
      LOG_API_ERROR("INKHttpHdrMethodGet");
    } else {
      pHdrInfo->httpMethod = INKstrndup(sHttpMethod, iHttpMethodLength);
    }

    if ((urlLoc = INKHttpHdrUrlGet(hdrBuf, hdrLoc)) == INK_ERROR_PTR) {
      LOG_API_ERROR("INKHttpHdrUrlGet");
    } else if ((sHostName = INKUrlHostGet(hdrBuf, urlLoc, &iHostLength)) == INK_ERROR_PTR) {
      LOG_API_ERROR("INKUrlHostGet");
    } else {
      pHdrInfo->hostName = INKstrndup(sHostName, iHostLength);
    }

    /* Clean-up */
    STR_RELEASE(hdrBuf, urlLoc, sHostName);
    STR_RELEASE(hdrBuf, urlLoc, sHttpMethod);
    HANDLE_RELEASE(hdrBuf, hdrLoc, urlLoc);

  } else if (pHdrInfo->httpType == INK_HTTP_TYPE_RESPONSE) {
    if ((pHdrInfo->httpStatus = INKHttpHdrStatusGet(hdrBuf, hdrLoc)) == INK_ERROR) {
      LOG_API_ERROR("INKHttpHdrStatusGet");
    }

    if ((sHttpHdrReason = INKHttpHdrReasonGet(hdrBuf, hdrLoc, &iHttpHdrReasonLength)) == INK_ERROR_PTR) {
      LOG_API_ERROR("INKHttpHdrReasonGet");
    } else if (sHttpHdrReason) {
      pHdrInfo->hdrReason = INKstrndup(sHttpHdrReason, iHttpHdrReasonLength);
    }

    /* clean-up */
    STR_RELEASE(hdrBuf, hdrLoc, sHttpHdrReason);
  } else {
    LOG_AUTO_ERROR("getHdrInfo", "httpType unknown");
  }
}
Exemplo n.º 2
0
	ZEND_HASH_FOREACH_STR_KEY_VAL(target_hash, string_key, element) {
		zend_string *str = zval_get_string(element);

		if (str->len == 0) {
			goto next_element;
		}

		if (string_key) {
			if (string_key->len == 0) {
				goto next_element;
			}

			l = string_key->len + str->len + 2;
			memcpy(p, string_key->val, string_key->len);
			strncat(p, "=", 1);
			strncat(p, str->val, str->len);

#ifndef PHP_WIN32
			*ep = p;
			++ep;
#endif
			p += l;
		} else {
			memcpy(p, str->val, str->len);
#ifndef PHP_WIN32
			*ep = p;
			++ep;
#endif
			p += str->len + 1;
		}
next_element:
		STR_RELEASE(str);
	} ZEND_HASH_FOREACH_END();
Exemplo n.º 3
0
/* {{{ _php_array_to_envp */
static php_process_env_t _php_array_to_envp(zval *environment, int is_persistent TSRMLS_DC)
{
	zval *element;
	php_process_env_t env;
	zend_string *string_key;
#ifndef PHP_WIN32
	char **ep;
#endif
	char *p;
	uint cnt, l, sizeenv=0;
	HashTable *target_hash;

	memset(&env, 0, sizeof(env));

	if (!environment) {
		return env;
	}

	cnt = zend_hash_num_elements(Z_ARRVAL_P(environment));

	if (cnt < 1) {
#ifndef PHP_WIN32
		env.envarray = (char **) pecalloc(1, sizeof(char *), is_persistent);
#endif
		env.envp = (char *) pecalloc(4, 1, is_persistent);
		return env;
	}

	target_hash = HASH_OF(environment);
	if (!target_hash) {
		return env;
	}

	/* first, we have to get the size of all the elements in the hash */
	ZEND_HASH_FOREACH_STR_KEY_VAL(target_hash, string_key, element) {
		zend_string *str = zval_get_string(element);
		uint el_len = str->len;
		STR_RELEASE(str);

		if (el_len == 0) {
			continue;
		}

		sizeenv += el_len + 1;

		if (string_key) {
			if (string_key->len == 0) {
				continue;
			}
			sizeenv += string_key->len + 1;
		}
	} ZEND_HASH_FOREACH_END();
Exemplo n.º 4
0
/* {{{ proto Closure Closure::bind(Closure $old, object $to [, mixed $scope = "static" ] )
   Create a closure from another one and bind to another object and scope */
ZEND_METHOD(Closure, bind)
{
	zval *newthis, *zclosure, *scope_arg = NULL;
	zend_closure *closure;
	zend_class_entry *ce;

	if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oo!|z", &zclosure, zend_ce_closure, &newthis, &scope_arg) == FAILURE) {
		RETURN_NULL();
	}

	closure = (zend_closure *)Z_OBJ_P(zclosure);

	if ((newthis != NULL) && (closure->func.common.fn_flags & ZEND_ACC_STATIC)) {
		zend_error(E_WARNING, "Cannot bind an instance to a static closure");
	}

	if (scope_arg != NULL) { /* scope argument was given */
		if (IS_ZEND_STD_OBJECT(*scope_arg)) {
			ce = Z_OBJCE_P(scope_arg);
		} else if (Z_TYPE_P(scope_arg) == IS_NULL) {
			ce = NULL;
		} else {
			zend_string *class_name = zval_get_string(scope_arg);
			if ((class_name->len == sizeof("static") - 1) &&
				(memcmp("static", class_name->val, sizeof("static") - 1) == 0)) {
				ce = closure->func.common.scope;
			} else if ((ce = zend_lookup_class_ex(class_name, NULL, 1 TSRMLS_CC)) == NULL) {
				zend_error(E_WARNING, "Class '%s' not found", class_name->val);
				STR_RELEASE(class_name);
				RETURN_NULL();
			}
			STR_RELEASE(class_name);
		}
	} else { /* scope argument not given; do not change the scope by default */
		ce = closure->func.common.scope;
	}

	zend_create_closure(return_value, &closure->func, ce, newthis TSRMLS_CC);
}
Exemplo n.º 5
0
ZEND_METHOD(Closure, __invoke) /* {{{ */
{
	zend_function *func = EG(current_execute_data)->func;
	zval *arguments;

	arguments = emalloc(sizeof(zval) * ZEND_NUM_ARGS());
	if (zend_get_parameters_array_ex(ZEND_NUM_ARGS(), arguments) == FAILURE) {
		efree(arguments);
		zend_error(E_RECOVERABLE_ERROR, "Cannot get arguments for calling closure");
		RETVAL_FALSE;
	} else if (call_user_function_ex(CG(function_table), NULL, getThis(), return_value, ZEND_NUM_ARGS(), arguments, 1, NULL TSRMLS_CC) == FAILURE) {
		RETVAL_FALSE;
	}
	efree(arguments);

	/* destruct the function also, then - we have allocated it in get_method */
	STR_RELEASE(func->internal_function.function_name);
	efree(func);
}
Exemplo n.º 6
0
int fpm_status_handle_request(TSRMLS_D) /* {{{ */
{
	struct fpm_scoreboard_s scoreboard, *scoreboard_p;
	struct fpm_scoreboard_proc_s proc;
	char *buffer, *time_format, time_buffer[64];
	time_t now_epoch;
	int full, encode;
	char *short_syntax, *short_post;
	char *full_pre, *full_syntax, *full_post, *full_separator;
	zend_string *_GET_str;

	if (!SG(request_info).request_uri) {
		return 0;
	}

	/* PING */
	if (fpm_status_ping_uri && fpm_status_ping_response && !strcmp(fpm_status_ping_uri, SG(request_info).request_uri)) {
		fpm_request_executing();
		sapi_add_header_ex(ZEND_STRL("Content-Type: text/plain"), 1, 1 TSRMLS_CC);
		sapi_add_header_ex(ZEND_STRL("Expires: Thu, 01 Jan 1970 00:00:00 GMT"), 1, 1 TSRMLS_CC);
		sapi_add_header_ex(ZEND_STRL("Cache-Control: no-cache, no-store, must-revalidate, max-age=0"), 1, 1 TSRMLS_CC);
		SG(sapi_headers).http_response_code = 200;

		/* handle HEAD */
		if (SG(request_info).headers_only) {
			return 1;
		}

		PUTS(fpm_status_ping_response);
		return 1;
	}

	/* STATUS */
	if (fpm_status_uri && !strcmp(fpm_status_uri, SG(request_info).request_uri)) {
		fpm_request_executing();

		scoreboard_p = fpm_scoreboard_get();
		if (!scoreboard_p) {
			zlog(ZLOG_ERROR, "status: unable to find or access status shared memory");
			SG(sapi_headers).http_response_code = 500;
			sapi_add_header_ex(ZEND_STRL("Content-Type: text/plain"), 1, 1 TSRMLS_CC);
			sapi_add_header_ex(ZEND_STRL("Expires: Thu, 01 Jan 1970 00:00:00 GMT"), 1, 1 TSRMLS_CC);
			sapi_add_header_ex(ZEND_STRL("Cache-Control: no-cache, no-store, must-revalidate, max-age=0"), 1, 1 TSRMLS_CC);
			PUTS("Internal error. Please review log file for errors.");
			return 1;
		}

		if (!fpm_spinlock(&scoreboard_p->lock, 1)) {
			zlog(ZLOG_NOTICE, "[pool %s] status: scoreboard already in used.", scoreboard_p->pool);
			SG(sapi_headers).http_response_code = 503;
			sapi_add_header_ex(ZEND_STRL("Content-Type: text/plain"), 1, 1 TSRMLS_CC);
			sapi_add_header_ex(ZEND_STRL("Expires: Thu, 01 Jan 1970 00:00:00 GMT"), 1, 1 TSRMLS_CC);
			sapi_add_header_ex(ZEND_STRL("Cache-Control: no-cache, no-store, must-revalidate, max-age=0"), 1, 1 TSRMLS_CC);
			PUTS("Server busy. Please try again later.");
			return 1;
		}
		/* copy the scoreboard not to bother other processes */
		scoreboard = *scoreboard_p;
		fpm_unlock(scoreboard_p->lock);

		if (scoreboard.idle < 0 || scoreboard.active < 0) {
			zlog(ZLOG_ERROR, "[pool %s] invalid status values", scoreboard.pool);
			SG(sapi_headers).http_response_code = 500;
			sapi_add_header_ex(ZEND_STRL("Content-Type: text/plain"), 1, 1 TSRMLS_CC);
			sapi_add_header_ex(ZEND_STRL("Expires: Thu, 01 Jan 1970 00:00:00 GMT"), 1, 1 TSRMLS_CC);
			sapi_add_header_ex(ZEND_STRL("Cache-Control: no-cache, no-store, must-revalidate, max-age=0"), 1, 1 TSRMLS_CC);
			PUTS("Internal error. Please review log file for errors.");
			return 1;
		}

		/* send common headers */
		sapi_add_header_ex(ZEND_STRL("Expires: Thu, 01 Jan 1970 00:00:00 GMT"), 1, 1 TSRMLS_CC);
		sapi_add_header_ex(ZEND_STRL("Cache-Control: no-cache, no-store, must-revalidate, max-age=0"), 1, 1 TSRMLS_CC);
		SG(sapi_headers).http_response_code = 200;

		/* handle HEAD */
		if (SG(request_info).headers_only) {
			return 1;
		}

		/* full status ? */
		_GET_str = STR_INIT("_GET", sizeof("_GET")-1, 0);
		full = (fpm_php_get_string_from_table(_GET_str, "full" TSRMLS_CC) != NULL);
		short_syntax = short_post = NULL;
		full_separator = full_pre = full_syntax = full_post = NULL;
		encode = 0;

		/* HTML */
		if (fpm_php_get_string_from_table(_GET_str, "html" TSRMLS_CC)) {
			sapi_add_header_ex(ZEND_STRL("Content-Type: text/html"), 1, 1 TSRMLS_CC);
			time_format = "%d/%b/%Y:%H:%M:%S %z";
			encode = 1;

			short_syntax =
				"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
				"<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n"
				"<head><title>PHP-FPM Status Page</title></head>\n"
				"<body>\n"
				"<table>\n"
					"<tr><th>pool</th><td>%s</td></tr>\n"
					"<tr><th>process manager</th><td>%s</td></tr>\n"
					"<tr><th>start time</th><td>%s</td></tr>\n"
					"<tr><th>start since</th><td>%lu</td></tr>\n"
					"<tr><th>accepted conn</th><td>%lu</td></tr>\n"
#ifdef HAVE_FPM_LQ
					"<tr><th>listen queue</th><td>%u</td></tr>\n"
					"<tr><th>max listen queue</th><td>%u</td></tr>\n"
					"<tr><th>listen queue len</th><td>%d</td></tr>\n"
#endif
					"<tr><th>idle processes</th><td>%d</td></tr>\n"
					"<tr><th>active processes</th><td>%d</td></tr>\n"
					"<tr><th>total processes</th><td>%d</td></tr>\n"
					"<tr><th>max active processes</th><td>%d</td></tr>\n"
					"<tr><th>max children reached</th><td>%u</td></tr>\n"
					"<tr><th>slow requests</th><td>%lu</td></tr>\n"
				"</table>\n";

			if (!full) {
				short_post = "</body></html>";
			} else {
				full_pre =
					"<table border=\"1\">\n"
					"<tr>"
						"<th>pid</th>"
						"<th>state</th>"
						"<th>start time</th>"
						"<th>start since</th>"
						"<th>requests</th>"
						"<th>request duration</th>"
						"<th>request method</th>"
						"<th>request uri</th>"
						"<th>content length</th>"
						"<th>user</th>"
						"<th>script</th>"
#ifdef HAVE_FPM_LQ
						"<th>last request cpu</th>"
#endif
						"<th>last request memory</th>"
					"</tr>\n";

				full_syntax =
					"<tr>"
						"<td>%d</td>"
						"<td>%s</td>"
						"<td>%s</td>"
						"<td>%lu</td>"
						"<td>%lu</td>"
						"<td>%lu</td>"
						"<td>%s</td>"
						"<td>%s%s%s</td>"
						"<td>%zu</td>"
						"<td>%s</td>"
						"<td>%s</td>"
#ifdef HAVE_FPM_LQ
						"<td>%.2f</td>"
#endif
						"<td>%zu</td>"
					"</tr>\n";

				full_post = "</table></body></html>";
			}

		/* XML */
		} else if (fpm_php_get_string_from_table(_GET_str, "xml" TSRMLS_CC)) {
			sapi_add_header_ex(ZEND_STRL("Content-Type: text/xml"), 1, 1 TSRMLS_CC);
			time_format = "%s";
			encode = 1;

			short_syntax =
				"<?xml version=\"1.0\" ?>\n"
				"<status>\n"
				"<pool>%s</pool>\n"
				"<process-manager>%s</process-manager>\n"
				"<start-time>%s</start-time>\n"
				"<start-since>%lu</start-since>\n"
				"<accepted-conn>%lu</accepted-conn>\n"
#ifdef HAVE_FPM_LQ
				"<listen-queue>%u</listen-queue>\n"
				"<max-listen-queue>%u</max-listen-queue>\n"
				"<listen-queue-len>%d</listen-queue-len>\n"
#endif
				"<idle-processes>%d</idle-processes>\n"
				"<active-processes>%d</active-processes>\n"
				"<total-processes>%d</total-processes>\n"
				"<max-active-processes>%d</max-active-processes>\n"
				"<max-children-reached>%u</max-children-reached>\n"
				"<slow-requests>%lu</slow-requests>\n";

				if (!full) {
					short_post = "</status>";
				} else {
					full_pre = "<processes>\n";
					full_syntax = 
						"<process>"
							"<pid>%d</pid>"
							"<state>%s</state>"
							"<start-time>%s</start-time>"
							"<start-since>%lu</start-since>"
							"<requests>%lu</requests>"
							"<request-duration>%lu</request-duration>"
							"<request-method>%s</request-method>"
							"<request-uri>%s%s%s</request-uri>"
							"<content-length>%zu</content-length>"
							"<user>%s</user>"
							"<script>%s</script>"
#ifdef HAVE_FPM_LQ
							"<last-request-cpu>%.2f</last-request-cpu>"
#endif
							"<last-request-memory>%zu</last-request-memory>"
						"</process>\n"
					;
					full_post = "</processes>\n</status>";
				}

			/* JSON */
		} else if (fpm_php_get_string_from_table(_GET_str, "json" TSRMLS_CC)) {
			sapi_add_header_ex(ZEND_STRL("Content-Type: application/json"), 1, 1 TSRMLS_CC);
			time_format = "%s";

			short_syntax =
				"{"
				"\"pool\":\"%s\","
				"\"process manager\":\"%s\","
				"\"start time\":%s,"
				"\"start since\":%lu,"
				"\"accepted conn\":%lu,"
#ifdef HAVE_FPM_LQ
				"\"listen queue\":%u,"
				"\"max listen queue\":%u,"
				"\"listen queue len\":%d,"
#endif
				"\"idle processes\":%d,"
				"\"active processes\":%d,"
				"\"total processes\":%d,"
				"\"max active processes\":%d,"
				"\"max children reached\":%u,"
				"\"slow requests\":%lu";

			if (!full) {
				short_post = "}";
			} else {
				full_separator = ",";
				full_pre = ", \"processes\":[";

				full_syntax = "{"
					"\"pid\":%d,"
					"\"state\":\"%s\","
					"\"start time\":%s,"
					"\"start since\":%lu,"
					"\"requests\":%lu,"
					"\"request duration\":%lu,"
					"\"request method\":\"%s\","
					"\"request uri\":\"%s%s%s\","
					"\"content length\":%zu,"
					"\"user\":\"%s\","
					"\"script\":\"%s\","
#ifdef HAVE_FPM_LQ
					"\"last request cpu\":%.2f,"
#endif
					"\"last request memory\":%zu"
					"}";

				full_post = "]}";
			}

		/* TEXT */
		} else {
			sapi_add_header_ex(ZEND_STRL("Content-Type: text/plain"), 1, 1 TSRMLS_CC);
			time_format = "%d/%b/%Y:%H:%M:%S %z";

			short_syntax =
				"pool:                 %s\n"
				"process manager:      %s\n"
				"start time:           %s\n"
				"start since:          %lu\n"
				"accepted conn:        %lu\n"
#ifdef HAVE_FPM_LQ
				"listen queue:         %u\n"
				"max listen queue:     %u\n"
				"listen queue len:     %d\n"
#endif
				"idle processes:       %d\n"
				"active processes:     %d\n"
				"total processes:      %d\n"
				"max active processes: %d\n"
				"max children reached: %u\n"
				"slow requests:        %lu\n";

				if (full) {
					full_syntax =
						"\n"
						"************************\n"
						"pid:                  %d\n"
						"state:                %s\n"
						"start time:           %s\n"
						"start since:          %lu\n"
						"requests:             %lu\n"
						"request duration:     %lu\n"
						"request method:       %s\n"
						"request URI:          %s%s%s\n"
						"content length:       %zu\n"
						"user:                 %s\n"
						"script:               %s\n"
#ifdef HAVE_FPM_LQ
						"last request cpu:     %.2f\n"
#endif
						"last request memory:  %zu\n";
				}
		}

		strftime(time_buffer, sizeof(time_buffer) - 1, time_format, localtime(&scoreboard.start_epoch));
		now_epoch = time(NULL);
		spprintf(&buffer, 0, short_syntax,
				scoreboard.pool,
				PM2STR(scoreboard.pm),
				time_buffer,
				now_epoch - scoreboard.start_epoch,
				scoreboard.requests,
#ifdef HAVE_FPM_LQ
				scoreboard.lq,
				scoreboard.lq_max,
				scoreboard.lq_len,
#endif
				scoreboard.idle,
				scoreboard.active,
				scoreboard.idle + scoreboard.active,
				scoreboard.active_max,
				scoreboard.max_children_reached,
				scoreboard.slow_rq);

		PUTS(buffer);
		efree(buffer);
		STR_RELEASE(_GET_str);

		if (short_post) {
			PUTS(short_post);
		}

		/* no need to test the var 'full' */
		if (full_syntax) {
			int i, first;
			zend_string *tmp_query_string;
			char *query_string;
			struct timeval duration, now;
#ifdef HAVE_FPM_LQ
			float cpu;
#endif

			fpm_clock_get(&now);

			if (full_pre) {
				PUTS(full_pre);
			}

			first = 1;
			for (i=0; i<scoreboard_p->nprocs; i++) {
				if (!scoreboard_p->procs[i] || !scoreboard_p->procs[i]->used) {
					continue;
				}
				proc = *scoreboard_p->procs[i];

				if (first) {
					first = 0;
				} else {
					if (full_separator) {
						PUTS(full_separator);
					}
				}

				query_string = NULL;
				tmp_query_string = NULL;
				if (proc.query_string[0] != '\0') {
					if (!encode) {
						query_string = proc.query_string;
					} else {
						tmp_query_string = php_escape_html_entities_ex((unsigned char *)proc.query_string, strlen(proc.query_string), 1, ENT_HTML_IGNORE_ERRORS & ENT_COMPAT, NULL, 1 TSRMLS_CC);
						query_string = tmp_query_string->val;
					}
				}

#ifdef HAVE_FPM_LQ
				/* prevent NaN */
				if (proc.cpu_duration.tv_sec == 0 && proc.cpu_duration.tv_usec == 0) {
					cpu = 0.;
				} else {
					cpu = (proc.last_request_cpu.tms_utime + proc.last_request_cpu.tms_stime + proc.last_request_cpu.tms_cutime + proc.last_request_cpu.tms_cstime) / fpm_scoreboard_get_tick() / (proc.cpu_duration.tv_sec + proc.cpu_duration.tv_usec / 1000000.) * 100.;
				}
#endif

				if (proc.request_stage == FPM_REQUEST_ACCEPTING) {
					duration = proc.duration;
				} else {
					timersub(&now, &proc.accepted, &duration);
				}
				strftime(time_buffer, sizeof(time_buffer) - 1, time_format, localtime(&proc.start_epoch));
				spprintf(&buffer, 0, full_syntax,
					proc.pid,
					fpm_request_get_stage_name(proc.request_stage),
					time_buffer,
					now_epoch - proc.start_epoch,
					proc.requests,
					duration.tv_sec * 1000000UL + duration.tv_usec,
					proc.request_method[0] != '\0' ? proc.request_method : "-",
					proc.request_uri[0] != '\0' ? proc.request_uri : "-",
					query_string ? "?" : "",
					query_string ? query_string : "",
					proc.content_length,
					proc.auth_user[0] != '\0' ? proc.auth_user : "******",
					proc.script_filename[0] != '\0' ? proc.script_filename : "-",
#ifdef HAVE_FPM_LQ
					proc.request_stage == FPM_REQUEST_ACCEPTING ? cpu : 0.,
#endif
					proc.request_stage == FPM_REQUEST_ACCEPTING ? proc.memory : 0);
				PUTS(buffer);
				efree(buffer);

				if (tmp_query_string) {
					STR_FREE(tmp_query_string);
				}
			}

			if (full_post) {
				PUTS(full_post);
			}
		}

		return 1;
	}

	return 0;
}
Exemplo n.º 7
0
/* Given a type-library, merge it into the current engine state */
PHP_COM_DOTNET_API int php_com_import_typelib(ITypeLib *TL, int mode, int codepage TSRMLS_DC)
{
	int i, j, interfaces;
	TYPEKIND pTKind;
	ITypeInfo *TypeInfo;
	VARDESC *pVarDesc;
	UINT NameCount;
	BSTR bstr_ids;
	zend_constant c;
	zval *exists, results, value;
	char *const_name;
	int len;

	if (TL == NULL) {
		return FAILURE;
	}

	interfaces = ITypeLib_GetTypeInfoCount(TL);
	for (i = 0; i < interfaces; i++) {
		ITypeLib_GetTypeInfoType(TL, i, &pTKind);
		if (pTKind == TKIND_ENUM) {
			ITypeLib_GetTypeInfo(TL, i, &TypeInfo);
			for (j = 0; ; j++) {
				if (FAILED(ITypeInfo_GetVarDesc(TypeInfo, j, &pVarDesc))) {
					break;
				}
				ITypeInfo_GetNames(TypeInfo, pVarDesc->memid, &bstr_ids, 1, &NameCount);
				if (NameCount != 1) {
					ITypeInfo_ReleaseVarDesc(TypeInfo, pVarDesc);
					continue;
				}

				const_name = php_com_olestring_to_string(bstr_ids, &len, codepage TSRMLS_CC);
				c.name = STR_INIT(const_name, len, 1);
				// TODO: avoid reallocation???
				efree(const_name);
				if(c.name == NULL) {
					ITypeInfo_ReleaseVarDesc(TypeInfo, pVarDesc);
					continue;
				}
//???				c.name_len++; /* include NUL */
				SysFreeString(bstr_ids);

				/* sanity check for the case where the constant is already defined */
				if ((exists = zend_get_constant(c.name TSRMLS_CC)) != NULL) {
					if (COMG(autoreg_verbose) && !compare_function(&results, &c.value, exists TSRMLS_CC)) {
						php_error_docref(NULL TSRMLS_CC, E_WARNING, "Type library constant %s is already defined", c.name);
					}
					STR_RELEASE(c.name);
					ITypeInfo_ReleaseVarDesc(TypeInfo, pVarDesc);
					continue;
				}

				/* register the constant */
				php_com_zval_from_variant(&value, pVarDesc->lpvarValue, codepage TSRMLS_CC);
				if (Z_TYPE(value) == IS_INT) {
					c.flags = mode;
					ZVAL_INT(&c.value, Z_IVAL(value));
					c.module_number = 0;
					zend_register_constant(&c TSRMLS_CC);
				}
				ITypeInfo_ReleaseVarDesc(TypeInfo, pVarDesc);
			}
			ITypeInfo_Release(TypeInfo);
		}
	}
	return SUCCESS;
}
Exemplo n.º 8
0
static void php_fsockopen_stream(INTERNAL_FUNCTION_PARAMETERS, int persistent)
{
	char *host;
	int host_len;
	long port = -1;
	zval *zerrno = NULL, *zerrstr = NULL;
	double timeout = FG(default_socket_timeout);
	unsigned long conv;
	struct timeval tv;
	char *hashkey = NULL;
	php_stream *stream = NULL;
	int err;
	char *hostname = NULL;
	long hostname_len;
	zend_string *errstr = NULL;

	RETVAL_FALSE;
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lz/z/d", &host, &host_len, &port, &zerrno, &zerrstr, &timeout) == FAILURE) {
		RETURN_FALSE;
	}

	if (persistent) {
		spprintf(&hashkey, 0, "pfsockopen__%s:%ld", host, port);
	}

	if (port > 0) {
		hostname_len = spprintf(&hostname, 0, "%s:%ld", host, port);
	} else {
		hostname_len = host_len;
		hostname = host;
	}
	
	/* prepare the timeout value for use */
	conv = (unsigned long) (timeout * 1000000.0);
	tv.tv_sec = conv / 1000000;
	tv.tv_usec = conv % 1000000;

	if (zerrno)	{
		zval_dtor(zerrno);
		ZVAL_LONG(zerrno, 0);
	}
	if (zerrstr) {
		zval_dtor(zerrstr);
		ZVAL_EMPTY_STRING(zerrstr);
	}

	stream = php_stream_xport_create(hostname, hostname_len, REPORT_ERRORS,
			STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT, hashkey, &tv, NULL, &errstr, &err);

	if (port > 0) {
		efree(hostname);
	}
	if (stream == NULL) {
		php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to connect to %s:%ld (%s)", host, port, errstr == NULL ? "Unknown error" : errstr->val);
	}

	if (hashkey) {
		efree(hashkey);
	}
	
	if (stream == NULL)	{
		if (zerrno) {
			zval_dtor(zerrno);
			ZVAL_LONG(zerrno, err);
		}
		if (zerrstr && errstr) {
			/* no need to dup; we need to efree buf anyway */
			zval_dtor(zerrstr);
			ZVAL_STR(zerrstr, errstr);
		} else if (!zerrstr && errstr) {
			STR_RELEASE(errstr);
		} 

		RETURN_FALSE;
	}

	if (errstr) {
		STR_RELEASE(errstr);
	}
		
	php_stream_to_zval(stream, return_value);
}
Exemplo n.º 9
0
static void dom_xpath_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs, int type) /* {{{ */
{
	zval retval;
	int result, i;
	int error = 0;
	zend_fcall_info fci;
	xmlXPathObjectPtr obj;
	char *str;
	zend_string *callable = NULL;
	dom_xpath_object *intern;
	
	TSRMLS_FETCH();

	if (! zend_is_executing(TSRMLS_C)) {
		xmlGenericError(xmlGenericErrorContext,
		"xmlExtFunctionTest: Function called from outside of PHP\n");
		error = 1;
	} else {
		intern = (dom_xpath_object *) ctxt->context->userData;
		if (intern == NULL) {
			xmlGenericError(xmlGenericErrorContext,
			"xmlExtFunctionTest: failed to get the internal object\n");
			error = 1;
		}
		else if (intern->registerPhpFunctions == 0) {
			xmlGenericError(xmlGenericErrorContext,
			"xmlExtFunctionTest: PHP Object did not register PHP functions\n");
			error = 1;
		}
	}
	
	if (error == 1) {
		for (i = nargs - 1; i >= 0; i--) {
			obj = valuePop(ctxt);
			xmlXPathFreeObject(obj);
		}
		return;
	}
		
	fci.param_count = nargs - 1;
	if (fci.param_count > 0) {
		fci.params = safe_emalloc(fci.param_count, sizeof(zval), 0);
	}
	/* Reverse order to pop values off ctxt stack */
	for (i = nargs - 2; i >= 0; i--) {
		obj = valuePop(ctxt);
		switch (obj->type) {
			case XPATH_STRING:
				ZVAL_STRING(&fci.params[i],  (char *)obj->stringval);
				break;
			case XPATH_BOOLEAN:
				ZVAL_BOOL(&fci.params[i],  obj->boolval);
				break;
			case XPATH_NUMBER:
				ZVAL_DOUBLE(&fci.params[i], obj->floatval);
				break;
			case XPATH_NODESET:
				if (type == 1) {
					str = (char *)xmlXPathCastToString(obj);
					ZVAL_STRING(&fci.params[i], str);
					xmlFree(str);
				} else if (type == 2) {
					int j;
					array_init(&fci.params[i]);
					if (obj->nodesetval && obj->nodesetval->nodeNr > 0) {
						for (j = 0; j < obj->nodesetval->nodeNr; j++) {
							xmlNodePtr node = obj->nodesetval->nodeTab[j];
							zval child;
							/* not sure, if we need this... it's copied from xpath.c */
							if (node->type == XML_NAMESPACE_DECL) {
								xmlNsPtr curns;
								xmlNodePtr nsparent;
								
								nsparent = node->_private;
								curns = xmlNewNs(NULL, node->name, NULL);
								if (node->children) {
									curns->prefix = xmlStrdup((xmlChar *) node->children);
								}
								if (node->children) {
									node = xmlNewDocNode(node->doc, NULL, (xmlChar *) node->children, node->name);
								} else {
									node = xmlNewDocNode(node->doc, NULL, (xmlChar *) "xmlns", node->name);
								}
								node->type = XML_NAMESPACE_DECL;
								node->parent = nsparent;
								node->ns = curns;
							}
							php_dom_create_object(node, &child, &intern->dom TSRMLS_CC);
							add_next_index_zval(&fci.params[i], &child);
						}
					}
				}
				break;
			default:
			ZVAL_STRING(&fci.params[i], (char *)xmlXPathCastToString(obj));
		}
		xmlXPathFreeObject(obj);
	}
	
	fci.size = sizeof(fci);
	fci.function_table = EG(function_table);
	
	obj = valuePop(ctxt);
	if (obj->stringval == NULL) {
		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Handler name must be a string");
		xmlXPathFreeObject(obj);
		if (fci.param_count > 0) {
			for (i = 0; i < nargs - 1; i++) {
				zval_ptr_dtor(&fci.params[i]);
			}
			efree(fci.params);
		}
		return; 
	}
	ZVAL_STRING(&fci.function_name, obj->stringval);
	xmlXPathFreeObject(obj);

	fci.symbol_table = NULL;
	fci.object = NULL;
	fci.retval = &retval;
	fci.no_separation = 0;

	if (!zend_make_callable(&fci.function_name, &callable TSRMLS_CC)) {
		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call handler %s()", callable->val);
	} else if (intern->registerPhpFunctions == 2 && zend_hash_exists(intern->registered_phpfunctions, callable) == 0) { 
		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Not allowed to call handler '%s()'.", callable->val);
		/* Push an empty string, so that we at least have an xslt result... */
		valuePush(ctxt, xmlXPathNewString((xmlChar *)""));
	} else {
		result = zend_call_function(&fci, NULL TSRMLS_CC);
		if (result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) {
			if (Z_TYPE(retval) == IS_OBJECT && instanceof_function(Z_OBJCE(retval), dom_node_class_entry TSRMLS_CC)) {
				xmlNode *nodep;
				dom_object *obj;
				if (intern->node_list == NULL) {
					ALLOC_HASHTABLE(intern->node_list);
					zend_hash_init(intern->node_list, 0, NULL, ZVAL_PTR_DTOR, 0);
				}
				GC_REFCOUNT(&retval)++;
				zend_hash_next_index_insert(intern->node_list, &retval);
				obj = Z_DOMOBJ_P(&retval);
				nodep = dom_object_get_node(obj);
				valuePush(ctxt, xmlXPathNewNodeSet(nodep));
			} else if (Z_TYPE(retval) == IS_FALSE || Z_TYPE(retval) == IS_TRUE) {
				valuePush(ctxt, xmlXPathNewBoolean(Z_TYPE(retval) == IS_TRUE));
			} else if (Z_TYPE(retval) == IS_OBJECT) {
				php_error_docref(NULL TSRMLS_CC, E_WARNING, "A PHP Object cannot be converted to a XPath-string");
				valuePush(ctxt, xmlXPathNewString((xmlChar *)""));
			} else {
				zend_string *str = zval_get_string(&retval);
				valuePush(ctxt, xmlXPathNewString(str->val));
				STR_RELEASE(str);
			}
			zval_ptr_dtor(&retval);
		}
	}
	STR_RELEASE(callable);
	zval_dtor(&fci.function_name);
	if (fci.param_count > 0) {
		for (i = 0; i < nargs - 1; i++) {
			zval_ptr_dtor(&fci.params[i]);
		}
		efree(fci.params);
	}
}
Exemplo n.º 10
0
static void
handleReadRequest(INKCont pCont, INKHttpTxn pTxn)
{
  LOG_SET_FUNCTION_NAME("handleReadRequest");

  INKMBuffer reqHdrBuf = NULL, newHttpHdrBuf = NULL;
  INKMLoc reqHdrLoc = NULL, newHttpHdrLoc = NULL;

  INKHttpType httpType;

  int iOldHttpVersion, iHttpMethodLength, iHttpVersion;
  const char *sHttpMethod = NULL;
  char *outputString = NULL, *sOldHttpMethod = NULL;

  HdrInfo_T *pReqHdrInfo = NULL, *pNewReqHdrInfo = NULL;

#if 0
  const char *constant_request_header_str =
    "GET http://www.joes-hardware.com/ HTTP/1.0\r\nDate: Wed, 05 Jul 2000 22:12:26 GMT\r\nConnection: Keep-Alive\r\nUser-Agent: Mozilla/4.51 [en] (X11; U; IRIX 6.2 IP22)\r\nHost: www.joes-hardware.com\r\nCache-Control: no-cache\r\nAccept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*\r\nAccept-Charset: iso-8859-1,*,utf-8\r\nAccept-Encoding: gzip\r\nAccept-Language: en\r\nX-Number-Header: 12345\r\nX-Silly-Header: frobnichek grobbledegook\r\nAccept-Charset: windows-1250, koi8-r\r\nX-Silly-Header: wawaaa\r\n\r\n";

#endif


  pReqHdrInfo = initHdr();
  pNewReqHdrInfo = initHdr();

  INKDebug(REQ, "\n>>>>>> handleReadRequest <<<<<<<\n");

  /* Get Request Marshall Buffer */
  if (!INKHttpTxnClientReqGet(pTxn, &reqHdrBuf, &reqHdrLoc)) {
    LOG_API_ERROR_COMMENT("INKHttpTxnClientReqGet", "ERROR: Can't retrieve client req hdr");
    goto done;
  }


    /******* (1): Get every specifics from the HTTP header *********/

  INKDebug(REQ, "--------------------------------");

  getHdrInfo(pReqHdrInfo, reqHdrBuf, reqHdrLoc);
  printHttpHeader(reqHdrBuf, reqHdrLoc, REQ, 1);

#ifdef DEBUG
  negTesting(reqHdrBuf, reqHdrLoc);
#endif

    /*********** (2): Create/Copy/Destroy **********/
  /* For every request, create, copy and destroy a new HTTP header and 
   * print the details */

  INKDebug(REQ, "--------------------------------");
  if ((newHttpHdrBuf = INKMBufferCreate()) == INK_ERROR_PTR) {
    LOG_API_ERROR_COMMENT("INKMBufferCreate", "skipping to section 3");
    goto section_3;             /* Skip to section (3) down the line directly; I hate GOTOs */
  }

    /*** INKHttpHdrCreate ***/
  if ((newHttpHdrLoc = INKHttpHdrCreate(newHttpHdrBuf)) == INK_ERROR_PTR) {
    LOG_API_ERROR_COMMENT("INKHttpHdrCreate", "skipping to section 3");
    goto section_3;             /* Skip to section (3) down the line directly; I hate GOTOs */
  }

  /* Make sure the newly created HTTP header has INKHttpType value of INK_HTTP_TYPE_UNKNOWN */
  if ((httpType = INKHttpHdrTypeGet(newHttpHdrBuf, newHttpHdrLoc)) == INK_ERROR) {
    LOG_API_ERROR_COMMENT("INKHttpHdrTypeGet", "but still continuing...");
  } else if (httpType != INK_HTTP_TYPE_UNKNOWN) {
    LOG_AUTO_ERROR("INKHttpHdrCreate", "Newly created hdr not of type INK_HTTP_TYPE_UNKNOWN");
  }

  /* set the HTTP header type: a new buffer has a type INK_HTTP_TYPE_UNKNOWN by default */
  if (INKHttpHdrTypeSet(newHttpHdrBuf, newHttpHdrLoc, INK_HTTP_TYPE_REQUEST) == INK_ERROR) {
    LOG_API_ERROR_COMMENT("INKHttpHdrTypeSet", "unable to set it to INK_HTTP_TYPE_REQUEST");
  } else if ((httpType = INKHttpHdrTypeGet(newHttpHdrBuf, newHttpHdrLoc)) == INK_ERROR) {
    LOG_API_ERROR_COMMENT("INKHttpHdrTypeGet", "still continuing");
  } else if (httpType != INK_HTTP_TYPE_REQUEST) {
    LOG_AUTO_ERROR("INKHttpHdrTypeSet", "Type not set to INK_HTTP_TYPE_REQUEST");
  }

    /*** INKHttpHdrCopy ***/
  if (INKHttpHdrCopy(newHttpHdrBuf, newHttpHdrLoc, reqHdrBuf, reqHdrLoc) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrCopy");
  }
  getHdrInfo(pNewReqHdrInfo, newHttpHdrBuf, newHttpHdrLoc);

  if (!identical_hdr(pNewReqHdrInfo, pReqHdrInfo)) {
    LOG_AUTO_ERROR("INKHttpHdrCopy", "New req buffer not identical to the original");
  }

  printHttpHeader(newHttpHdrBuf, newHttpHdrLoc, REQ, 2);

  FREE(pNewReqHdrInfo->httpMethod);
  FREE(pNewReqHdrInfo->hostName);

section_3:
    /********* (3): Excercise all the INK__Set on ReqBuf *********/
  INKDebug(REQ, "--------------------------------");

    /*** INKHttpHdrMethodSet ***/
  /* save the original method */
  if ((sHttpMethod = INKHttpHdrMethodGet(reqHdrBuf, reqHdrLoc, &iHttpMethodLength)) == INK_ERROR_PTR) {
    LOG_API_ERROR("INKHttpHdrMethodGet");
  } else {
    sOldHttpMethod = INKstrndup(sHttpMethod, iHttpMethodLength);
  }
  /* change it to some unknown method */
  if (INKHttpHdrMethodSet(reqHdrBuf, reqHdrLoc, "FOOBAR", strlen("FOOBAR")) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrMethodSet");
  } else {
    if ((sHttpMethod = INKHttpHdrMethodGet(reqHdrBuf, reqHdrLoc, &iHttpMethodLength)) == INK_ERROR_PTR) {
      LOG_API_ERROR("INKHttpHdrMethodGet");
    } else if (strncmp(sHttpMethod, "FOOBAR", iHttpMethodLength)) {
      LOG_AUTO_ERROR("INKHttpHdrMethodSet/Get", "GET method different from SET method");
    }
  }

  outputString = INKstrndup(sHttpMethod, iHttpMethodLength);
  INKDebug(REQ, "(3): new HTTP Header Method = %s", outputString);
  FREE(outputString);
  STR_RELEASE(reqHdrBuf, reqHdrLoc, sHttpMethod);

  printHttpHeader(reqHdrBuf, reqHdrLoc, REQ, 3);

  /* set it back to the original method */
  /*INKHttpHdrMethodSet (reqHdrBuf, reqHdrLoc, sOldHttpMethod, iHttpMethodLength); */
  if (INKHttpHdrMethodSet(reqHdrBuf, reqHdrLoc, sOldHttpMethod, strlen(sOldHttpMethod)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrMethodSet");
  } else if ((sHttpMethod = INKHttpHdrMethodGet(reqHdrBuf, reqHdrLoc, &iHttpMethodLength)) == INK_ERROR_PTR) {
    LOG_API_ERROR("INKHttpHdrMethodGet");
  } else if (strncmp(sHttpMethod, sOldHttpMethod, iHttpMethodLength)) {
    LOG_AUTO_ERROR("INKHttpHdrMethodSet/Get", "GET method different from SET method");
  }

  outputString = INKstrndup(sHttpMethod, iHttpMethodLength);
  INKDebug(REQ, "(3): original HTTP Header Method = %s", outputString);
  FREE(outputString);
  STR_RELEASE(reqHdrBuf, reqHdrLoc, sHttpMethod);


    /*** INKHttpHdrVersionSet ***/
  /* get the original version */
  if ((iOldHttpVersion = INKHttpHdrVersionGet(reqHdrBuf, reqHdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrVersionGet");
  }

  /* change it to some unknown version */
  if (INKHttpHdrVersionSet(reqHdrBuf, reqHdrLoc, INK_HTTP_VERSION(10, 10)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrVersionSet");
  } else if ((iHttpVersion = INKHttpHdrVersionGet(reqHdrBuf, reqHdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrVersionGet");
  } else if ((INK_HTTP_MAJOR(iHttpVersion) != 10) || (INK_HTTP_MINOR(iHttpVersion) != 10)) {
    LOG_AUTO_ERROR("INKHttpHdrVersionSet/Get", "SET HTTP version different from GET version");
  }

  INKDebug(REQ, "(3): new HTTP version; Major = %d   Minor = %d",
           INK_HTTP_MAJOR(iHttpVersion), INK_HTTP_MINOR(iHttpVersion));

  /* change it back to the original version */
  if (INKHttpHdrVersionSet(reqHdrBuf, reqHdrLoc, iOldHttpVersion) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrVersionSet");
  } else if ((iHttpVersion = INKHttpHdrVersionGet(reqHdrBuf, reqHdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrVersionGet");
  } else if (iHttpVersion != iOldHttpVersion) {
    LOG_AUTO_ERROR("INKHttpHdrVersionSet/Get", "SET HTTP version different from GET version");
  }

  getHdrInfo(pNewReqHdrInfo, reqHdrBuf, reqHdrLoc);
  if (!identical_hdr(pNewReqHdrInfo, pReqHdrInfo)) {
    LOG_AUTO_ERROR("INK..Set", "ReqBuf: Values not restored properly");
  }

  /* (3): clean-up */
  FREE(sOldHttpMethod);

done:
    /*************** Clean-up ***********************/
  /*
     FREE(pReqHdrInfo->httpMethod);
     FREE(pReqHdrInfo->hostName);

     FREE(pNewReqHdrInfo->httpMethod);
     FREE(pNewReqHdrInfo->hostName);

     FREE(pReqHdrInfo);
     FREE(pNewReqHdrInfo);
   */
  freeHdr(pReqHdrInfo);
  freeHdr(pNewReqHdrInfo);

  /* release hdrLoc */
  HANDLE_RELEASE(reqHdrBuf, INK_NULL_MLOC, reqHdrLoc);
  HANDLE_RELEASE(newHttpHdrBuf, INK_NULL_MLOC, newHttpHdrLoc);

  /* destroy hdr */
  HDR_DESTROY(newHttpHdrBuf, newHttpHdrLoc);

  /* destroy mbuffer */
  BUFFER_DESTROY(newHttpHdrBuf);


  if (INKHttpTxnReenable(pTxn, INK_EVENT_HTTP_CONTINUE) == INK_ERROR) {
    LOG_API_ERROR("INKHttpTxnReenable");
  }
  INKDebug(REQ, "..... exiting handleReadRequest ......\n");

}                               /* handleReadReadRequest */
Exemplo n.º 11
0
static void
handleSendResponse(INKCont pCont, INKHttpTxn pTxn)
{
  LOG_SET_FUNCTION_NAME("handleSendResponse");

  INKMBuffer respHdrBuf = NULL, newHttpHdrBuf = NULL, parseBuffer = NULL;
  INKMLoc respHttpHdrLoc = NULL, newHttpHdrLoc = NULL, parseHttpHdrLoc = NULL;

  INKHttpStatus oldHttpStatus, tmpHttpStatus;
  INKHttpType httpType;
  INKHttpParser httpRespParser = NULL;

  HdrInfo_T *pRespHdrInfo = NULL, *pNewRespHdrInfo = NULL;

  int iHttpHdrReasonLength, iOldHttpVersion, iTmpHttpVersion, iTmpHttpHdrReasonLength;
  const char *sHttpHdrReason = NULL, *sTmpHttpHdrReason = NULL, *pHttpParseStart = NULL, *pHttpParseEnd = NULL;
  char *sOldHttpReason = NULL;

  const char *sRespHdrStr1 =
    "HTTP/1.1 200 OK\r\nServer: Netscape-Enterprise/4.1\r\nDate: Tue, 31 Oct 2000 03:38:19 GMT\r\nContent-type: text/html\r\nAge: 3476\r\nContent-Length: 12440\r\nVia: HTTP/1.1 ts-sun14 (Traffic-Server/4.0.0 [cHs f ])\r\n\r\n";

  const char *sRespHdrStr2 =
    "HTTP/1.1 404 Not Found \r\nServer: Netscape-Enterprise/4.1\r\nDate: Tue, 31 Oct 2000 03:38:19 GMT\r\nContent-type: text/html\r\nAge: 3476\r\nContent-Length: 12440\r\nVia: HTTP/1.1 ts-sun24 (Traffic-Server/4.0.0 [cHs f ])\r\n\r\n";

  const char *sRespHdrStr3 =
    "HTTP/1.1 505 HTTP Version Not Supported \r\nServer: Netscape-Enterprise/4.1\r\nDate: Tue, 31 Oct 2000 03:38:19 GMT\r\nContent-type: text/html\r\nAge: 3476\r\nContent-Length: 12440\r\nVia: HTTP/1.1 ts-sun34 (Traffic-Server/4.0.0 [cHs f ])\r\n\r\n";



  pRespHdrInfo = initHdr();
  pNewRespHdrInfo = initHdr();

  INKDebug(RESP, ">>> handleSendResponse <<<<\n");

  /* Get Response Marshall Buffer */
  if (!INKHttpTxnClientRespGet(pTxn, &respHdrBuf, &respHttpHdrLoc)) {
    LOG_API_ERROR_COMMENT("INKHttpTxnClientReqGet", "ERROR: Can't retrieve client req hdr");
    goto done;
  }

#ifdef DEBUG
  negTesting(respHdrBuf, respHttpHdrLoc);
#endif

    /******* (1): Exercise all possible INK*GET and print the values **********/

  INKDebug(RESP, "--------------------------------");
  getHdrInfo(pRespHdrInfo, respHdrBuf, respHttpHdrLoc);
  printHttpHeader(respHdrBuf, respHttpHdrLoc, RESP, 1);

    /******* (2): Create a new header and check everything is copied correctly *********/

  INKDebug(RESP, "--------------------------------");

  if ((newHttpHdrBuf = INKMBufferCreate()) == INK_ERROR_PTR) {
    LOG_API_ERROR_COMMENT("INKMBufferCreate", "skipping to section(4)");
    goto resp_4;
  }

    /*** INKHttpHdrCreate ***/
  if ((newHttpHdrLoc = INKHttpHdrCreate(newHttpHdrBuf)) == INK_ERROR_PTR) {
    LOG_API_ERROR_COMMENT("INKMHTTPHdrCreate", "skipping to section(4)");
    goto resp_4;
  }

  /* Make sure the newly created HTTP header has INKHttpType value of INK_HTTP_TYPE_UNKNOWN */
  if ((httpType = INKHttpHdrTypeGet(newHttpHdrBuf, newHttpHdrLoc)) == INK_ERROR) {
    LOG_API_ERROR_COMMENT("INKMHTTPHdrCreate", "continuing");
  } else if (httpType != INK_HTTP_TYPE_UNKNOWN) {
    LOG_AUTO_ERROR("INKHttpHdrCreate", "Newly created hdr not of type INK_HTTP_TYPE_UNKNOWN");
  }


    /*** INKHttpHdrCopy ***/
  if (INKHttpHdrCopy(newHttpHdrBuf, newHttpHdrLoc, respHdrBuf, respHttpHdrLoc) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrCopy");
  }

  getHdrInfo(pNewRespHdrInfo, newHttpHdrBuf, newHttpHdrLoc);
  printHttpHeader(newHttpHdrBuf, newHttpHdrLoc, RESP, 2);

  if (!identical_hdr(pRespHdrInfo, pNewRespHdrInfo)) {
    LOG_AUTO_ERROR("INKHttpHdrCopy", "copy of the resp header not identical to the original");
  }

  /* Reuse:
   * newHttpHdrBuf, newHttHdrLoc */

    /******* (3): Now excercise some INK..SETs on the new header ********/
  INKDebug(RESP, "--------------------------------");

    /*** INKHttpHdrTypeSet ***/
  /* ERROR: 
   * 1. Setting type other than INK_HTTP_TYPE_UNKNOWN, INK_HTTP_TYPE_REQUEST, 
   * INK_HTTP_TYPE_RESPONSE, and,
   * 2. Setting the type twice.  The hdr type has been already set during INKHttpHdrCopy 
   * above, so setting it again is incorrect */
  if (INKHttpHdrTypeSet(newHttpHdrBuf, newHttpHdrLoc, INK_HTTP_TYPE_RESPONSE) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrTypeSet");
  }

    /*** INKHttpHdrReasonSet ***/
  /* save the original reason */
  if ((sHttpHdrReason = INKHttpHdrReasonGet(newHttpHdrBuf, newHttpHdrLoc, &iHttpHdrReasonLength))
      == INK_ERROR_PTR) {
    LOG_API_ERROR("INKHttpHdrReasonGet");
  } else {
    sOldHttpReason = INKstrndup(sHttpHdrReason, iHttpHdrReasonLength);
  }

  /* Note: 
   * INKHttpHdrReasonGet may return a NULL reason string (for e.g. I tried www.eyesong.8m.com).
   * Do NOT assume that INKstrndup always returns a null terminated string.  INKstrndup does 
   * not returns a NULL terminated string for a NULL ptr as i/p parameter.  It simply returns 
   * it backs. So functions like strlen() on the return value might cause TS to crash */


  if (INKHttpHdrReasonSet(newHttpHdrBuf, newHttpHdrLoc, "dummy reason", strlen("dummy reason")) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrReasonGet");
  } else {
    if ((sTmpHttpHdrReason = INKHttpHdrReasonGet(newHttpHdrBuf, newHttpHdrLoc, &iTmpHttpHdrReasonLength))
        == INK_ERROR_PTR) {
      LOG_API_ERROR("INKHttpHdrReasonGet");
    } else if (sTmpHttpHdrReason && strncmp(sTmpHttpHdrReason, "dummy reason", iTmpHttpHdrReasonLength)) {
      LOG_AUTO_ERROR("INKHttpHdrReasonSet/Get", "GET reason different from the SET reason");
    }
    STR_RELEASE(newHttpHdrBuf, newHttpHdrLoc, sTmpHttpHdrReason);
  }

    /*** INKHttpStatusSet ***/
  /* save the original value */
  if ((oldHttpStatus = INKHttpHdrStatusGet(newHttpHdrBuf, newHttpHdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrStatusGet");
  }

  /* change it to some unknown value */
  if (INKHttpHdrStatusSet(newHttpHdrBuf, newHttpHdrLoc, INK_HTTP_STATUS_NONE) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrStatusSet");
  } else if ((tmpHttpStatus = INKHttpHdrStatusGet(newHttpHdrBuf, newHttpHdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrStatusGet");
  } else if (tmpHttpStatus != INK_HTTP_STATUS_NONE) {
    LOG_AUTO_ERROR("INKHttpHdrStatusGet/Set", "GET status different from the SET status");
  }


    /*** INKHttpHdrVersionSet ***/
  /* get the original version */
  if ((iOldHttpVersion = INKHttpHdrVersionGet(newHttpHdrBuf, newHttpHdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrVersionGet");
  }

  /* change it to some unknown version */
  if (INKHttpHdrVersionSet(newHttpHdrBuf, newHttpHdrLoc, INK_HTTP_VERSION(10, 10)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrVersionSet");
  } else if ((iTmpHttpVersion = INKHttpHdrVersionGet(newHttpHdrBuf, newHttpHdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrVersionGet");
  } else if (INK_HTTP_MAJOR(iTmpHttpVersion) != 10 && INK_HTTP_MINOR(iTmpHttpVersion) != 10) {
    LOG_AUTO_ERROR("INKHttpHdrVersionSet", "GET version different from SET version");
  }

  printHttpHeader(newHttpHdrBuf, newHttpHdrLoc, RESP, 3);

  /* Restore the original values */

  /* Here we can't use strlen(sOldHttpReason) to set the length.  This would crash TS if 
   * sOldHttpReason happens to be NULL */
  if (INKHttpHdrReasonSet(newHttpHdrBuf, newHttpHdrLoc, sOldHttpReason, iHttpHdrReasonLength) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrReasonSet");
  }
  /*INKHttpHdrReasonSet (newHttpHdrBuf, newHttpHdrLoc, sOldHttpReason, strlen(sOldHttpReason)); */
  if (INKHttpHdrStatusSet(newHttpHdrBuf, newHttpHdrLoc, oldHttpStatus) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrStatusSet");
  }
  if (INKHttpHdrVersionSet(newHttpHdrBuf, newHttpHdrLoc, iOldHttpVersion) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrStatusSet");
  }

  if (!identical_hdr(pRespHdrInfo, pNewRespHdrInfo)) {
    LOG_AUTO_ERROR("INK..SET", "Hdr values not properly restored");
  }

  /* (3): clean-up */
  STR_RELEASE(newHttpHdrBuf, newHttpHdrLoc, sHttpHdrReason);
  FREE(sOldHttpReason);

resp_4:
    /******* (4): Now excercise some SETs on the response header ********/
  INKDebug(RESP, "--------------------------------");

    /*** INKHttpHdrReasonSet ***/
  /* save the original reason */
  if ((sHttpHdrReason = INKHttpHdrReasonGet(respHdrBuf, respHttpHdrLoc, &iHttpHdrReasonLength))
      == INK_ERROR_PTR) {
    LOG_API_ERROR("INKHttpHdrReasonGet");
  } else {
    sOldHttpReason = INKstrndup(sHttpHdrReason, iHttpHdrReasonLength);
  }

  /* change the reason phrase */
  if (INKHttpHdrReasonSet(respHdrBuf, respHttpHdrLoc, "dummy reason", strlen("dummy reason")) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrReasonSet");
  }

  if ((sTmpHttpHdrReason = INKHttpHdrReasonGet(respHdrBuf, respHttpHdrLoc, &iTmpHttpHdrReasonLength))
      == INK_ERROR_PTR) {
    LOG_API_ERROR("INKHttpHdrReasonGet");
  } else if (sTmpHttpHdrReason && strncmp(sTmpHttpHdrReason, "dummy reason", iTmpHttpHdrReasonLength)) {
    LOG_AUTO_ERROR("INKHttpHdrReasonSet/Get", "GET reason string different from SET reason");
  }
  STR_RELEASE(respHdrBuf, respHttpHdrLoc, sTmpHttpHdrReason);

    /*** INKHttpStatusSet ***/
  /* save the original value */
  if ((oldHttpStatus = INKHttpHdrStatusGet(respHdrBuf, respHttpHdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrStatusGet");
  }

  /* change it to some unknown value */
  if (INKHttpHdrStatusSet(respHdrBuf, respHttpHdrLoc, INK_HTTP_STATUS_NONE) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrStatusSet");
  } else if (INKHttpHdrStatusGet(respHdrBuf, respHttpHdrLoc) != INK_HTTP_STATUS_NONE) {
    LOG_AUTO_ERROR("INKHttpHdrStatusSet/GET", "GET status value different from SET status");
  }


    /*** INKHttpHdrTypeSet ***/
  /* ERROR: 
   * 1. Setting type other than INK_HTTP_TYPE_UNKNOWN, INK_HTTP_TYPE_REQUEST, 
   * INK_HTTP_TYPE_RESPONSE and,
   * 2. Setting the type twice.  The hdr type has been already set during INKHttpTxnClientRespGet
   * above, so setting it again should fail */
  if (INKHttpHdrTypeSet(respHdrBuf, respHttpHdrLoc, INK_HTTP_TYPE_RESPONSE) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrTypeSet");
  }
  if (INKHttpHdrTypeGet(respHdrBuf, respHttpHdrLoc) == INK_HTTP_TYPE_UNKNOWN) {
    LOG_AUTO_ERROR("INKHttpHdrTypeSet/Get", "respHdrBuf CAN be set to INK_HTTP_TYPE_UNKNOWN");
  }

    /*** INKHttpHdrVersionSet ***/
  /* get the original version */
  if ((iOldHttpVersion = INKHttpHdrVersionGet(respHdrBuf, respHttpHdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrVersionGet");
  }

  /* change it to some unknown version */
  if (INKHttpHdrVersionSet(respHdrBuf, respHttpHdrLoc, INK_HTTP_VERSION(10, 10)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrVersionSet");
  } else if ((iTmpHttpVersion = INKHttpHdrVersionGet(respHdrBuf, respHttpHdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrVersionGet");
  } else if (INK_HTTP_MAJOR(iTmpHttpVersion) != 10 && INK_HTTP_MINOR(iTmpHttpVersion) != 10) {
    LOG_AUTO_ERROR("INKHttpHdrVersionGet/Set", "GET HTTP version different from SET version");
  }

  printHttpHeader(respHdrBuf, respHttpHdrLoc, RESP, 4);

  /* restore the original values */

  /* For INKHttpHdrReasonSet, do NOT use strlen(sOldHttpReason) to set the length.  
   * This would crash TS if sOldHttpReason happened to be NULL */
  if (INKHttpHdrReasonSet(respHdrBuf, respHttpHdrLoc, sOldHttpReason, iHttpHdrReasonLength) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrReasonSet");
  }
  /*INKHttpHdrReasonSet (respHdrBuf, respHttpHdrLoc, sOldHttpReason, strlen(sOldHttpReason)); */
  if (INKHttpHdrStatusSet(respHdrBuf, respHttpHdrLoc, oldHttpStatus) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrStatusSet");
  }
  if (INKHttpHdrVersionSet(respHdrBuf, respHttpHdrLoc, iOldHttpVersion) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrVersionSet");
  }

  FREE(pNewRespHdrInfo->hdrReason);
  getHdrInfo(pNewRespHdrInfo, respHdrBuf, respHttpHdrLoc);

  if (!identical_hdr(pRespHdrInfo, pNewRespHdrInfo)) {
    LOG_AUTO_ERROR("INK..SET", "Hdr values not properly restored");
  }

  /* (4): clean-up */
  STR_RELEASE(respHdrBuf, respHttpHdrLoc, sHttpHdrReason);
  FREE(sOldHttpReason);

    /********************************/
    /** (5): INKHttpHdrParseResp   **/
    /********************************/

  INKDebug(RESP, "--------------------------------");

  /* Create a parser Buffer and header location */
  if ((parseBuffer = INKMBufferCreate()) == INK_ERROR_PTR || parseBuffer == NULL) {
    LOG_API_ERROR_COMMENT("INKMBufferCreate", "abnormal exit");
    goto done;
  } else if ((parseHttpHdrLoc = INKHttpHdrCreate(parseBuffer)) == INK_ERROR_PTR || parseHttpHdrLoc == NULL) {
    LOG_API_ERROR_COMMENT("INKHttpHdrCreate", "abnormal exit");
    goto done;
  }

  pHttpParseStart = sRespHdrStr1;
  pHttpParseEnd = pHttpParseStart + strlen(pHttpParseStart);

  httpRespParser = INKHttpParserCreate();

  if (INKHttpHdrParseResp(httpRespParser, parseBuffer, parseHttpHdrLoc, &pHttpParseStart, pHttpParseEnd)
      == INK_PARSE_ERROR) {
    LOG_API_ERROR("INKHttpHdrParseResp");
  }

  printHttpHeader(parseBuffer, parseHttpHdrLoc, RESP, 5.1);

  if (INKHttpParserClear(httpRespParser) == INK_ERROR) {
    LOG_API_ERROR("INKHttpParseClear");
  }

  INKDebug(RESP, "--------------------------------");

  pHttpParseStart = sRespHdrStr2;
  pHttpParseEnd = pHttpParseStart + strlen(pHttpParseStart);

  /* httpRespParser = INKHttpParserCreate(); */

  if (INKHttpHdrParseResp(httpRespParser, parseBuffer, parseHttpHdrLoc, &pHttpParseStart, pHttpParseEnd)
      == INK_PARSE_ERROR) {
    LOG_API_ERROR("INKHttpHdrParseResp");
  }

  printHttpHeader(parseBuffer, parseHttpHdrLoc, RESP, 5.2);

  if (INKHttpParserClear(httpRespParser) == INK_ERROR) {
    LOG_API_ERROR("INKHttpParseClear");
  }

  INKDebug(RESP, "--------------------------------");

  pHttpParseStart = sRespHdrStr3;
  pHttpParseEnd = pHttpParseStart + strlen(pHttpParseStart);

  /* httpRespParser = INKHttpParserCreate(); */

  if (INKHttpHdrParseResp(httpRespParser, parseBuffer, parseHttpHdrLoc, &pHttpParseStart, pHttpParseEnd)
      == INK_PARSE_ERROR) {
    LOG_API_ERROR("INKHttpHdrParseResp");
  }

  printHttpHeader(parseBuffer, parseHttpHdrLoc, RESP, 5.3);


done:
  /* Clean-up */
  freeHdr(pRespHdrInfo);
  freeHdr(pNewRespHdrInfo);

  /* release hdrLoc */
  HANDLE_RELEASE(respHdrBuf, INK_NULL_MLOC, respHttpHdrLoc);
  HANDLE_RELEASE(newHttpHdrBuf, INK_NULL_MLOC, newHttpHdrLoc);
  HANDLE_RELEASE(parseBuffer, INK_NULL_MLOC, parseHttpHdrLoc);

  /* destroy hdrLoc */
  HDR_DESTROY(respHdrBuf, respHttpHdrLoc);
  HDR_DESTROY(parseBuffer, parseHttpHdrLoc);

  /* destroy mbuffer */
  BUFFER_DESTROY(newHttpHdrBuf);
  BUFFER_DESTROY(parseBuffer);

  /* destroy the parser */
  if (INKHttpParserDestroy(httpRespParser) == INK_ERROR) {
    LOG_API_ERROR("INKHttpParserDestroy");
  }

  if (INKHttpTxnReenable(pTxn, INK_EVENT_HTTP_CONTINUE) == INK_ERROR) {
    LOG_API_ERROR("INKHttpTxnReenable");
  }

  INKDebug(RESP, "......... exiting handleRespResponse .............\n");

}                               /* handleSendResponse */
Exemplo n.º 12
0
static void
printHttpHeader(INKMBuffer hdrBuf, INKMLoc hdrLoc, char *debugTag, float section)
{
  LOG_SET_FUNCTION_NAME("printHttpHeader");

  INKMLoc urlLoc = NULL;

  INKHttpStatus httpStatus;
  INKHttpType httpType;

  int iHostLength, iHttpHdrLength, iHttpMethodLength, iHttpHdrReasonLength, iHttpVersion;
  const char *sHostName = NULL, *sHttpMethod = NULL, *sHttpHdrReason = NULL;
  char *outputString = NULL;


    /*** INKHttpHdrTypeGet ***/
  if ((httpType = INKHttpHdrTypeGet(hdrBuf, hdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrTypeGet");
  }
  INKDebug(debugTag, "(%g) HTTP Header Type = %d", section, httpType);

    /*** INKHttpHdrLengthGet ***/
  if ((iHttpHdrLength = INKHttpHdrLengthGet(hdrBuf, hdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrLengthGet");
  }
  INKDebug(debugTag, "(%g) HTTP Header Length = %d", section, iHttpHdrLength);

    /*** INKHttpVersionGet ***/
  if ((iHttpVersion = INKHttpHdrVersionGet(hdrBuf, hdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrVersionGet");
  }
  INKDebug(debugTag, "(%g) HTTP Header Version = %d", section, iHttpVersion);
  INKDebug(debugTag, "(%g) Major Version = %d, Minor Version = %d", section,
           INK_HTTP_MAJOR(iHttpVersion), INK_HTTP_MINOR(iHttpVersion));


  if (httpType == INK_HTTP_TYPE_REQUEST) {
        /*** INKHttpHdrMethodGet ***/
    if ((sHttpMethod = INKHttpHdrMethodGet(hdrBuf, hdrLoc, &iHttpMethodLength)) == INK_ERROR_PTR) {
      LOG_API_ERROR("INKHttpHdrMethodGet");
    } else {
      outputString = INKstrndup(sHttpMethod, iHttpMethodLength);
      INKDebug(debugTag, "(%g) HTTP Header Method = %s", section, outputString);
      FREE(outputString);
      STR_RELEASE(hdrBuf, urlLoc, sHttpMethod);
    }

        /*** INKHttpHdrUrlGet ***/
    if ((urlLoc = INKHttpHdrUrlGet(hdrBuf, hdrLoc)) == INK_ERROR_PTR) {
      LOG_API_ERROR("INKHttpHdrUrlGet");
    } else if ((sHostName = INKUrlHostGet(hdrBuf, urlLoc, &iHostLength)) == INK_ERROR_PTR) {
      LOG_API_ERROR("INKUrlHostGet");
    } else if (sHostName) {
      outputString = INKstrndup(sHostName, iHostLength);
      INKDebug(debugTag, "(%g) HTTP Host = %s", section, outputString);
      FREE(outputString);
      STR_RELEASE(hdrBuf, urlLoc, sHostName);
    }

    /* Clean-up */
    HANDLE_RELEASE(hdrBuf, hdrLoc, urlLoc);

  } else if (httpType == INK_HTTP_TYPE_RESPONSE) {

        /*** INKHttpHdrReasonGet ***/
    /* Try getting reason phrase from the request header - this is an error */
    if ((sHttpHdrReason = INKHttpHdrReasonGet(hdrBuf, hdrLoc, &iHttpHdrReasonLength)) == INK_ERROR_PTR) {
      LOG_API_ERROR("INKHttpHdrReasonGet");
    } else {
      outputString = INKstrndup(sHttpHdrReason, iHttpHdrReasonLength);
      INKDebug(debugTag, "(%g) HTTP Header Reason = %s", section, outputString);
      FREE(outputString);
      STR_RELEASE(hdrBuf, hdrLoc, sHttpHdrReason);
    }

        /*** INKHttpHdrStatusGet ***/
    /* Try getting status phrase from the request header - this is an error */
    if ((httpStatus = INKHttpHdrStatusGet(hdrBuf, hdrLoc)) == INK_ERROR) {
      LOG_API_ERROR("INKHttpHdrStatusGet");
    } else {
      INKDebug(debugTag, "(%g) HTTP Header Status = %d", section, httpStatus);
    }
  }
}
Exemplo n.º 13
0
void
negTesting(INKMBuffer hdrBuf, INKMLoc httpHdrLoc)
{
  LOG_SET_FUNCTION_NAME("negTesting");

  INKMBuffer negHdrBuf = NULL;
  INKMLoc negHttpHdrLoc = NULL;

  INKHttpType negType, hdrHttpType;
  INKHttpStatus httpStatus;

  const char *sHttpReason = NULL;
  int iHttpMethodLength, iHttpHdrReasonLength;

  /* INKMBufferCreate: Nothing to neg test */

  /* INKMBufferDestroy */
  if (INKMBufferDestroy(NULL) != INK_ERROR) {
    LOG_NEG_ERROR("INKMBufferDestroy");
  }

  /* INKHttpHdrCreate */
  if (INKHttpHdrCreate(NULL) != INK_ERROR_PTR) {
    LOG_NEG_ERROR("INKHttpHdrCreate");
  }

  /* INKHttpHdrCopy */
  /* Copy w/o creating the hdrBuf and httpHdrLoc */
  if (INKHttpHdrCopy(negHdrBuf, negHttpHdrLoc, hdrBuf, httpHdrLoc) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrCopy");
  }

  /* valid create */
  if ((negHdrBuf = INKMBufferCreate()) == INK_ERROR_PTR) {
    LOG_API_ERROR("INKHttpHdrCreate");
  }
  if ((negHttpHdrLoc = INKHttpHdrCreate(negHdrBuf)) == INK_ERROR_PTR) {
    LOG_API_ERROR("INKMHttpHdrCreate");
  }

  if (INKHttpHdrCopy(NULL, negHttpHdrLoc, hdrBuf, httpHdrLoc) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrCopy");
  }
  if (INKHttpHdrCopy(negHdrBuf, NULL, hdrBuf, httpHdrLoc) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrCopy");
  }
  if (INKHttpHdrCopy(negHdrBuf, negHttpHdrLoc, NULL, httpHdrLoc) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrCopy");
  }
  if (INKHttpHdrCopy(negHdrBuf, negHttpHdrLoc, hdrBuf, NULL) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrCopy");
  }

  /* INKHttpHdrTypeSet */
  /* Docs - INKHttpHdrTypeSet should NOT be called after INKHttpHdrCopy */
  /* Try some incorrect (but valid int type) arguments */
  if (INKHttpHdrTypeSet(negHdrBuf, negHttpHdrLoc, 10) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrTypeSet");
  }
  if (INKHttpHdrTypeSet(negHdrBuf, negHttpHdrLoc, -1) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrTypeSet");
  }

  if (INKHttpHdrTypeSet(NULL, negHttpHdrLoc, INK_HTTP_TYPE_RESPONSE) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrTypeSet");
  }
  if (INKHttpHdrTypeSet(negHdrBuf, NULL, INK_HTTP_TYPE_RESPONSE) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrTypeSet");
  }
  /* INKqa12708 */
  if (INKHttpHdrTypeSet(negHdrBuf, negHttpHdrLoc, 100) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrTypeSet");
  }


  /* INKHtttpHdrTypeGet */
  if ((negType = INKHttpHdrTypeGet(NULL, negHttpHdrLoc)) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrTypeGet");
  }
  if ((negType = INKHttpHdrTypeGet(negHdrBuf, NULL)) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrTypeGet");
  }

  /* INKHttpHdrVersionGet */
  if (INKHttpHdrVersionGet(NULL, negHttpHdrLoc) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrVersionGet");
  }
  if (INKHttpHdrVersionGet(negHdrBuf, NULL) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrVersionGet");
  }

  /* INKHttpHdrVersionSet */
  if (INKHttpHdrVersionSet(NULL, negHttpHdrLoc, INK_HTTP_VERSION(1, 1)) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrVersionSet");
  }
  if (INKHttpHdrVersionSet(negHdrBuf, NULL, INK_HTTP_VERSION(1, 1)) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrVersionSet");
  }
  /* Try some incorrect (but valid int type) arguments */
  if (INKHttpHdrVersionSet(negHdrBuf, negHttpHdrLoc, 0) == INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrVersionSet");
  }
  if (INKHttpHdrVersionSet(negHdrBuf, negHttpHdrLoc, -1) == INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrVersionSet");
  }

  /* INKHttpHdrLengthGet */
  if (INKHttpHdrLengthGet(NULL, negHttpHdrLoc) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrLengthGet");
  }
  if (INKHttpHdrLengthGet(negHdrBuf, NULL) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrLengthGet");
  }

  /* valid copy */
  if (INKHttpHdrCopy(negHdrBuf, negHttpHdrLoc, hdrBuf, httpHdrLoc) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrCopy");
  }

  if ((hdrHttpType = INKHttpHdrTypeGet(negHdrBuf, negHttpHdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrTypeGet");
  }

  if (hdrHttpType == INK_HTTP_TYPE_REQUEST) {
    /* INKHttpHdrUrlGet */
    if (INKHttpHdrUrlGet(NULL, negHttpHdrLoc) != INK_ERROR_PTR) {
      LOG_NEG_ERROR("INKHttpHdrUrlGet");
    }
    if (INKHttpHdrUrlGet(negHdrBuf, NULL) != INK_ERROR_PTR) {
      LOG_NEG_ERROR("INKHttpHdrUrlGet");
    }

    /* INKHttpHdrMethodGet */
    if (INKHttpHdrMethodGet(NULL, negHttpHdrLoc, &iHttpMethodLength) != INK_ERROR_PTR) {
      LOG_NEG_ERROR("INKHttpHdrMethodGet");
    }
    if (INKHttpHdrMethodGet(negHdrBuf, NULL, &iHttpMethodLength) != INK_ERROR_PTR) {
      LOG_NEG_ERROR("INKHttpHdrMethodGet");
    }
    if (INKHttpHdrMethodGet(negHdrBuf, negHttpHdrLoc, NULL) == INK_ERROR_PTR) {
      LOG_NEG_ERROR("INKHttpHdrMethodGet");
    }

    /* INKHttpHdrMethodSet */
    if (INKHttpHdrMethodSet(NULL, negHttpHdrLoc, "FOOBAR", strlen("FOOBAR")) != INK_ERROR) {
      LOG_NEG_ERROR("INKHttpHdrMethodSet");
    }
    if (INKHttpHdrMethodSet(negHdrBuf, NULL, "FOOBAR", strlen("FOOBAR")) != INK_ERROR) {
      LOG_NEG_ERROR("INKHttpHdrMethodSet");
    }
    /* INKqa12722 */
    if (INKHttpHdrMethodSet(negHdrBuf, negHttpHdrLoc, NULL, -1) != INK_ERROR) {
      LOG_NEG_ERROR("INKHttpHdrMethodSet");
    }
    /* FIXME:  This neg test would crash TS */
    /* NOTE: This is a valid (corner) test case */
    if (INKHttpHdrMethodSet(negHdrBuf, negHttpHdrLoc, "", -1) == INK_ERROR) {
      LOG_NEG_ERROR("INKHttpHdrMethodSet");
    }

  } else if (hdrHttpType == INK_HTTP_TYPE_RESPONSE) {

    /* INKHttpHdrStatusGet */
    if (INKHttpHdrStatusGet(NULL, negHttpHdrLoc) != INK_ERROR) {
      LOG_NEG_ERROR("INKHttpHdrStatusGet");
    }
    if (INKHttpHdrStatusGet(negHdrBuf, NULL) != INK_ERROR) {
      LOG_NEG_ERROR("INKHttpHdrStatusGet");
    }

    /* INKHttpHdrStatusSet */
    /* valid status get */
    if ((httpStatus = INKHttpHdrStatusGet(negHdrBuf, negHttpHdrLoc)) == INK_ERROR) {
      LOG_API_ERROR("INKHttpHdrStatusGet");
    }

    if (INKHttpHdrStatusSet(NULL, negHttpHdrLoc, httpStatus) != INK_ERROR) {
      LOG_NEG_ERROR("INKHttpHdrStatusSet");
    }
    if (INKHttpHdrStatusSet(negHdrBuf, NULL, httpStatus) != INK_ERROR) {
      LOG_NEG_ERROR("INKHttpHdrStatusSet");
    }
    /* setting status = NULL is NOT an error */
    if (INKHttpHdrStatusSet(negHdrBuf, negHttpHdrLoc, -1) == INK_ERROR) {
      LOG_NEG_ERROR("INKHttpHdrStatusSet");
    }

    /* INKHttpHdrReasonGet */
    /* valid reason get */
    if ((sHttpReason = INKHttpHdrReasonGet(negHdrBuf, negHttpHdrLoc, &iHttpHdrReasonLength))
        == INK_ERROR_PTR) {
      LOG_API_ERROR("INKHttpHdrReasonGet");
    }

    if (INKHttpHdrReasonGet(NULL, negHttpHdrLoc, &iHttpHdrReasonLength) != INK_ERROR_PTR) {
      LOG_NEG_ERROR("INKHttpHdrReasonGet");
    }
    if (INKHttpHdrReasonGet(negHdrBuf, NULL, &iHttpHdrReasonLength) != INK_ERROR_PTR) {
      LOG_NEG_ERROR("INKHttpHdrReasonGet");
    }
    /* NULL is a valid length arg */
    if (INKHttpHdrReasonGet(negHdrBuf, negHttpHdrLoc, NULL) == INK_ERROR_PTR) {
      LOG_NEG_ERROR("INKHttpHdrReasonGet");
    }

    /* INKHttpHdrReasonSet */
    if (INKHttpHdrReasonSet(NULL, negHttpHdrLoc, sHttpReason, iHttpHdrReasonLength) != INK_ERROR) {
      LOG_NEG_ERROR("INKHttpHdrReasonSet");
    }
    if (INKHttpHdrReasonSet(negHdrBuf, NULL, sHttpReason, iHttpHdrReasonLength) != INK_ERROR) {
      LOG_NEG_ERROR("INKHttpHdrReasonSet");
    }

    /* NOTE: INKqa12722: NULL reason arg fixed now */
    if (INKHttpHdrReasonSet(negHdrBuf, negHttpHdrLoc, NULL, iHttpHdrReasonLength) != INK_ERROR) {
      LOG_NEG_ERROR("INKHttpHdrReasonSet");
    }
    /* FIXME: INKqa12722 - This neg test would crash TS */
    if (INKHttpHdrReasonSet(negHdrBuf, negHttpHdrLoc, NULL, -1) != INK_ERROR) {
      LOG_NEG_ERROR("INKHttpHdrReasonSet");
    }

    STR_RELEASE(negHdrBuf, negHttpHdrLoc, sHttpReason);
  }

  /* Clean-up */
  HANDLE_RELEASE(negHdrBuf, INK_NULL_MLOC, negHttpHdrLoc);
  BUFFER_DESTROY(negHdrBuf);
}
Exemplo n.º 14
0
PHPAPI int php_var_unserialize(UNSERIALIZE_PARAMETER)
{
	const unsigned char *cursor, *limit, *marker, *start;
	zval *rval_ref;

	limit = max;
	cursor = *p;
	
	if (YYCURSOR >= YYLIMIT) {
		return 0;
	}
	
	if (var_hash && (*p)[0] != 'R') {
		var_push(var_hash, rval);
	}

	start = cursor;


#line 485 "ext/standard/var_unserializer.c"
{
	YYCTYPE yych;
	static const unsigned char yybm[] = {
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		128, 128, 128, 128, 128, 128, 128, 128, 
		128, 128,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
	};

	if ((YYLIMIT - YYCURSOR) < 7) YYFILL(7);
	yych = *YYCURSOR;
	switch (yych) {
	case 'C':
	case 'O':	goto yy13;
	case 'N':	goto yy5;
	case 'R':	goto yy2;
	case 'S':	goto yy10;
	case 'a':	goto yy11;
	case 'b':	goto yy6;
	case 'd':	goto yy8;
	case 'i':	goto yy7;
	case 'o':	goto yy12;
	case 'r':	goto yy4;
	case 's':	goto yy9;
	case '}':	goto yy14;
	default:	goto yy16;
	}
yy2:
	yych = *(YYMARKER = ++YYCURSOR);
	if (yych == ':') goto yy95;
yy3:
#line 826 "ext/standard/var_unserializer.re"
	{ return 0; }
#line 547 "ext/standard/var_unserializer.c"
yy4:
	yych = *(YYMARKER = ++YYCURSOR);
	if (yych == ':') goto yy89;
	goto yy3;
yy5:
	yych = *++YYCURSOR;
	if (yych == ';') goto yy87;
	goto yy3;
yy6:
	yych = *(YYMARKER = ++YYCURSOR);
	if (yych == ':') goto yy83;
	goto yy3;
yy7:
	yych = *(YYMARKER = ++YYCURSOR);
	if (yych == ':') goto yy77;
	goto yy3;
yy8:
	yych = *(YYMARKER = ++YYCURSOR);
	if (yych == ':') goto yy53;
	goto yy3;
yy9:
	yych = *(YYMARKER = ++YYCURSOR);
	if (yych == ':') goto yy46;
	goto yy3;
yy10:
	yych = *(YYMARKER = ++YYCURSOR);
	if (yych == ':') goto yy39;
	goto yy3;
yy11:
	yych = *(YYMARKER = ++YYCURSOR);
	if (yych == ':') goto yy32;
	goto yy3;
yy12:
	yych = *(YYMARKER = ++YYCURSOR);
	if (yych == ':') goto yy25;
	goto yy3;
yy13:
	yych = *(YYMARKER = ++YYCURSOR);
	if (yych == ':') goto yy17;
	goto yy3;
yy14:
	++YYCURSOR;
#line 820 "ext/standard/var_unserializer.re"
	{
	/* this is the case where we have less data than planned */
	php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unexpected end of serialized data");
	return 0; /* not sure if it should be 0 or 1 here? */
}
#line 596 "ext/standard/var_unserializer.c"
yy16:
	yych = *++YYCURSOR;
	goto yy3;
yy17:
	yych = *++YYCURSOR;
	if (yybm[0+yych] & 128) {
		goto yy20;
	}
	if (yych == '+') goto yy19;
yy18:
	YYCURSOR = YYMARKER;
	goto yy3;
yy19:
	yych = *++YYCURSOR;
	if (yybm[0+yych] & 128) {
		goto yy20;
	}
	goto yy18;
yy20:
	++YYCURSOR;
	if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
	yych = *YYCURSOR;
	if (yybm[0+yych] & 128) {
		goto yy20;
	}
	if (yych != ':') goto yy18;
	yych = *++YYCURSOR;
	if (yych != '"') goto yy18;
	++YYCURSOR;
#line 681 "ext/standard/var_unserializer.re"
	{
	size_t len, len2, len3, maxlen;
	long elements;
	char *str;
	zend_string *class_name;
	zend_class_entry *ce;
	int incomplete_class = 0;

	int custom_object = 0;

	zval user_func;
	zval retval;
	zval args[1];

	if (*start == 'C') {
		custom_object = 1;
	}
	
//???	INIT_PZVAL(rval);
	len2 = len = parse_uiv(start + 2);
	maxlen = max - YYCURSOR;
	if (maxlen < len || len == 0) {
		*p = start + 2;
		return 0;
	}

	str = (char*)YYCURSOR;

	YYCURSOR += len;

	if (*(YYCURSOR) != '"') {
		*p = YYCURSOR;
		return 0;
	}
	if (*(YYCURSOR+1) != ':') {
		*p = YYCURSOR+1;
		return 0;
	}

	len3 = strspn(str, "0123456789_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377\\");
	if (len3 != len)
	{
		*p = YYCURSOR + len3 - len;
		return 0;
	}

	class_name = STR_INIT(str, len, 0);

	do {
		/* Try to find class directly */
		BG(serialize_lock)++;
		ce = zend_lookup_class(class_name TSRMLS_CC);
		if (ce) {
			BG(serialize_lock)--;
			if (EG(exception)) {
				STR_RELEASE(class_name);
				return 0;
			}
			break;
		}
		BG(serialize_lock)--;

		if (EG(exception)) {
			STR_RELEASE(class_name);
			return 0;
		}
		
		/* Check for unserialize callback */
		if ((PG(unserialize_callback_func) == NULL) || (PG(unserialize_callback_func)[0] == '\0')) {
			incomplete_class = 1;
			ce = PHP_IC_ENTRY;
			break;
		}
		
		/* Call unserialize callback */
		ZVAL_STRING(&user_func, PG(unserialize_callback_func));
		
		ZVAL_STR(&args[0], STR_COPY(class_name));
		BG(serialize_lock)++;
		if (call_user_function_ex(CG(function_table), NULL, &user_func, &retval, 1, args, 0, NULL TSRMLS_CC) != SUCCESS) {
			BG(serialize_lock)--;
			if (EG(exception)) {
				STR_RELEASE(class_name);
				zval_ptr_dtor(&user_func);
				zval_ptr_dtor(&args[0]);
				return 0;
			}
			php_error_docref(NULL TSRMLS_CC, E_WARNING, "defined (%s) but not found", Z_STRVAL(user_func));
			incomplete_class = 1;
			ce = PHP_IC_ENTRY;
			zval_ptr_dtor(&user_func);
			zval_ptr_dtor(&args[0]);
			break;
		}
		BG(serialize_lock)--;
		zval_ptr_dtor(&retval);
		if (EG(exception)) {
			STR_RELEASE(class_name);
			zval_ptr_dtor(&user_func);
			zval_ptr_dtor(&args[0]);
			return 0;
		}
		
		/* The callback function may have defined the class */
		if ((ce = zend_lookup_class(class_name TSRMLS_CC)) == NULL) {
			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Function %s() hasn't defined the class it was called for", Z_STRVAL(user_func));
			incomplete_class = 1;
			ce = PHP_IC_ENTRY;
		}

		zval_ptr_dtor(&user_func);
		zval_ptr_dtor(&args[0]);
		break;
	} while (1);

	*p = YYCURSOR;

	if (custom_object) {
		int ret;

		ret = object_custom(UNSERIALIZE_PASSTHRU, ce);

		if (ret && incomplete_class) {
			php_store_class_name(rval, class_name->val, len2);
		}
		STR_RELEASE(class_name);
		return ret;
	}
	
	elements = object_common1(UNSERIALIZE_PASSTHRU, ce);

	if (incomplete_class) {
		php_store_class_name(rval, class_name->val, len2);
	}
	STR_RELEASE(class_name);

	return object_common2(UNSERIALIZE_PASSTHRU, elements);
}
#line 765 "ext/standard/var_unserializer.c"
yy25:
	yych = *++YYCURSOR;
	if (yych <= ',') {
		if (yych != '+') goto yy18;
	} else {
		if (yych <= '-') goto yy26;
		if (yych <= '/') goto yy18;
		if (yych <= '9') goto yy27;
		goto yy18;
	}
yy26:
	yych = *++YYCURSOR;
	if (yych <= '/') goto yy18;
	if (yych >= ':') goto yy18;
yy27:
	++YYCURSOR;
	if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
	yych = *YYCURSOR;
	if (yych <= '/') goto yy18;
	if (yych <= '9') goto yy27;
	if (yych >= ';') goto yy18;
	yych = *++YYCURSOR;
	if (yych != '"') goto yy18;
	++YYCURSOR;
#line 673 "ext/standard/var_unserializer.re"
	{

//???	INIT_PZVAL(rval);
	
	return object_common2(UNSERIALIZE_PASSTHRU,
			object_common1(UNSERIALIZE_PASSTHRU, ZEND_STANDARD_CLASS_DEF_PTR));
}
#line 798 "ext/standard/var_unserializer.c"
yy32:
	yych = *++YYCURSOR;
	if (yych == '+') goto yy33;
	if (yych <= '/') goto yy18;
	if (yych <= '9') goto yy34;
	goto yy18;
yy33:
	yych = *++YYCURSOR;
	if (yych <= '/') goto yy18;
	if (yych >= ':') goto yy18;
yy34:
	++YYCURSOR;
	if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
	yych = *YYCURSOR;
	if (yych <= '/') goto yy18;
	if (yych <= '9') goto yy34;
	if (yych >= ';') goto yy18;
	yych = *++YYCURSOR;
	if (yych != '{') goto yy18;
	++YYCURSOR;
#line 652 "ext/standard/var_unserializer.re"
	{
	long elements = parse_iv(start + 2);
	/* use iv() not uiv() in order to check data range */
	*p = YYCURSOR;

	if (elements < 0) {
		return 0;
	}

	array_init_size(rval, elements);
//??? we can't convert from packed to hash during unserialization, becaue
//??? reference to some zvals might be keept in var_hash (to support references)
	zend_hash_real_init(Z_ARRVAL_P(rval), 0);

	if (!process_nested_data(UNSERIALIZE_PASSTHRU, Z_ARRVAL_P(rval), elements, 0)) {
		return 0;
	}

	return finish_nested_data(UNSERIALIZE_PASSTHRU);
}
#line 840 "ext/standard/var_unserializer.c"
yy39:
	yych = *++YYCURSOR;
	if (yych == '+') goto yy40;
	if (yych <= '/') goto yy18;
	if (yych <= '9') goto yy41;
	goto yy18;
yy40:
	yych = *++YYCURSOR;
	if (yych <= '/') goto yy18;
	if (yych >= ':') goto yy18;
yy41:
	++YYCURSOR;
	if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
	yych = *YYCURSOR;
	if (yych <= '/') goto yy18;
	if (yych <= '9') goto yy41;
	if (yych >= ';') goto yy18;
	yych = *++YYCURSOR;
	if (yych != '"') goto yy18;
	++YYCURSOR;
#line 624 "ext/standard/var_unserializer.re"
	{
	size_t len, maxlen;
	zend_string *str;

	len = parse_uiv(start + 2);
	maxlen = max - YYCURSOR;
	if (maxlen < len) {
		*p = start + 2;
		return 0;
	}

	if ((str = unserialize_str(&YYCURSOR, len, maxlen)) == NULL) {
		return 0;
	}

	if (*(YYCURSOR) != '"') {
		STR_FREE(str);
		*p = YYCURSOR;
		return 0;
	}

	YYCURSOR += 2;
	*p = YYCURSOR;

	ZVAL_STR(rval, str);
	return 1;
}
#line 889 "ext/standard/var_unserializer.c"
yy46:
	yych = *++YYCURSOR;
	if (yych == '+') goto yy47;
	if (yych <= '/') goto yy18;
	if (yych <= '9') goto yy48;
	goto yy18;
yy47:
	yych = *++YYCURSOR;
	if (yych <= '/') goto yy18;
	if (yych >= ':') goto yy18;
yy48:
	++YYCURSOR;
	if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
	yych = *YYCURSOR;
	if (yych <= '/') goto yy18;
	if (yych <= '9') goto yy48;
	if (yych >= ';') goto yy18;
	yych = *++YYCURSOR;
	if (yych != '"') goto yy18;
	++YYCURSOR;
#line 597 "ext/standard/var_unserializer.re"
	{
	size_t len, maxlen;
	char *str;

	len = parse_uiv(start + 2);
	maxlen = max - YYCURSOR;
	if (maxlen < len) {
		*p = start + 2;
		return 0;
	}

	str = (char*)YYCURSOR;

	YYCURSOR += len;

	if (*(YYCURSOR) != '"') {
		*p = YYCURSOR;
		return 0;
	}

	YYCURSOR += 2;
	*p = YYCURSOR;

	ZVAL_STRINGL(rval, str, len);
	return 1;
}
#line 937 "ext/standard/var_unserializer.c"
yy53:
	yych = *++YYCURSOR;
	if (yych <= '/') {
		if (yych <= ',') {
			if (yych == '+') goto yy57;
			goto yy18;
		} else {
			if (yych <= '-') goto yy55;
			if (yych <= '.') goto yy60;
			goto yy18;
		}
	} else {
		if (yych <= 'I') {
			if (yych <= '9') goto yy58;
			if (yych <= 'H') goto yy18;
			goto yy56;
		} else {
			if (yych != 'N') goto yy18;
		}
	}
	yych = *++YYCURSOR;
	if (yych == 'A') goto yy76;
	goto yy18;
yy55:
	yych = *++YYCURSOR;
	if (yych <= '/') {
		if (yych == '.') goto yy60;
		goto yy18;
	} else {
		if (yych <= '9') goto yy58;
		if (yych != 'I') goto yy18;
	}
yy56:
	yych = *++YYCURSOR;
	if (yych == 'N') goto yy72;
	goto yy18;
yy57:
	yych = *++YYCURSOR;
	if (yych == '.') goto yy60;
	if (yych <= '/') goto yy18;
	if (yych >= ':') goto yy18;
yy58:
	++YYCURSOR;
	if ((YYLIMIT - YYCURSOR) < 4) YYFILL(4);
	yych = *YYCURSOR;
	if (yych <= ':') {
		if (yych <= '.') {
			if (yych <= '-') goto yy18;
			goto yy70;
		} else {
			if (yych <= '/') goto yy18;
			if (yych <= '9') goto yy58;
			goto yy18;
		}
	} else {
		if (yych <= 'E') {
			if (yych <= ';') goto yy63;
			if (yych <= 'D') goto yy18;
			goto yy65;
		} else {
			if (yych == 'e') goto yy65;
			goto yy18;
		}
	}
yy60:
	yych = *++YYCURSOR;
	if (yych <= '/') goto yy18;
	if (yych >= ':') goto yy18;
yy61:
	++YYCURSOR;
	if ((YYLIMIT - YYCURSOR) < 4) YYFILL(4);
	yych = *YYCURSOR;
	if (yych <= ';') {
		if (yych <= '/') goto yy18;
		if (yych <= '9') goto yy61;
		if (yych <= ':') goto yy18;
	} else {
		if (yych <= 'E') {
			if (yych <= 'D') goto yy18;
			goto yy65;
		} else {
			if (yych == 'e') goto yy65;
			goto yy18;
		}
	}
yy63:
	++YYCURSOR;
#line 588 "ext/standard/var_unserializer.re"
	{
#if SIZEOF_LONG == 4
use_double:
#endif
	*p = YYCURSOR;
	ZVAL_DOUBLE(rval, zend_strtod((const char *)start + 2, NULL));
	return 1;
}
#line 1034 "ext/standard/var_unserializer.c"
yy65:
	yych = *++YYCURSOR;
	if (yych <= ',') {
		if (yych != '+') goto yy18;
	} else {
		if (yych <= '-') goto yy66;
		if (yych <= '/') goto yy18;
		if (yych <= '9') goto yy67;
		goto yy18;
	}
yy66:
	yych = *++YYCURSOR;
	if (yych <= ',') {
		if (yych == '+') goto yy69;
		goto yy18;
	} else {
		if (yych <= '-') goto yy69;
		if (yych <= '/') goto yy18;
		if (yych >= ':') goto yy18;
	}
yy67:
	++YYCURSOR;
	if (YYLIMIT <= YYCURSOR) YYFILL(1);
	yych = *YYCURSOR;
	if (yych <= '/') goto yy18;
	if (yych <= '9') goto yy67;
	if (yych == ';') goto yy63;
	goto yy18;
yy69:
	yych = *++YYCURSOR;
	if (yych <= '/') goto yy18;
	if (yych <= '9') goto yy67;
	goto yy18;
yy70:
	++YYCURSOR;
	if ((YYLIMIT - YYCURSOR) < 4) YYFILL(4);
	yych = *YYCURSOR;
	if (yych <= ';') {
		if (yych <= '/') goto yy18;
		if (yych <= '9') goto yy70;
		if (yych <= ':') goto yy18;
		goto yy63;
	} else {
		if (yych <= 'E') {
			if (yych <= 'D') goto yy18;
			goto yy65;
		} else {
			if (yych == 'e') goto yy65;
			goto yy18;
		}
	}
yy72:
	yych = *++YYCURSOR;
	if (yych != 'F') goto yy18;
yy73:
	yych = *++YYCURSOR;
	if (yych != ';') goto yy18;
	++YYCURSOR;
#line 572 "ext/standard/var_unserializer.re"
	{
	*p = YYCURSOR;

	if (!strncmp((char*)start + 2, "NAN", 3)) {
		ZVAL_DOUBLE(rval, php_get_nan());
	} else if (!strncmp((char*)start + 2, "INF", 3)) {
		ZVAL_DOUBLE(rval, php_get_inf());
	} else if (!strncmp((char*)start + 2, "-INF", 4)) {
		ZVAL_DOUBLE(rval, -php_get_inf());
	} else {
		ZVAL_NULL(rval);
	}

	return 1;
}
#line 1109 "ext/standard/var_unserializer.c"
yy76:
	yych = *++YYCURSOR;
	if (yych == 'N') goto yy73;
	goto yy18;
yy77:
	yych = *++YYCURSOR;
	if (yych <= ',') {
		if (yych != '+') goto yy18;
	} else {
		if (yych <= '-') goto yy78;
		if (yych <= '/') goto yy18;
		if (yych <= '9') goto yy79;
		goto yy18;
	}
yy78:
	yych = *++YYCURSOR;
	if (yych <= '/') goto yy18;
	if (yych >= ':') goto yy18;
yy79:
	++YYCURSOR;
	if (YYLIMIT <= YYCURSOR) YYFILL(1);
	yych = *YYCURSOR;
	if (yych <= '/') goto yy18;
	if (yych <= '9') goto yy79;
	if (yych != ';') goto yy18;
	++YYCURSOR;
#line 546 "ext/standard/var_unserializer.re"
	{
#if SIZEOF_LONG == 4
	int digits = YYCURSOR - start - 3;

	if (start[2] == '-' || start[2] == '+') {
		digits--;
	}

	/* Use double for large long values that were serialized on a 64-bit system */
	if (digits >= MAX_LENGTH_OF_LONG - 1) {
		if (digits == MAX_LENGTH_OF_LONG - 1) {
			int cmp = strncmp((char*)YYCURSOR - MAX_LENGTH_OF_LONG, long_min_digits, MAX_LENGTH_OF_LONG - 1);

			if (!(cmp < 0 || (cmp == 0 && start[2] == '-'))) {
				goto use_double;
			}
		} else {
			goto use_double;
		}
	}
#endif
	*p = YYCURSOR;
	ZVAL_LONG(rval, parse_iv(start + 2));
	return 1;
}
#line 1162 "ext/standard/var_unserializer.c"
yy83:
	yych = *++YYCURSOR;
	if (yych <= '/') goto yy18;
	if (yych >= '2') goto yy18;
	yych = *++YYCURSOR;
	if (yych != ';') goto yy18;
	++YYCURSOR;
#line 540 "ext/standard/var_unserializer.re"
	{
	*p = YYCURSOR;
	ZVAL_BOOL(rval, parse_iv(start + 2));
	return 1;
}
#line 1176 "ext/standard/var_unserializer.c"
yy87:
	++YYCURSOR;
#line 534 "ext/standard/var_unserializer.re"
	{
	*p = YYCURSOR;
	ZVAL_NULL(rval);
	return 1;
}
#line 1185 "ext/standard/var_unserializer.c"
yy89:
	yych = *++YYCURSOR;
	if (yych <= ',') {
		if (yych != '+') goto yy18;
	} else {
		if (yych <= '-') goto yy90;
		if (yych <= '/') goto yy18;
		if (yych <= '9') goto yy91;
		goto yy18;
	}
yy90:
	yych = *++YYCURSOR;
	if (yych <= '/') goto yy18;
	if (yych >= ':') goto yy18;
yy91:
	++YYCURSOR;
	if (YYLIMIT <= YYCURSOR) YYFILL(1);
	yych = *YYCURSOR;
	if (yych <= '/') goto yy18;
	if (yych <= '9') goto yy91;
	if (yych != ';') goto yy18;
	++YYCURSOR;
#line 511 "ext/standard/var_unserializer.re"
	{
	long id;

 	*p = YYCURSOR;
	if (!var_hash) return 0;

	id = parse_iv(start + 2) - 1;
	if (id == -1 || (rval_ref = var_access(var_hash, id)) == NULL) {
		return 0;
	}

//???
//???	if (rval == rval_ref) return 0;

//???	if (!ZVAL_IS_UNDEF(rval)) {
//???		var_push_dtor_no_addref(var_hash, rval);
//???	}
	ZVAL_COPY(rval, rval_ref);
//???	Z_UNSET_ISREF_PP(rval);
	
	return 1;
}
#line 1231 "ext/standard/var_unserializer.c"
yy95:
	yych = *++YYCURSOR;
	if (yych <= ',') {
		if (yych != '+') goto yy18;
	} else {
		if (yych <= '-') goto yy96;
		if (yych <= '/') goto yy18;
		if (yych <= '9') goto yy97;
		goto yy18;
	}
yy96:
	yych = *++YYCURSOR;
	if (yych <= '/') goto yy18;
	if (yych >= ':') goto yy18;
yy97:
	++YYCURSOR;
	if (YYLIMIT <= YYCURSOR) YYFILL(1);
	yych = *YYCURSOR;
	if (yych <= '/') goto yy18;
	if (yych <= '9') goto yy97;
	if (yych != ';') goto yy18;
	++YYCURSOR;
#line 489 "ext/standard/var_unserializer.re"
	{
	long id;

 	*p = YYCURSOR;
	if (!var_hash) return 0;

	id = parse_iv(start + 2) - 1;
	if (id == -1 || (rval_ref = var_access(var_hash, id)) == NULL) {
		return 0;
	}

	zval_ptr_dtor(rval);
	if (Z_ISREF_P(rval_ref)) {
		ZVAL_COPY(rval, rval_ref);
	} else {
		ZVAL_NEW_REF(rval_ref, rval_ref);
		ZVAL_COPY(rval, rval_ref);
	}
	
	return 1;
}
#line 1276 "ext/standard/var_unserializer.c"
}
#line 828 "ext/standard/var_unserializer.re"


	return 0;
}