Example #1
0
/* {{{ QConfig::GetBatchKeys( .. )
   */
static PHP_METHOD(QConfig, GetBatchKeys)
{
	char *path, *idc;
	size_t path_len, idc_len;
	int i;
	long get_flags = QCONF_WAIT;
	string_vector_t nodes;
	int ret = 0;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|sl", &path, &path_len, &idc, &idc_len, &get_flags) == FAILURE) 
	{
		RETURN_NULL();
	}
    
	init_string_vector(&nodes);
	if (QCONF_OK != ret)
	{
		RETVAL_NULL();
	}

	if (QCONF_NOWAIT == get_flags)
	{
		ret = qconf_aget_batch_keys(path, &nodes, idc);
	}
	else
	{
		ret = qconf_get_batch_keys(path, &nodes, idc); 
	}

	if (QCONF_OK == ret && (nodes.count >= 0))
	{
		array_init(return_value);
		for (i = 0; i < nodes.count; i++) 
		{
#if PHP_VERSION_ID >= 70000
			add_next_index_string(return_value, nodes.data[i]);
#else
			add_next_index_string(return_value, nodes.data[i], 1);
#endif
		}

		destroy_string_vector(&nodes);
	}
	else
	{
		RETVAL_NULL();
	}

	return;
}
Example #2
0
static void MakeArray(zval *arr, struct descrip *ans, int dim, int *index) {
	int i;
	array_init(arr);
	if (dim == 0) {
		for (i=0;i<ans->dims[dim];i++) {
			switch (ans->dtype) {
			case DTYPE_UCHAR: add_next_index_long(arr,(int)((unsigned char *)ans->ptr)[*index]); break;
			case DTYPE_USHORT:add_next_index_long(arr,(int)((unsigned short *)ans->ptr)[*index]); break;
			case DTYPE_ULONG: add_next_index_long(arr,(int)((int *)ans->ptr)[*index]); break;
			case DTYPE_CHAR:  add_next_index_long(arr,(int)((char *)ans->ptr)[*index]); break;
			case DTYPE_SHORT: add_next_index_long(arr,(int)((short *)ans->ptr)[*index]); break;
			case DTYPE_LONG:  add_next_index_long(arr,((int *)ans->ptr)[*index]); break;
			case DTYPE_FLOAT: add_next_index_double(arr,(double)((float *)ans->ptr)[*index]); break;
			case DTYPE_DOUBLE: add_next_index_double(arr,((double *)ans->ptr)[*index]); break;
			case DTYPE_CSTRING: {
				char *string = strncpy(emalloc(ans->length+1),((char *)ans->ptr) + (*index * ans->length),ans->length);
				string[ans->length]=0;
				add_next_index_string(arr,string,0);
				break;
			}
			}
			*index = *index + 1;
		}
	} else {
		for (i=0;i<ans->dims[dim];i++) {
			zval *arr2;
			MAKE_STD_ZVAL(arr2);
			MakeArray(arr2,ans,dim-1,index);
			add_next_index_zval(arr,arr2);
        }
	}
}
Example #3
0
/* {{{ proto array SolrInputDocument::getFieldNames(void)
   Returns an array of all the field names in the document. */
