示例#1
0
/* parse headers */
static int multipart_buffer_headers(multipart_buffer *self, zend_llist *header)
{
	char *line;
	mime_header_entry prev_entry = {0}, entry;
	int prev_len, cur_len;

	/* didn't find boundary, abort */
	if (!find_boundary(self, self->boundary)) {
		return 0;
	}

	/* get lines of text, or CRLF_CRLF */

	while( (line = get_line(self)) && line[0] != '\0' )
	{
		/* add header to table */
		char *key = line;
		char *value = NULL;

		if (php_rfc1867_encoding_translation()) {
			self->input_encoding = zend_multibyte_encoding_detector(line, strlen(line), self->detect_order, self->detect_order_size);
		}

		/* space in the beginning means same header */
		if (!isspace(line[0])) {
			value = strchr(line, ':');
		}

		if (value) {
			*value = 0;
			do { value++; } while(isspace(*value));

			entry.value = estrdup(value);
			entry.key = estrdup(key);

		} else if (zend_llist_count(header)) { /* If no ':' on the line, add to previous line */

			prev_len = (int)strlen(prev_entry.value);
			cur_len = (int)strlen(line);

			entry.value = emalloc(prev_len + cur_len + 1);
			memcpy(entry.value, prev_entry.value, prev_len);
			memcpy(entry.value + prev_len, line, cur_len);
			entry.value[cur_len + prev_len] = '\0';

			entry.key = estrdup(prev_entry.key);

			zend_llist_remove_tail(header);
		} else {
			continue;
		}

		zend_llist_add_element(header, &entry);
		prev_entry = entry;
	}

	return 1;
}
示例#2
0
void orbit_class_function_call(
    zend_class_entry * pClass,
    int dataType,
    zend_property_reference *pPropertyReference,
    Class_Constructor pConstructor,
    Class_CallFunction pCallFunction,
    INTERNAL_FUNCTION_PARAMETERS)
{
    /* get object */
    zval * object = pPropertyReference->object;

    /* get function name */
    zend_overloaded_element * function_name =
        (zend_overloaded_element *)pPropertyReference->elements_list->tail->data;

    /* handle parameters */
    zval ** arguments = orbit_new_n(zval *, ZEND_NUM_ARGS());
    /*(zval **)emalloc(sizeof(zval *) * ZEND_NUM_ARGS());*/
    if (getParametersArray(ht, ZEND_NUM_ARGS(), arguments) == FAILURE)
    {
        /* TODO: handle error */
    }

    /* constructor or normal function? */
    if (zend_llist_count(pPropertyReference->elements_list) == 1
            && !strcasecmp(function_name->element.value.str.val, pClass->name))
    {
        /* constructor */
        if (pConstructor)
        {
            void * p_data = NULL;
            zend_bool success = (*pConstructor)(&p_data, ZEND_NUM_ARGS(), arguments);

            if (success)
                orbit_save_data(object, dataType, p_data);
        }
        else
        {
            zend_error(E_WARNING, "(Satellite) This class has no constructor");
            \
        }
    }
    else
    {
        /* normal function */
        if (pCallFunction)
        {
            void * p_data = orbit_retrieve_data(object, dataType);

            if (p_data == NULL)
            {
                /*
                 * this means that the constructor has failed earlier!
                 * -- or should NULL be allowed here?
                 */
                php_error(E_WARNING, "(Satellite) Class has no data!");
                RETVAL_NULL();
                goto orbit_class_function_call_exit;
            }

            /* pval * return_value is a part of INTERNAL_FUNCTION_PARAMETERS */
            (*pCallFunction)(p_data, function_name->element.value.str.val,
                             ZEND_NUM_ARGS(), arguments, return_value);
        }
        else
        {
            zend_error(E_WARNING, "(Satellite) Can't call functions in this class");
            \
        }
    }

orbit_class_function_call_exit:
    satellite_delete(arguments);

    /* seems to be required! */
    zval_dtor(&function_name->element);
}