PHP_METHOD(SolrInputDocument, getFieldNames)
{
	solr_document_t *doc_entry = NULL;

	/* Retrieve the document entry for the SolrDocument instance */
	if (solr_fetch_document_entry(getThis(), &doc_entry TSRMLS_CC) == SUCCESS)
	{
		HashTable *fields_ht = doc_entry->fields;
		register zend_bool duplicate = 0;

		array_init(return_value);

		SOLR_HASHTABLE_FOR_LOOP(fields_ht)
		{
			char *fieldname       = NULL;
			uint fieldname_length = 0U;
			ulong num_index       = 0L;

			solr_field_list_t **field      = NULL;
			zend_bool duplicate_field_name = 1;

			zend_hash_get_current_key_ex(fields_ht, &fieldname, &fieldname_length, &num_index, duplicate, NULL);
			zend_hash_get_current_data_ex(fields_ht, (void **) &field, NULL);

			add_next_index_string(return_value, (char *) (*field)->field_name, duplicate_field_name);
		}

		/* We are done */
		return;
	}
Example #4
0
File: arrr.c Project: tony2001/arrr
static void php_r_to_zval(SEXP value, zval *result) /* {{{ */
{
	int value_len, i;

	zval_dtor(result);
	array_init(result);

	value_len = GET_LENGTH(value);

	if (value_len == 0) {
		return;
	}
	
	for (i = 0; i < value_len; i++) {
		switch (TYPEOF(value)) {
			case INTSXP:
				add_next_index_long(result, INTEGER_DATA(value)[i]);
				break;
			case REALSXP:
				add_next_index_double(result, NUMERIC_DATA(value)[i]);
				break;
			case LGLSXP:
				add_next_index_bool(result, LOGICAL_DATA(value)[i]);
				break;
			case STRSXP:
				add_next_index_string(result, CHAR(STRING_ELT(value, 0)), 1);
				break;
		}
	}
	return;
}
Example #5
0
/* Takes a pointer to posix group and a pointer to an already initialized ZVAL
 * array container and fills the array with the posix group member data. */
int php_posix_group_to_array(struct group *g, zval *array_group) /* {{{ */
{
	zval array_members;
	int count;

	if (NULL == g)
		return 0;

	if (array_group == NULL || Z_TYPE_P(array_group) != IS_ARRAY)
		return 0;

	array_init(&array_members);

	add_assoc_string(array_group, "name", g->gr_name);
	if (g->gr_passwd) {
		add_assoc_string(array_group, "passwd", g->gr_passwd);
	} else {
		add_assoc_null(array_group, "passwd");
	}
	for (count = 0; g->gr_mem[count] != NULL; count++) {
		add_next_index_string(&array_members, g->gr_mem[count]);
	}
	zend_hash_str_update(Z_ARRVAL_P(array_group), "members", sizeof("members")-1, &array_members);
	add_assoc_long(array_group, "gid", g->gr_gid);
	return 1;
}
Example #6
0
/* {{{ proto array pspell_suggest(int pspell, string word)
   Returns array of suggestions */
static PHP_FUNCTION(pspell_suggest)
{
	zend_long scin;
	char *word;
	size_t word_len;
	PspellManager *manager;
	const PspellWordList *wl;
	const char *sug;

	if (zend_parse_parameters(ZEND_NUM_ARGS(), "ls", &scin, &word, &word_len) == FAILURE) {
		return;
	}

	PSPELL_FETCH_MANAGER;

	array_init(return_value);

	wl = pspell_manager_suggest(manager, word);
	if (wl) {
		PspellStringEmulation *els = pspell_word_list_elements(wl);
		while ((sug = pspell_string_emulation_next(els)) != 0) {
			add_next_index_string(return_value,(char *)sug);
		}
		delete_pspell_string_emulation(els);
	} else {
		php_error_docref(NULL, E_WARNING, "PSPELL had a problem. details: %s", pspell_manager_error_message(manager));
		RETURN_FALSE;
	}
}
Example #7
0
/* {{{ mlfi_envform()
*/
static sfsistat mlfi_envfrom(SMFICTX *ctx, char **argv)
{
	zval function_name, retval, *param[1];
	int status;
	TSRMLS_FETCH();

	/* call userland */
	INIT_ZVAL(function_name);
	
	ALLOC_ZVAL(param[0]);
	INIT_PZVAL(param[0]);

	ZVAL_STRING(&function_name, "milter_envfrom", 0);
	array_init(param[0]);

	while (*argv) {
		add_next_index_string(param[0], *argv, 1);
		argv++;
	}

	/* set the milter context for possible use in API functions */
	MG(ctx) = ctx;
	MG(state) = MLFI_ENVFROM;
	
	status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param TSRMLS_CC);

	MG(state) = MLFI_NONE;
	zval_ptr_dtor(param);
	
	if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) {
		return Z_LVAL(retval);
	}

	return SMFIS_CONTINUE;
}
PHP_METHOD(ArrayList, toValue) {
	array_init(return_value);
	list_object* obj = (list_object*) zend_object_store_get_object(getThis() TSRMLS_CC);
    if (obj->object != NULL) {
		if(obj->type == TYPE_LONG) {
			ArrayList<long>* list = (ArrayList<long>*) obj->object;
	    	for (auto it=list->begin(); it!=list->end(); ++it) {
				add_next_index_long(return_value,*it);
			}
		} else if (obj->type == TYPE_DOUBLE) {
			ArrayList<double>* list = (ArrayList<double>*) obj->object;
	    	for (auto it=list->begin(); it!=list->end(); ++it) {
				add_next_index_double(return_value,*it);
			}
		} else if (obj->type == TYPE_BOOLEAN) {
			ArrayList<char>* list = (ArrayList<char>*) obj->object;
	    	for (auto it=list->begin(); it!=list->end(); ++it) {
				add_next_index_bool(return_value,*it);
			}
		} else if (obj->type == TYPE_STRING) {
			ArrayList<char*>* list = (ArrayList<char*>*) obj->object;
	    	for (auto it=list->begin(); it!=list->end(); ++it) {
				add_next_index_string(return_value,*it,1);
			}
		} else {
			ArrayList<zval*>* list = (ArrayList<zval*>*) obj->object;
	    	for (auto it=list->begin(); it!=list->end(); ++it) {
				Z_ADDREF_P(*it);
				add_next_index_zval(return_value,*it);
			}
		}
    }
}
Example #9
0
static void trace(jsonlite_decoder *self, const char *msg, const char *detail) {
    zval *trace = NULL;

    MAKE_STD_ZVAL(trace);
    array_init(trace);
    add_next_index_string(trace, msg, 1);
    add_next_index_long(trace, self->transactionIndex);
    add_next_index_long(trace, self->index);

    if (detail != NULL) {
        add_next_index_string(trace, detail, 1);
    }

    add_next_index_zval(self->trace, trace);

}
static void coro_dns_onGetaddrinfoCompleted(swAio_event *event)
{
    php_context *context = event->object;

    zval *retval = NULL;
    zval *result = NULL;

    SW_MAKE_STD_ZVAL(result);

    struct sockaddr_in *addr_v4;
    struct sockaddr_in6 *addr_v6;

    swRequest_getaddrinfo *req = event->req;

    if (req->error == 0)
    {
        array_init(result);
        int i;
        char tmp[INET6_ADDRSTRLEN];
        const char *r ;

        for (i = 0; i < req->count; i++)
        {
            if (req->family == AF_INET)
            {
                addr_v4 = req->result + (i * sizeof(struct sockaddr_in));
                r = inet_ntop(AF_INET, (const void*) &addr_v4->sin_addr, tmp, sizeof(tmp));
            }
            else
            {
                addr_v6 = req->result + (i * sizeof(struct sockaddr_in6));
                r = inet_ntop(AF_INET6, (const void*) &addr_v6->sin6_addr, tmp, sizeof(tmp));
            }
            if (r)
            {
                add_next_index_string(result, tmp);
            }
        }
    }
    else
    {
        ZVAL_BOOL(result, 0);
        SwooleG.error = req->error;
    }

    int ret = coro_resume(context, result, &retval);
    if (ret == CORO_END && retval)
    {
        sw_zval_ptr_dtor(&retval);
    }
    sw_zval_ptr_dtor(&result);
    efree(req->hostname);
    efree(req->result);
    if (req->service)
    {
        efree(req->service);
    }
    efree(req);
    efree(context);
}
/* {{{ Mosquitto\Message::tokeniseTopic() */
PHP_METHOD(Mosquitto_Message, tokeniseTopic)
{
	char *topic = NULL, **topics = NULL;
	int topic_len = 0, retval = 0, count = 0, i = 0;

	PHP_MOSQUITTO_ERROR_HANDLING();
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &topic, &topic_len) == FAILURE) {
		PHP_MOSQUITTO_RESTORE_ERRORS();
		return;
	}
	PHP_MOSQUITTO_RESTORE_ERRORS();

	retval = mosquitto_sub_topic_tokenise(topic, &topics, &count);

	if (retval == MOSQ_ERR_NOMEM) {
		zend_throw_exception_ex(mosquitto_ce_exception, 0 TSRMLS_CC, "Failed to tokenise topic");
		return;
	}

	array_init(return_value);
	for (i = 0; i < count; i++) {
		if (topics[i] == NULL) {
			add_next_index_null(return_value);
		} else {
			add_next_index_string(return_value, topics[i], 1);
		}
	}

	mosquitto_sub_topic_tokens_free(&topics, count);
}
/**
 * Internal function that goes through every property specified in the PHP.ini
 * file and for each of the properties checks that such property exists in the
 * data set properties array. If a property exists, then a corresponding value
 * is added to the array that will be returned to PHP. If a property does not
 * exist, then a "Switch Data Set" message is returned as the property value
 * @param returnArray a pointer to the Zend array to store results in.
 */
void buildArray(zval *returnArray)
{
    char* propertyName;
    char *valueString;
    char* methodString;
    int propertyIndex;
    int valueCount;
    int valueIndex;
    int32_t sigRank;

    for(propertyIndex = 0;
        propertyIndex < FIFTYONE_G(ws)->dataSet->requiredPropertyCount;
        propertyIndex++) {
        propertyName = (char*)fiftyoneDegreesGetPropertyName(
                FIFTYONE_G(ws)->dataSet,
                *(FIFTYONE_G(ws)->dataSet->requiredProperties + propertyIndex));
        valueCount = fiftyoneDegreesSetValues(FIFTYONE_G(ws), propertyIndex);

        if (valueCount == 1) {
            valueString = (char*)fiftyoneDegreesGetValueName(
                FIFTYONE_G(ws)->dataSet,
                *FIFTYONE_G(ws)->values);
            add_assoc_string(returnArray, propertyName, valueString, 1);
        } else if (valueCount > 1) {
            zval* valueArray;
            ALLOC_INIT_ZVAL(valueArray);
            array_init(valueArray);
            add_assoc_zval(returnArray, propertyName, valueArray);
            for(valueIndex = 0; valueIndex < valueCount; valueIndex++) {
                valueString = (char*)fiftyoneDegreesGetValueName(
                    FIFTYONE_G(ws)->dataSet,
                    *(FIFTYONE_G(ws)->values + valueIndex));
                add_next_index_string(valueArray, valueString, 1);
            }
        }
    }
    // Add signature rank information.
    sigRank = fiftyoneDegreesGetSignatureRank(FIFTYONE_G(ws));
    // SignatureRank is obsolete and will be removed in future versions.
    // Use Rank instead.
    add_assoc_long(returnArray, "SignatureRank", sigRank);
    add_assoc_long(returnArray, "Rank", sigRank);
    add_assoc_long(returnArray, "Difference", FIFTYONE_G(ws)->difference);

    // Add method that was used for detection to the results array.
    switch(FIFTYONE_G(ws)->method){
        case NONE: methodString = "None"; break;
        case EXACT: methodString = "Exact"; break;
        case NUMERIC: methodString = "Numeric"; break;
        case NEAREST: methodString = "Nearest"; break;
        case CLOSEST: methodString = "Closest"; break;
        default: methodString = "Unknown"; break;
    }
    add_assoc_string(returnArray, "Method", methodString, 1);
    addDeviceIdToArray(returnArray);
}
Example #13
0
static int pdo_sqlite_stmt_col_meta(pdo_stmt_t *stmt, zend_long colno, zval *return_value)
{
	pdo_sqlite_stmt *S = (pdo_sqlite_stmt*)stmt->driver_data;
	const char *str;
	zval flags;

	if (!S->stmt) {
		return FAILURE;
	}
	if(colno >= sqlite3_data_count(S->stmt)) {
		/* error invalid column */
		pdo_sqlite_error_stmt(stmt);
		return FAILURE;
	}

	array_init(return_value);
	array_init(&flags);

	switch (sqlite3_column_type(S->stmt, colno)) {
		case SQLITE_NULL:
			add_assoc_string(return_value, "native_type", "null");
			break;

		case SQLITE_FLOAT:
			add_assoc_string(return_value, "native_type", "double");
			break;

		case SQLITE_BLOB:
			add_next_index_string(&flags, "blob");
		case SQLITE_TEXT:
			add_assoc_string(return_value, "native_type", "string");
			break;

		case SQLITE_INTEGER:
			add_assoc_string(return_value, "native_type", "integer");
			break;
	}

	str = sqlite3_column_decltype(S->stmt, colno);
	if (str) {
		add_assoc_string(return_value, "sqlite:decl_type", (char *)str);
	}

#ifdef SQLITE_ENABLE_COLUMN_METADATA
	str = sqlite3_column_table_name(S->stmt, colno);
	if (str) {
		add_assoc_string(return_value, "table", (char *)str);
	}
#endif

	add_assoc_zval(return_value, "flags", &flags);

	return SUCCESS;
}
Example #14
0
static int dblib_fetch_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info)
{
	pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data;
	pdo_dblib_err *einfo = &H->err;
	pdo_dblib_stmt *S = NULL;
	char *message;
	char *msg;

	if (stmt) {
		S = (pdo_dblib_stmt*)stmt->driver_data;
		einfo = &S->err;
	}

	if (einfo->lastmsg) {
		msg = einfo->lastmsg;
	} else if (DBLIB_G(err).lastmsg) {
		msg = DBLIB_G(err).lastmsg;
		DBLIB_G(err).lastmsg = NULL;
	} else {
		msg = einfo->dberrstr;
	}

	/* don't return anything if there's nothing to return */
	if (msg == NULL && einfo->dberr == 0 && einfo->oserr == 0 && einfo->severity == 0) {
		return 0;
	}

	spprintf(&message, 0, "%s [%d] (severity %d) [%s]",
		msg, einfo->dberr, einfo->severity, stmt ? stmt->active_query_string : "");

	add_next_index_long(info, einfo->dberr);
	add_next_index_string(info, message);
	efree(message);
	add_next_index_long(info, einfo->oserr);
	add_next_index_long(info, einfo->severity);
	if (einfo->oserrstr) {
		add_next_index_string(info, einfo->oserrstr);
	}

	return 1;
}
Example #15
0
static int pdo_pgsql_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) /* {{{ */
{
	pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data;
	pdo_pgsql_error_info *einfo = &H->einfo;

	if (einfo->errcode) {
		add_next_index_long(info, einfo->errcode);
		add_next_index_string(info, einfo->errmsg);
	}

	return 1;
}
Example #16
0
/* {{{ proto array Glib::filenameGetCharsets()
	   Determines the preferred character sets used for filenames. 
	   Returns an array. The first element is a boolean indicating if the filename encoding
	   is UTF-8. The second element is the filename encoding.
	   The final element is an array of character sets used when trying to generate a
	   displayable representation of a filename.
	   */
PHP_METHOD(Glib, filenameGetCharsets)
{
	const gchar **charsets;
	gboolean utf8;
	zval *charset_array;
	int i;

	if (zend_parse_parameters_none() == FAILURE) {
		return;
	}

	array_init(return_value);
	MAKE_STD_ZVAL(charset_array);
	array_init(charset_array);

	utf8 = g_get_filename_charsets(&charsets);
	add_next_index_bool(return_value, utf8);
	add_next_index_string(return_value, (char *)charsets[0], 1);
	for (i = 1; charsets[i]; i++) {
		add_next_index_string(charset_array, (char *)charsets[i], 1);
	}
	add_next_index_zval(return_value, charset_array);
}
Example #17
0
void pdo_sqlsrv_retrieve_context_error( sqlsrv_error const* last_error, zval* pdo_zval )
{
    if( last_error ) {

        // SQLSTATE is already present in the zval.
        add_next_index_long( pdo_zval, last_error->native_code );
        add_next_index_string( pdo_zval, reinterpret_cast<char*>( last_error->native_message ), 1 /*dup*/ );
    }
    else {
        add_next_index_null( pdo_zval ); /* native code */
        add_next_index_null( pdo_zval ); /* native message */
    }

}
Example #18
0
/* {{{ proto array Glib::getCharset()
	   Obtains the character set for the current locale.
	   Returns an array, the first element of which is a boolean indicating if the
	   current charset is UTF-8. The remaining element is the charset.
	   */
PHP_METHOD(Glib, getCharset)
{
	gboolean status;
	const gchar *charset;

	if (zend_parse_parameters_none() == FAILURE) {
		return;
	}

	status = g_get_charset(&charset);
	array_init(return_value);
	add_next_index_bool(return_value, status);
	add_next_index_string(return_value, (char *)charset, 1);
}
Example #19
0
static int process_keyword (void *cls, const char *plugin_name, 
                     enum EXTRACTOR_MetaType type, 
                     enum EXTRACTOR_MetaFormat format, 
                     const char *data_mime_type, 
                     const char *data, size_t data_len) {
    
    zval *keywords, **subarray;
    const char *ktype = EXTRACTOR_metatype_to_string(type);
    const char *kval  = estrndup(data, data_len);
    
    ALLOC_INIT_ZVAL(keywords);
    array_init(keywords);

    if (zend_hash_find(Z_ARRVAL_P((zval*) cls), ktype, strlen(ktype) + 1, (void**) &subarray) == SUCCESS) {
        add_next_index_string(*subarray, kval, 1);
        return 0;
    }
    
    add_next_index_string(keywords, kval, 1);
    add_assoc_zval(cls, ktype, keywords);

    return 0;
}
Example #20
0
/* Add numeric indexed string value array to given zval by key */
void
string_php_repeated (zval* out, char* name, char** const* val, unsigned int num_fields)
{
    unsigned int i;
    char** arr = *val;
    zval* repeated;
    MAKE_STD_ZVAL(repeated);
    array_init(repeated);

    for (i=0;i<num_fields;++i) {
        add_next_index_string(repeated, arr[i], 1);
    }

    add_assoc_zval(out, name, repeated);
}
Example #21
0
/* {{{ proto array Glib::systemConfigDirs()
	   Returns an ordered list of base directories in which to access system-wide configuration information.
*/
PHP_METHOD(Glib, systemConfigDirs)
{
	if (zend_parse_parameters_none() == FAILURE) {
		return;
	}

	const gchar* const *dir = g_get_system_config_dirs();

	array_init(return_value);

	while (*dir != NULL) {
		add_next_index_string(return_value, *dir, 1);
		dir++;
	}
}
Example #22
0
/* {{{ proto array Glib::getLanguageNames()
	   Checks the version of the GLib library the extension was compiled against.
	   Returns TRUE if the version of the GLib header files compiled against are the same as or newer than the passed-in version. 
   */
PHP_METHOD(Glib, getLanguageNames)
{
	const gchar* const *langs;
	int i;

	if (zend_parse_parameters_none() == FAILURE) {
		return;
	}
	langs = g_get_language_names();

	array_init(return_value);
	for (i = 0; langs[i]; i++) {
		add_next_index_string(return_value, (char *)langs[i], 1);
	}
}
Example #23
0
/* {{{ ftp_raw
 */
void
ftp_raw(ftpbuf_t *ftp, const char *cmd, zval *return_value)
{
	if (ftp == NULL || cmd == NULL) {
		RETURN_NULL();
	}
	if (!ftp_putcmd(ftp, cmd, NULL)) {
		RETURN_NULL();
	}
	array_init(return_value);
	while (ftp_readline(ftp)) {
		add_next_index_string(return_value, ftp->inbuf);
		if (isdigit(ftp->inbuf[0]) && isdigit(ftp->inbuf[1]) && isdigit(ftp->inbuf[2]) && ftp->inbuf[3] == ' ') {
			return;
		}
	}
}
Example #24
0
U_CFUNC PHP_FUNCTION(intlcal_get_available_locales)
{
	intl_error_reset(NULL TSRMLS_CC);

	if (zend_parse_parameters_none() == FAILURE) {
		intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
			"intlcal_get_available_locales: bad arguments", 0 TSRMLS_CC);
		RETURN_FALSE;
	}

	int32_t count;
	const Locale *availLocales = Calendar::getAvailableLocales(count);
	array_init(return_value);
	for (int i = 0; i < count; i++) {
		Locale locale = availLocales[i];
		add_next_index_string(return_value, locale.getName());
	}
}
Example #25
0
/* {{{ pdo_mysql_fetch_error_func */
static int pdo_mysql_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info)
{
	pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
	pdo_mysql_error_info *einfo = &H->einfo;

	PDO_DBG_ENTER("pdo_mysql_fetch_error_func");
	PDO_DBG_INF_FMT("dbh=%p stmt=%p", dbh, stmt);
	if (stmt) {
		pdo_mysql_stmt *S = (pdo_mysql_stmt*)stmt->driver_data;
		einfo = &S->einfo;
	} else {
		einfo = &H->einfo;
	}

	if (einfo->errcode) {
		add_next_index_long(info, einfo->errcode);
		add_next_index_string(info, einfo->errmsg);
	}

	PDO_DBG_RETURN(1);
}
static PHP_METHOD (midgard_connection, list_auth_types)
{
	MidgardConnection *mgd =__midgard_connection_get_ptr(getThis());
	CHECK_MGD(mgd);
	array_init (return_value);

	if (zend_parse_parameters_none () == FAILURE)
		return;

	guint n_types;
	gchar **auth_types = midgard_connection_list_auth_types(mgd, &n_types);

	if (!auth_types)
		return;

	guint i;

	for (i = 0; i < n_types; i++) {
		add_next_index_string(return_value, auth_types[i], 1);
	}

	g_free(auth_types);
}
Example #27
0
static int pdo_odbc_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info)
{
	pdo_odbc_db_handle *H = (pdo_odbc_db_handle *)dbh->driver_data;
	pdo_odbc_errinfo *einfo = &H->einfo;
	pdo_odbc_stmt *S = NULL;
	zend_string *message = NULL;

	if (stmt) {
		S = (pdo_odbc_stmt*)stmt->driver_data;
		einfo = &S->einfo;
	}

	message = strpprintf(0, "%s (%s[%ld] at %s:%d)",
				einfo->last_err_msg,
				einfo->what, einfo->last_error,
				einfo->file, einfo->line);

	add_next_index_long(info, einfo->last_error);
	add_next_index_str(info, message);
	add_next_index_string(info, einfo->last_state);

	return 1;
}
Example #28
0
static void php_mongo_enumerate_collections(INTERNAL_FUNCTION_PARAMETERS, int full_collection)
{
	zend_bool system_col = 0;
	zval *nss, *collection, *cursor, *list, *next;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &system_col) == FAILURE) {
		return;
	}

  // select db.system.namespaces collection
  MAKE_STD_ZVAL(nss);
  ZVAL_STRING(nss, "system.namespaces", 1);

  MAKE_STD_ZVAL(collection);
  MONGO_METHOD1(MongoDB, selectCollection, collection, getThis(), nss);

  // list to return
  MAKE_STD_ZVAL(list);
  array_init(list);

  // do find
  MAKE_STD_ZVAL(cursor);
  MONGO_METHOD(MongoCollection, find, cursor, collection);

  // populate list
  MAKE_STD_ZVAL(next);
  MONGO_METHOD(MongoCursor, getNext, next, cursor);
  while (!IS_SCALAR_P(next)) {
    zval *c, *zname;
    zval **collection;
    char *name, *first_dot, *system;

    // check that the ns is valid and not an index (contains $)
    if (zend_hash_find(HASH_P(next), "name", 5, (void**)&collection) == FAILURE ||
        strchr(Z_STRVAL_PP(collection), '$')) {

      zval_ptr_dtor(&next);
      MAKE_STD_ZVAL(next);
      ZVAL_NULL(next);

      MONGO_METHOD(MongoCursor, getNext, next, cursor);
      continue;
    }

    first_dot = strchr(Z_STRVAL_PP(collection), '.');
    system = strstr(Z_STRVAL_PP(collection), ".system.");
    // check that this isn't a system ns
    if (!system_col && (system && first_dot == system) ||
      (name = strchr(Z_STRVAL_PP(collection), '.')) == 0) {

      zval_ptr_dtor(&next);
      MAKE_STD_ZVAL(next);
      ZVAL_NULL(next);

      MONGO_METHOD(MongoCursor, getNext, next, cursor);
      continue;
    }

    // take a substring after the first "."
    name++;

    // "foo." was allowed in earlier versions
    if (name == '\0') {
      zval_ptr_dtor(&next);
      MAKE_STD_ZVAL(next);
      ZVAL_NULL(next);

      MONGO_METHOD(MongoCursor, getNext, next, cursor);
      continue;
    }

	if (full_collection) {
		MAKE_STD_ZVAL(c);
		ZVAL_NULL(c);

		MAKE_STD_ZVAL(zname);
		ZVAL_NULL(zname);

		// name must be copied because it is a substring of
		// a string that will be garbage collected in a sec
		ZVAL_STRING(zname, name, 1);
		MONGO_METHOD1(MongoDB, selectCollection, c, getThis(), zname);

		add_next_index_zval(list, c);

		zval_ptr_dtor(&zname);
	} else {
		add_next_index_string(list, name, 1);
	}
    zval_ptr_dtor(&next);
    MAKE_STD_ZVAL(next);

    MONGO_METHOD(MongoCursor, getNext, next, cursor);
  }

  zval_ptr_dtor(&next);
  zval_ptr_dtor(&nss);
  zval_ptr_dtor(&cursor);
  zval_ptr_dtor(&collection);

  RETURN_ZVAL(list, 0, 1);
}
Example #29
0
static inline int phpdbg_call_register(phpdbg_param_t *stack) /* {{{ */
{
	phpdbg_param_t *name = NULL;

	if (stack->type == STACK_PARAM) {
		char *lc_name;

		name = stack->next;

		if (!name || name->type != STR_PARAM) {
			return FAILURE;
		}

		lc_name = zend_str_tolower_dup(name->str, name->len);

		if (zend_hash_str_exists(&PHPDBG_G(registered), lc_name, name->len)) {
			zval fretval;
			zend_fcall_info fci;

			memset(&fci, 0, sizeof(zend_fcall_info));

			ZVAL_STRINGL(&fci.function_name, lc_name, name->len);
			fci.size = sizeof(zend_fcall_info);
			fci.function_table = &PHPDBG_G(registered);
			fci.symbol_table = zend_rebuild_symbol_table();
			fci.object = NULL;
			fci.retval = &fretval;
			fci.no_separation = 1;

			if (name->next) {
				zval params;
				phpdbg_param_t *next = name->next;

				array_init(&params);

				while (next) {
					char *buffered = NULL;

					switch (next->type) {
						case OP_PARAM:
						case COND_PARAM:
						case STR_PARAM:
							add_next_index_stringl(&params, next->str, next->len);
						break;

						case NUMERIC_PARAM:
							add_next_index_long(&params, next->num);
						break;

						case METHOD_PARAM:
							spprintf(&buffered, 0, "%s::%s", next->method.class, next->method.name);
							add_next_index_string(&params, buffered);
						break;

						case NUMERIC_METHOD_PARAM:
							spprintf(&buffered, 0, "%s::%s#%ld", next->method.class, next->method.name, next->num);
							add_next_index_string(&params, buffered);
						break;

						case NUMERIC_FUNCTION_PARAM:
							spprintf(&buffered, 0, "%s#%ld", next->str, next->num);
							add_next_index_string(&params, buffered);
						break;

						case FILE_PARAM:
							spprintf(&buffered, 0, "%s:%ld", next->file.name, next->file.line);
							add_next_index_string(&params, buffered);
						break;

						case NUMERIC_FILE_PARAM:
							spprintf(&buffered, 0, "%s:#%ld", next->file.name, next->file.line);
							add_next_index_string(&params, buffered);
						break;

						default: {
							/* not yet */
						}
					}

					next = next->next;
				}

				zend_fcall_info_args(&fci, &params);
			} else {
Example #30
0
/*
* Generic SNMP object fetcher
*
* st=1   snmpget() - query an agent and return a single value.
* st=2   snmpwalk() - walk the mib and return a single dimensional array 
*          containing the values.
* st=3 snmprealwalk() and snmpwalkoid() - walk the mib and return an 
*          array of oid,value pairs.
* st=5-8 ** Reserved **
* st=11  snmpset() - query an agent and set a single value
*
*/
void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st) {
	zval **a1, **a2, **a3, **a4, **a5, **a6, **a7;
	struct snmp_session session, *ss;
	struct snmp_pdu *pdu=NULL, *response;
	struct variable_list *vars;
    char *objid;
    oid name[MAX_NAME_LEN];
    int name_length;
    int status, count,rootlen=0,gotroot=0;
	oid root[MAX_NAME_LEN];
	char buf[2048];
	char buf2[2048];
	int keepwalking=1;
	long timeout=SNMP_DEFAULT_TIMEOUT;
	long retries=SNMP_DEFAULT_RETRIES;
	int myargc = ZEND_NUM_ARGS();
    char type = (char) 0;
    char *value = (char *) 0;
	
	if (myargc < 3 || myargc > 7 ||
		zend_get_parameters_ex(myargc, &a1, &a2, &a3, &a4, &a5, &a6, &a7) == FAILURE) {
		WRONG_PARAM_COUNT;
	}

	convert_to_string_ex(a1);
	convert_to_string_ex(a2);
	convert_to_string_ex(a3);
	
	if (st == 11) {
		if (myargc < 5) {
			WRONG_PARAM_COUNT;
		}

		convert_to_string_ex(a4);
		convert_to_string_ex(a5);
	
		if(myargc > 5) {
			convert_to_long_ex(a6);
			timeout = (*a6)->value.lval;
		}

		if(myargc > 6) {
			convert_to_long_ex(a7);
			retries = (*a7)->value.lval;
		}

		type = (*a4)->value.str.val[0];
		value = (*a5)->value.str.val;
	} else {
		if(myargc > 3) {
			convert_to_long_ex(a4);
			timeout = (*a4)->value.lval;
		}

		if(myargc > 4) {
			convert_to_long_ex(a5);
			retries = (*a5)->value.lval;
		}
	}

	objid = (*a3)->value.str.val;
	
	if (st >= 2) { /* walk */
		rootlen = MAX_NAME_LEN;
		if ( strlen(objid) ) { /* on a walk, an empty string means top of tree - no error */
			if ( read_objid(objid, root, &rootlen) ) {
				gotroot = 1;
			} else {
				php_error(E_WARNING,"Invalid object identifier: %s\n", objid);
			}
		}
		if (gotroot == 0) {
			memmove((char *)root, (char *)objid_mib, sizeof(objid_mib));
			rootlen = sizeof(objid_mib) / sizeof(oid);
			gotroot = 1;
		}
	}
	
	memset(&session, 0, sizeof(struct snmp_session));

	session.peername = (*a1)->value.str.val;
	session.version = SNMP_VERSION_1;
	/*
	* FIXME: potential memory leak
	* This is a workaround for an "artifact" (Mike Slifcak)
	* in (at least) ucd-snmp 3.6.1 which frees
	* memory it did not allocate
	*/
#ifdef UCD_SNMP_HACK
	session.community = (u_char *)strdup((*a2)->value.str.val); /* memory freed by SNMP library, strdup NOT estrdup */
#else
	session.community = (u_char *)(*a2)->value.str.val;
#endif
	session.community_len = (*a2)->value.str.len;
	session.retries = retries;
	session.timeout = timeout;
	
	session.authenticator = NULL;
	snmp_synch_setup(&session);

	if ((ss = snmp_open(&session)) == NULL) {
		php_error(E_WARNING,"Could not open snmp\n");
		RETURN_FALSE;
	}

	if (st >= 2) {
		memmove((char *)name, (char *)root, rootlen * sizeof(oid));
		name_length = rootlen;
		if (array_init(return_value) == FAILURE) {
			php_error(E_WARNING, "Cannot prepare result array");
			RETURN_FALSE;
		}
	}

	while(keepwalking) {
		keepwalking=0;
		if (st == 1) {
			pdu = snmp_pdu_create(SNMP_MSG_GET);
			name_length = MAX_NAME_LEN;
			if ( !read_objid(objid, name, &name_length) ) {
				php_error(E_WARNING,"Invalid object identifier: %s\n", objid);
				RETURN_FALSE;
			}
			snmp_add_null_var(pdu, name, name_length);
		} else if (st == 11) {
			pdu = snmp_pdu_create(SNMP_MSG_SET);
			if (snmp_add_var(pdu, name, name_length, type, value)) {
				php_error(E_WARNING,"Could not add variable: %s\n", name);
				RETURN_FALSE;
			}
		} else if (st >= 2) {
			pdu = snmp_pdu_create(SNMP_MSG_GETNEXT);
			snmp_add_null_var(pdu, name, name_length);
		}
		
retry:
		status = snmp_synch_response(ss, pdu, &response);
		if (status == STAT_SUCCESS) {
			if (response->errstat == SNMP_ERR_NOERROR) {
				for (vars = response->variables; vars; vars = vars->next_variable) {
					if (st >= 2 && st != 11 && 
						(vars->name_length < rootlen || memcmp(root, vars->name, rootlen * sizeof(oid)))) {
						continue;       /* not part of this subtree */
					}

					if (st != 11) {
						sprint_value(buf,vars->name, vars->name_length, vars);
					}
#if 0
					Debug("snmp response is: %s\n",buf);
#endif
					if (st == 1) {
						RETVAL_STRING(buf,1);
					} else if (st == 2) {
						add_next_index_string(return_value,buf,1); /* Add to returned array */
					} else if (st == 3)  {
						sprint_objid(buf2, vars->name, vars->name_length);
						add_assoc_string(return_value,buf2,buf,1);
					}
					if (st >= 2 && st != 11) {
						if (vars->type != SNMP_ENDOFMIBVIEW && 
							vars->type != SNMP_NOSUCHOBJECT && vars->type != SNMP_NOSUCHINSTANCE) {
							memmove((char *)name, (char *)vars->name,vars->name_length * sizeof(oid));
							name_length = vars->name_length;
							keepwalking = 1;
						}
					}
				}	
			} else {
				if (st != 2 || response->errstat != SNMP_ERR_NOSUCHNAME) {
					php_error(E_WARNING,"Error in packet.\nReason: %s\n", snmp_errstring(response->errstat));
					if (response->errstat == SNMP_ERR_NOSUCHNAME) {
						for (count=1, vars = response->variables; vars && count != response->errindex;
						vars = vars->next_variable, count++);
						if (vars) {
							sprint_objid(buf,vars->name, vars->name_length);
						}
						php_error(E_WARNING,"This name does not exist: %s\n",buf);
					}
					if (st == 1) {
						if ((pdu = snmp_fix_pdu(response, SNMP_MSG_GET)) != NULL) {
							goto retry;
						}
					} else if (st == 11) {
						if ((pdu = snmp_fix_pdu(response, SNMP_MSG_SET)) != NULL) {
							goto retry;
						}
					} else if (st >= 2) {
						if ((pdu = snmp_fix_pdu(response, SNMP_MSG_GETNEXT)) != NULL) {
							goto retry;
						}
					}
					RETURN_FALSE;
				}
			}
		} else if (status == STAT_TIMEOUT) {
			php_error(E_WARNING,"No Response from %s\n", (*a1)->value.str.val);
			RETURN_FALSE;
		} else {    /* status == STAT_ERROR */
			php_error(E_WARNING,"An error occurred, Quitting...\n");
			RETURN_FALSE;
		}
		if (response) {
			snmp_free_pdu(response);
		}
	} /* keepwalking */
	snmp_close(ss);
}