Esempio n. 1
0
/* {{{ proto long win32_start_service(string servicename [, string machine])
   Starts a service */
static PHP_FUNCTION(win32_start_service)
{
	char *machine = NULL;
	char *service = NULL;
	size_t machine_len = 0;
	size_t	service_len = 0;
	SC_HANDLE hsvc;
	SC_HANDLE hmgr;

	if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!", &service, &service_len, &machine, &machine_len)) {
		RETURN_FALSE;
	}

	hmgr = OpenSCManager(machine, NULL, SC_MANAGER_ALL_ACCESS);
	if (hmgr) {
		hsvc = OpenService(hmgr, service, SERVICE_START);
		if (hsvc) {
			if (StartService(hsvc, 0, NULL)) {
				RETVAL_LONG(NO_ERROR);
			} else {
				RETVAL_LONG(GetLastError());
			}
			CloseServiceHandle(hsvc);
		} else {
			RETVAL_LONG(GetLastError());
		}
		CloseServiceHandle(hmgr);
	} else {
		RETVAL_LONG(GetLastError());
	}
}
Esempio n. 2
0
static void win32_handle_service_controls(INTERNAL_FUNCTION_PARAMETERS, long access, long status) /* {{{ */
{
	char *machine = NULL;
	char *service = NULL;
	size_t machine_len = 0;
	size_t	service_len = 0;
	SC_HANDLE hsvc;
	SC_HANDLE hmgr;
	SERVICE_STATUS st;

	if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!", &service, &service_len, &machine, &machine_len)) {
		RETURN_FALSE;
	}

	hmgr = OpenSCManager(machine, NULL, SC_MANAGER_ALL_ACCESS);
	if (hmgr) {
		hsvc = OpenService(hmgr, service, access);
		if (hsvc) {
			if (ControlService(hsvc, status, &st)) {
				RETVAL_LONG(NO_ERROR);
			} else {
				RETVAL_LONG(GetLastError());
			}
			CloseServiceHandle(hsvc);
		} else {
			RETVAL_LONG(GetLastError());
		}
		CloseServiceHandle(hmgr);
	} else {
		RETVAL_LONG(GetLastError());
	}
}
Esempio n. 3
0
/* {{{ proto mixed win32_query_service_status(string servicename [, string machine])
   Queries the status of a service */
static PHP_FUNCTION(win32_query_service_status)
{
	char *machine = NULL;
	char *service = NULL;
	size_t machine_len = 0;
	size_t	service_len = 0;
	SC_HANDLE hsvc;
	SC_HANDLE hmgr;
	SERVICE_STATUS_PROCESS *st;
	DWORD size;

	if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!", &service, &service_len, &machine, &machine_len)) {
		RETURN_FALSE;
	}

	hmgr = OpenSCManager(machine, NULL, GENERIC_READ);
	if (hmgr) {
		hsvc = OpenService(hmgr, service, SERVICE_QUERY_STATUS);
		if (hsvc) {
			size = sizeof(*st);
			st = emalloc(size);
			if (!QueryServiceStatusEx(hsvc, SC_STATUS_PROCESS_INFO,
					(LPBYTE)st, size, &size)) {
				if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
					RETVAL_LONG(GetLastError());
					goto out_fail;
				}
				st = erealloc(st, size);
				if (!QueryServiceStatusEx(hsvc, SC_STATUS_PROCESS_INFO,
						(LPBYTE)st, size, &size)) {
					RETVAL_LONG(GetLastError());
					goto out_fail;
				}
			}
			/* map the struct to an array */
			array_init(return_value);
			add_assoc_long(return_value, "ServiceType", st->dwServiceType);
			add_assoc_long(return_value, "CurrentState", st->dwCurrentState);
			add_assoc_long(return_value, "ControlsAccepted", st->dwControlsAccepted);
			add_assoc_long(return_value, "Win32ExitCode", st->dwWin32ExitCode);
			add_assoc_long(return_value, "ServiceSpecificExitCode", st->dwServiceSpecificExitCode);
			add_assoc_long(return_value, "CheckPoint", st->dwCheckPoint);
			add_assoc_long(return_value, "WaitHint", st->dwWaitHint);
			add_assoc_long(return_value, "ProcessId", st->dwProcessId);
			add_assoc_long(return_value, "ServiceFlags", st->dwServiceFlags);
out_fail:
			CloseServiceHandle(hsvc);
		} else {
			RETVAL_LONG(GetLastError());
		}
		CloseServiceHandle(hmgr);
	} else {
		RETVAL_LONG(GetLastError());
	}
}
static PHP_METHOD(HttpMessageParser, stream)
{
	php_http_message_parser_object_t *parser_obj;
	zend_error_handling zeh;
	zval *zmsg, *zstream;
	php_stream *s;
	zend_long flags;

	php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "rlz", &zstream, &flags, &zmsg), invalid_arg, return);

	zend_replace_error_handling(EH_THROW, php_http_exception_unexpected_val_class_entry, &zeh);
	php_stream_from_zval(s, zstream);
	zend_restore_error_handling(&zeh);

	parser_obj = PHP_HTTP_OBJ(NULL, getThis());
	RETVAL_LONG(php_http_message_parser_parse_stream(parser_obj->parser, &parser_obj->buffer, s, flags, &parser_obj->parser->message));

	ZVAL_DEREF(zmsg);
	zval_dtor(zmsg);
	ZVAL_NULL(zmsg);
	if (parser_obj->parser->message) {
		php_http_message_t *msg_cpy = php_http_message_copy(parser_obj->parser->message, NULL);
		php_http_message_object_t *msg_obj = php_http_message_object_new_ex(php_http_message_class_entry, msg_cpy);
		ZVAL_OBJ(zmsg, &msg_obj->zo);
	}
}
static PHP_METHOD(HttpMessageParser, getState)
{
	php_http_message_parser_object_t *parser_obj = PHP_HTTP_OBJ(NULL, getThis());

	zend_parse_parameters_none();
	/* always return the real state */
	RETVAL_LONG(php_http_message_parser_state_is(parser_obj->parser));
}
Esempio n. 6
0
/* {{{ proto int ImagickPixel::getColorValueQuantum(int color)
	Gets the quantum color of the ImagickPixel
*/
PHP_METHOD(imagickpixel, getcolorvaluequantum)
{
	php_imagickpixel_object *internp;
	long color, color_value;

	/* Parse parameters given to function */
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &color) == FAILURE) {
		return;
	}
	
	internp = (php_imagickpixel_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
	
	switch (color) {

		case IMAGICKCOLORBLACK:
			color_value = PixelGetBlackQuantum(internp->pixel_wand);
		break;

		case IMAGICKCOLORBLUE:
			color_value = PixelGetBlueQuantum(internp->pixel_wand);
		break;

		case IMAGICKCOLORCYAN:
			color_value = PixelGetCyanQuantum(internp->pixel_wand);
		break;

		case IMAGICKCOLORGREEN:
			color_value = PixelGetGreenQuantum(internp->pixel_wand);
		break;

		case IMAGICKCOLORRED:
			color_value = PixelGetRedQuantum(internp->pixel_wand);
		break;

		case IMAGICKCOLORYELLOW:
			color_value = PixelGetYellowQuantum(internp->pixel_wand);
		break;

		case IMAGICKCOLORMAGENTA:
			color_value = PixelGetMagentaQuantum(internp->pixel_wand);
		break;

		case IMAGICKCOLOROPACITY:
			color_value = PixelGetOpacityQuantum(internp->pixel_wand);
		break;

		case IMAGICKCOLORALPHA:
			color_value = PixelGetAlphaQuantum(internp->pixel_wand);
		break;

		default:
			php_imagick_throw_exception (IMAGICKPIXEL_CLASS, "Unknown color type" TSRMLS_CC);
			return;
		break;
	}
	RETVAL_LONG(color_value);
}
Esempio n. 7
0
/* {{{ proto bool ImagickPixel::getIndex()
	Gets the colormap index of the pixel wand 
*/
PHP_METHOD(imagickpixel, getindex)
{
	php_imagickpixel_object *internp;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) {
		return;
	}
	
	internp = (php_imagickpixel_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
	RETVAL_LONG(PixelGetIndex(internp->pixel_wand));
}
Esempio n. 8
0
/* {{{ proto bool ImagickPixel::getIndex()
	Gets the colormap index of the pixel wand
*/
PHP_METHOD(imagickpixel, getindex)
{
    php_imagickpixel_object *internp;

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

    internp = Z_IMAGICKPIXEL_P(getThis());
    RETVAL_LONG(PixelGetIndex(internp->pixel_wand));
}
Esempio n. 9
0
/* {{ proto int GmagickDraw::getGravity()
   Gets the gravity value
*/
PHP_METHOD(gmagickdraw, getgravity)
{
   php_gmagickdraw_object *internd;

   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) {
      return;
   }

   internd = (php_gmagickdraw_object *)zend_object_store_get_object(getThis() TSRMLS_CC);

   RETVAL_LONG(DrawGetGravity(internd->drawing_wand));
}
Esempio n. 10
0
/* {{{ proto float GmagickPixel::getColorValueQuantum(int color )
	Gets the quantum color of the GmagickPixel.
*/
PHP_METHOD(gmagickpixel, getcolorvaluequantum)
{
	php_gmagickpixel_object *internp;
	zend_long color_quantum;
	Quantum color_value_quantum = 0;

	/* Parse parameters given to function */
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &color_quantum) == FAILURE) {
		return;
	}

	internp = Z_GMAGICKPIXEL_OBJ_P(getThis());

	switch (color_quantum) {

		case GMAGICK_COLOR_BLACK:
			color_value_quantum = PixelGetBlackQuantum(internp->pixel_wand);
			break;

		case GMAGICK_COLOR_BLUE:
			color_value_quantum = PixelGetBlueQuantum(internp->pixel_wand);
			break;

		case GMAGICK_COLOR_CYAN:
			color_value_quantum = PixelGetCyanQuantum(internp->pixel_wand);
			break;

		case GMAGICK_COLOR_GREEN:
			color_value_quantum = PixelGetGreenQuantum(internp->pixel_wand);
			break;

		case GMAGICK_COLOR_RED:
			color_value_quantum = PixelGetRedQuantum(internp->pixel_wand);
			break;

		case GMAGICK_COLOR_YELLOW:
			color_value_quantum = PixelGetYellowQuantum(internp->pixel_wand);
			break;

		case GMAGICK_COLOR_MAGENTA:
			color_value_quantum = PixelGetMagentaQuantum(internp->pixel_wand);
			break;

		case GMAGICK_COLOR_OPACITY:
			color_value_quantum = PixelGetOpacityQuantum(internp->pixel_wand);
			break;

		default:
			zend_throw_exception_ex(php_gmagickpixel_exception_class_entry, 2 TSRMLS_CC, "Unknown color type: %d", color_quantum);
			RETURN_NULL();
	}
	RETVAL_LONG(color_value_quantum);
}
Esempio n. 11
0
// CHash method addTarget(<target>[, <weight>]) -> long
PHP_METHOD(CHash, addTarget)
{
    chash_object *instance = (chash_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
    char         *target;
    int          length;
    long         weight = 1;

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &target, &length, &weight) != SUCCESS || length == 0)
    {
        RETURN_LONG(chash_return(instance, CHASH_ERROR_INVALID_PARAMETER))
    }
    RETVAL_LONG(chash_return(instance, chash_add_target(&(instance->context), target, weight)));
}
Esempio n. 12
0
/* {{{ proto int GmagickPixel::getColorCount()
	Returns the color count associated with this color.
*/
PHP_METHOD(gmagickpixel, getcolorcount)
{
	php_gmagickpixel_object *internp;
	zend_long color_count;
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) {
		return;
	}

	internp = Z_GMAGICKPIXEL_OBJ_P(getThis());

	color_count = PixelGetColorCount(internp->pixel_wand);
	RETVAL_LONG(color_count);
}
Esempio n. 13
0
/* {{{ proto int GmagickDraw::getStrokeLineJoin()
        Returns the shape to be used at the corners of paths (or other vector shapes) when they are stroked. Values of LineJoin are UndefinedJoin, MiterJoin, RoundJoin, and BevelJoin.
*/
PHP_METHOD(gmagickdraw, getstrokelinejoin)
{
        php_gmagickdraw_object *internd;
        long line_join;

        if (zend_parse_parameters_none() == FAILURE) {
                return;
        }
        
        internd = (php_gmagickdraw_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
        line_join = DrawGetStrokeLineJoin(internd->drawing_wand);

        RETVAL_LONG(line_join);
}
Esempio n. 14
0
/* {{{ proto int GmagickDraw::getStrokeMiterLimit()
        Returns the miter limit. When two line segments meet at a sharp angle and miter joins have been specified for 'lineJoin', it is possible for the miter to extend far beyond the thickness of the line stroking the path. The miterLimit' imposes a limit on the ratio of the miter length to the 'lineWidth'.
*/
PHP_METHOD(gmagickdraw, getstrokemiterlimit)
{
        php_gmagickdraw_object *internd;
        unsigned long miter_limit;

        if (zend_parse_parameters_none() == FAILURE) {
                return;
        }
        
        internd = (php_gmagickdraw_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
        miter_limit = DrawGetStrokeMiterLimit(internd->drawing_wand);

        RETVAL_LONG(miter_limit);
}
Esempio n. 15
0
File: gmp.c Progetto: AllardJ/Tomato
/* {{{ _gmp_unary_opl
 */
static inline void _gmp_unary_opl(INTERNAL_FUNCTION_PARAMETERS, gmp_unary_opl_t gmp_op)
{
	zval **a_arg;
	mpz_t *gmpnum_a;
	int temp_a;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &a_arg) == FAILURE){
		return;
	}
	
	FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a);
	RETVAL_LONG(gmp_op(*gmpnum_a));
	FREE_GMP_TEMP(temp_a);
}
Esempio n. 16
0
/* {{{ proto int octdec(string octal_number)
   Returns the decimal equivalent of an octal string */
void php3_octdec(INTERNAL_FUNCTION_PARAMETERS)
{
	pval *arg;
	long ret;
	TLS_VARS;
	
	if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) {
		WRONG_PARAM_COUNT;
	}

	convert_to_string(arg);

	ret = _php3_basetolong(arg, 8);
	RETVAL_LONG(ret);
}
/* {{{ proto string CursorId::__toString()
   Returns the string representation of the CursorId */
PHP_METHOD(CursorId, __toString)
{
	php_phongo_cursorid_t    *intern;
	(void)return_value_ptr; (void)return_value_used;


	intern = (php_phongo_cursorid_t *)zend_object_store_get_object(getThis() TSRMLS_CC);

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

	RETVAL_LONG(intern->id);
	convert_to_string(return_value);
}
Esempio n. 18
0
/* {{{ proto string CursorId::__toString()
   Returns the string representation of the CursorId */
PHP_METHOD(CursorId, __toString)
{
	php_phongo_cursorid_t    *intern;
	SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)


	intern = Z_CURSORID_OBJ_P(getThis());

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

	RETVAL_LONG(intern->id);
	convert_to_string(return_value);
}
Esempio n. 19
0
bool ssdb_geo_set(
		SSDBSock *ssdb_sock,
		char *key,
		int key_len,
		char *member_key,
		int member_key_len,
		double latitude,
		double longitude,
		INTERNAL_FUNCTION_PARAMETERS) {
	GeoHashBits hash;
	if (!geohashEncodeWGS84(latitude, longitude, GEO_STEP_MAX, &hash)) {
		return false;
	}

	char *member_score_str = NULL, *cmd = NULL;
	GeoHashFix52Bits bits = geohashAlign52Bits(hash);
	int member_score_str_len = spprintf(&member_score_str, 0, "%lld", bits);
	int key_free = ssdb_key_prefix(ssdb_sock, &key, &key_len);
	int cmd_len = ssdb_cmd_format_by_str(ssdb_sock, &cmd, ZEND_STRL("zset"), key, key_len, member_key, member_key_len, member_score_str, member_score_str_len, NULL);

	efree(member_score_str);
	if (key_free) efree(key);
	if (0 == cmd_len) return false;

	if (ssdb_sock_write(ssdb_sock, cmd, cmd_len) < 0) {
		efree(cmd);
		return false;
	}
	efree(cmd);

	SSDBResponse *ssdb_response = ssdb_sock_read(ssdb_sock);
	if (ssdb_response == NULL || ssdb_response->status != SSDB_IS_OK) {
		ssdb_response_free(ssdb_response);
		return false;
	}

	ssdb_response_free(ssdb_response);
	RETVAL_LONG(bits);

	return true;
}
static PHP_METHOD(HttpMessageParser, parse)
{
	php_http_message_parser_object_t *parser_obj;
	zval *zmsg;
	char *data_str;
	size_t data_len;
	zend_long flags;

	php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "slz", &data_str, &data_len, &flags, &zmsg), invalid_arg, return);

	parser_obj = PHP_HTTP_OBJ(NULL, getThis());
	php_http_buffer_append(&parser_obj->buffer, data_str, data_len);
	RETVAL_LONG(php_http_message_parser_parse(parser_obj->parser, &parser_obj->buffer, flags, &parser_obj->parser->message));

	ZVAL_DEREF(zmsg);
	zval_dtor(zmsg);
	ZVAL_NULL(zmsg);
	if (parser_obj->parser->message) {
		php_http_message_t *msg_cpy = php_http_message_copy(parser_obj->parser->message, NULL);
		php_http_message_object_t *msg_obj = php_http_message_object_new_ex(php_http_message_class_entry, msg_cpy);
		ZVAL_OBJ(zmsg, &msg_obj->zo);
	}
}
Esempio n. 21
0
PHP_METHOD(jsonrpc_server, rpcformat)
{
  zval *payload;
  zval *object;
  zval **method = NULL;
  zval **jsonrpc = NULL;
  zval **params = NULL;

  object = getThis();

  payload = zend_read_property(
      php_jsonrpc_server_entry, object, "payload", sizeof("payload")-1, 0 TSRMLS_CC
    );

  if (Z_TYPE_P(payload) != IS_ARRAY)
  {
    RETVAL_LONG(-32600);
    return ;
  }

  if (!zend_symtable_exists(Z_ARRVAL_P(payload), "jsonrpc", strlen("jsonrpc")+1))
  {
    RETVAL_LONG(-32600);
    return ;
  }

  if (!zend_symtable_exists(Z_ARRVAL_P(payload), "method", strlen("method")+1))
  {
    RETVAL_LONG(-32601);
    return ;
  }

  //MAKE_STD_ZVAL(&method);
  if (zend_hash_find(Z_ARRVAL_P(payload), "method", strlen("method")+1, (void **)&method) == FAILURE)
  {
    RETVAL_LONG(-32601);
    return ;
  }

  if (Z_TYPE_PP(method) != IS_STRING)
  {
    RETVAL_LONG(-32601);
    return ;
  }

  //MAKE_STD_ZVAL(&jsonrpc);
  if (zend_hash_find(Z_ARRVAL_P(payload), "jsonrpc", strlen("jsonrpc")+1, (void **)&jsonrpc) == FAILURE)
  {
    RETVAL_LONG(-32600);
    return ;
  }

  if (strcmp(Z_STRVAL_PP(jsonrpc),"2.0") != 0)
  {
    RETVAL_LONG(-32600);
    return ;
  }

  
  //MAKE_STD_ZVAL(&params);
  if (zend_hash_find(Z_ARRVAL_P(payload), "params", strlen("params")+1, (void **)&params) == FAILURE)
  {
    RETVAL_LONG(-32602);
    return ;
  }
  if (Z_TYPE_PP(params) != IS_ARRAY)
  {
    RETVAL_LONG(-32602);
    return ;
  }

  RETVAL_LONG(0);
  return ;

}
Esempio n. 22
0
SPL_METHOD(SplCharIterator, key)
{
	FETCH_OBJECT

	RETVAL_LONG(obj->offset);
}
Esempio n. 23
0
/* {{{ proto long win32_create_service(array details [, string machine])
   Creates a new service entry in the SCM database */
static PHP_FUNCTION(win32_create_service)
{
	zval *tmp;
	zval *details;
	char *machine = NULL;
	size_t machine_len;
	char *service = NULL;
	char *display;
	char *user;
	char *password;
	char *path;
	char *params;
	long svc_type;
	long start_type;
	long error_control;
	char *load_order;
	char **deps = NULL;
	char *desc;
	BOOL delayed_start;
	SC_HANDLE hsvc, hmgr;
	char *path_and_params;
	SERVICE_DESCRIPTION srvc_desc;
	SERVICE_DELAYED_AUTO_START_INFO srvc_delayed_start;
	OSVERSIONINFO osvi;
	DWORD base_priority;
	HKEY hKey;
	char *service_key;
	long registry_result;

	if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|s!", &details, &machine, &machine_len)) {
		RETURN_FALSE;
	}

#define STR_DETAIL(name, var, def) \
	if ((tmp = zend_hash_str_find(Z_ARRVAL_P(details), name, sizeof(name)-1)) != NULL) { \
		if (IS_NULL != Z_TYPE_P(tmp)) { \
			convert_to_string_ex(tmp); \
		} else { \
			convert_to_null_ex(tmp); \
		} \
		if (strlen(Z_STRVAL_P(tmp)) != Z_STRLEN_P(tmp)) { \
			php_error_docref(NULL TSRMLS_CC, E_WARNING, "malformed " name); \
			RETURN_FALSE; \
		} \
		var = Z_STRVAL_P(tmp); \
	} else { \
		var = def; \
	}

#define INT_DETAIL(name, var, def) \
	if ((tmp = zend_hash_find(Z_ARRVAL_P(details), zend_string_init(name, sizeof(name), 0))) != NULL) { \
		convert_to_long_ex(tmp); \
		var = Z_LVAL_P(tmp); \
	} else { \
		var = def; \
	}

#define BOOL_DETAIL(name, var, def) \
	if ((tmp = zend_hash_find(Z_ARRVAL_P(details), zend_string_init(name, sizeof(name), 0))) != NULL) { \
		convert_to_boolean_ex(tmp); \
		var = Z_LVAL_P(tmp); \
	} else { \
		var = def; \
	}

	STR_DETAIL("service", service, NULL);
	STR_DETAIL("display", display, NULL);
	STR_DETAIL("user", user, NULL);
	STR_DETAIL("password", password, "");
	STR_DETAIL("path", path, NULL);
	STR_DETAIL("params", params, "");
	STR_DETAIL("load_order", load_order, NULL);
	STR_DETAIL("description", desc, NULL);
	INT_DETAIL("svc_type", svc_type, SERVICE_WIN32_OWN_PROCESS);
	INT_DETAIL("start_type", start_type, SERVICE_AUTO_START);
	INT_DETAIL("error_control", error_control, SERVICE_ERROR_IGNORE);
	BOOL_DETAIL("delayed_start", delayed_start, 0); /* Allow Vista+ delayed service start. */
	INT_DETAIL("base_priority", base_priority, NORMAL_PRIORITY_CLASS);

	if (service == NULL) {
		php_error_docref(NULL TSRMLS_CC, E_WARNING, "missing vital parameters");
		RETURN_FALSE;
	}

	srvc_desc.lpDescription = desc;
	srvc_delayed_start.fDelayedAutostart = delayed_start;

	/* Connect to the SCManager. */
	hmgr = OpenSCManager(machine, NULL, SC_MANAGER_ALL_ACCESS);

	/* Quit if no connection. */
	if (!hmgr) {
		RETURN_LONG(GetLastError());
	}

	/* Build service path and parameters. */
	if (path == NULL) {
		DWORD len;
		char buf[MAX_PATH];

		len = GetModuleFileName(NULL, buf, sizeof(buf));
		buf[len] = '\0';

		if (strchr(buf, ' '))
			spprintf(&path_and_params, 0, "\"%s\" %s", buf, params);
		else
			spprintf(&path_and_params, 0, "%s %s", buf, params);
	} else {
		if (strchr(path, ' '))
			spprintf(&path_and_params, 0, "\"%s\" %s", path, params);
		else
			spprintf(&path_and_params, 0, "%s %s", path, params);
	}

	/* If interact with desktop is set and no username supplied (Only LocalSystem allows InteractWithDesktop) then pass the path and params through %COMSPEC% /C "..." */
	if (SERVICE_INTERACTIVE_PROCESS & svc_type && user == NULL) {
		spprintf(&path_and_params, 0, "\"%s\" /C \"%s\"", getenv("COMSPEC"), path_and_params);
	}

	/* Register the service. */
	hsvc = CreateService(hmgr,
			service,
			display ? display : service,
			SERVICE_ALL_ACCESS,
			svc_type,
			start_type,
			error_control,
			path_and_params,
			load_order,
			NULL,
			(LPCSTR)deps,
			(LPCSTR)user,
			(LPCSTR)password);

	efree(path_and_params);

	/* Get the current OS version. */
	osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
	GetVersionEx(&osvi);

	/* If there was an error :
	   - Creating the service
	   - Setting the service description
	   - Setting the delayed start - only on Windows Vista and greater and if the service start type is auto start.
	   then track the error. */
	if (	!hsvc ||
		!ChangeServiceConfig2(hsvc, SERVICE_CONFIG_DESCRIPTION, &srvc_desc) ||
		(start_type & SERVICE_AUTO_START && osvi.dwMajorVersion >= 6 && !ChangeServiceConfig2(hsvc, SERVICE_CONFIG_DELAYED_AUTO_START_INFO, &srvc_delayed_start))
		) {
		RETVAL_LONG(GetLastError());
	} else {
		RETVAL_LONG(NO_ERROR);
	}

	CloseServiceHandle(hsvc);
	CloseServiceHandle(hmgr);

	/* Store the base_priority in the registry. */
	spprintf(&service_key, 0, "%s%s", SERVICES_REG_KEY_ROOT, service);
	if (ERROR_SUCCESS != (registry_result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, service_key, 0, KEY_ALL_ACCESS, &hKey))) {
		RETVAL_LONG(registry_result);
	} else if (ERROR_SUCCESS != (registry_result = RegSetValueEx(hKey, SERVICES_REG_BASE_PRIORITY, 0, REG_DWORD, (CONST BYTE*)&base_priority, sizeof(REG_DWORD)))) {
		RETVAL_LONG(registry_result);
	} else {
		RegCloseKey(hKey);
	}
	efree(service_key);

}
Esempio n. 24
0
static void php_facedetect(INTERNAL_FUNCTION_PARAMETERS, int return_type)
{
	char *file, *casc;
	long flen, clen;

	zval *array;

	CvHaarClassifierCascade* cascade;
	IplImage *img, *gray;
	CvMemStorage *storage;
	CvSeq *faces;
	CvRect *rect;

	if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &file, &flen, &casc, &clen) == FAILURE) {
		RETURN_NULL();
	}

	img = cvLoadImage(file, 1);
	if(!img) {
		RETURN_FALSE;
	}

	cascade = (CvHaarClassifierCascade*)cvLoad(casc, 0, 0, 0);
	if(!cascade) {
		RETURN_FALSE;
	}

	gray = cvCreateImage(cvSize(img->width, img->height), 8, 1);
	cvCvtColor(img, gray, CV_BGR2GRAY);
	cvEqualizeHist(gray, gray);

	storage = cvCreateMemStorage(0);

	faces = cvHaarDetectObjects(gray, cascade, storage, 1.1, 2, CV_HAAR_DO_CANNY_PRUNING, cvSize(0, 0), cvSize(0, 0));

	if(return_type) {

		array_init(return_value);

		if(faces && faces->total > 0) {
			int i;
			for(i = 0; i < faces->total; i++) {
				MAKE_STD_ZVAL(array);
				array_init(array);

				rect = (CvRect *)cvGetSeqElem(faces, i);

				add_assoc_long(array, "x", rect->x);
				add_assoc_long(array, "y", rect->y);
				add_assoc_long(array, "w", rect->width);
				add_assoc_long(array, "h", rect->height);

				add_next_index_zval(return_value, array);
			}
		}
	} else {
		RETVAL_LONG(faces ? faces->total : 0);
	}

	cvReleaseMemStorage(&storage);
	cvReleaseImage(&gray);
	cvReleaseImage(&img);
}
Esempio n. 25
0
/* {{{ _php_mb_regex_ereg_exec */
static void _php_mb_regex_ereg_exec(INTERNAL_FUNCTION_PARAMETERS, int icase)
{
	zval *arg_pattern, *array = NULL;
	char *string;
	size_t string_len;
	php_mb_regex_t *re;
	OnigRegion *regs = NULL;
	int i, match_len, beg, end;
	OnigOptionType options;
	char *str;

	if (zend_parse_parameters(ZEND_NUM_ARGS(), "zs|z/", &arg_pattern, &string, &string_len, &array) == FAILURE) {
		RETURN_FALSE;
	}

	if (!php_mb_check_encoding(
	string,
	string_len,
	_php_mb_regex_mbctype2name(MBREX(current_mbctype))
	)) {
		if (array != NULL) {
			zval_dtor(array);
			array_init(array);
		}
		RETURN_FALSE;
	}

	if (array != NULL) {
		zval_dtor(array);
		array_init(array);
	}

	options = MBREX(regex_default_options);
	if (icase) {
		options |= ONIG_OPTION_IGNORECASE;
	}

	/* compile the regular expression from the supplied regex */
	if (Z_TYPE_P(arg_pattern) != IS_STRING) {
		/* we convert numbers to integers and treat them as a string */
		if (Z_TYPE_P(arg_pattern) == IS_DOUBLE) {
			convert_to_long_ex(arg_pattern);	/* get rid of decimal places */
		}
		convert_to_string_ex(arg_pattern);
		/* don't bother doing an extended regex with just a number */
	}

	if (Z_STRLEN_P(arg_pattern) == 0) {
		php_error_docref(NULL, E_WARNING, "empty pattern");
		RETVAL_FALSE;
		goto out;
	}

	re = php_mbregex_compile_pattern(Z_STRVAL_P(arg_pattern), Z_STRLEN_P(arg_pattern), options, MBREX(current_mbctype), MBREX(regex_default_syntax));
	if (re == NULL) {
		RETVAL_FALSE;
		goto out;
	}

	regs = onig_region_new();

	/* actually execute the regular expression */
	if (onig_search(re, (OnigUChar *)string, (OnigUChar *)(string + string_len), (OnigUChar *)string, (OnigUChar *)(string + string_len), regs, 0) < 0) {
		RETVAL_FALSE;
		goto out;
	}

	match_len = 1;
	str = string;
	if (array != NULL) {

		match_len = regs->end[0] - regs->beg[0];
		for (i = 0; i < regs->num_regs; i++) {
			beg = regs->beg[i];
			end = regs->end[i];
			if (beg >= 0 && beg < end && (size_t)end <= string_len) {
				add_index_stringl(array, i, (char *)&str[beg], end - beg);
			} else {
				add_index_bool(array, i, 0);
			}
		}
	}

	if (match_len == 0) {
		match_len = 1;
	}
	RETVAL_LONG(match_len);
out:
	if (regs != NULL) {
		onig_region_free(regs, 1);
	}
}
Esempio n. 26
0
/* {{{ proto Quantum ImagickPixel::getColorValueQuantum(int color)
	Gets the quantum value of a color in the ImagickPixel. Quantum is a float if ImageMagick was compiled with HDRI
	otherwise an integer.
*/
PHP_METHOD(imagickpixel, getcolorvaluequantum)
{
    php_imagickpixel_object *internp;
    im_long color;
    Quantum color_value;

    /* Parse parameters given to function */
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &color) == FAILURE) {
        return;
    }

    internp = Z_IMAGICKPIXEL_P(getThis());

    switch (color) {

    case PHP_IMAGICK_COLOR_BLACK:
        color_value = PixelGetBlackQuantum(internp->pixel_wand);
        break;

    case PHP_IMAGICK_COLOR_BLUE:
        color_value = PixelGetBlueQuantum(internp->pixel_wand);
        break;

    case PHP_IMAGICK_COLOR_CYAN:
        color_value = PixelGetCyanQuantum(internp->pixel_wand);
        break;

    case PHP_IMAGICK_COLOR_GREEN:
        color_value = PixelGetGreenQuantum(internp->pixel_wand);
        break;

    case PHP_IMAGICK_COLOR_RED:
        color_value = PixelGetRedQuantum(internp->pixel_wand);
        break;

    case PHP_IMAGICK_COLOR_YELLOW:
        color_value = PixelGetYellowQuantum(internp->pixel_wand);
        break;

    case PHP_IMAGICK_COLOR_MAGENTA:
        color_value = PixelGetMagentaQuantum(internp->pixel_wand);
        break;

#if MagickLibVersion < 0x700
    case PHP_IMAGICK_COLOR_OPACITY:
        color_value = PixelGetOpacityQuantum(internp->pixel_wand);
        break;
#endif

    case PHP_IMAGICK_COLOR_ALPHA:
        color_value = PixelGetAlphaQuantum(internp->pixel_wand);
        break;

    default:
        php_imagick_throw_exception (IMAGICKPIXEL_CLASS, "Unknown color type" TSRMLS_CC);
        return;
        break;
    }

#if MAGICKCORE_HDRI_ENABLE
    RETVAL_DOUBLE(color_value);
#else
    RETVAL_LONG(color_value);
#endif
}
Esempio n. 27
0
PHP_METHOD(MongoCursor, count) {
  zval *response, *data, *db;
  zval **n;
  mongo_cursor *cursor;
  mongo_db *db_struct;

  cursor = (mongo_cursor*)zend_object_store_get_object(getThis() TSRMLS_CC);
  MONGO_CHECK_INITIALIZED(cursor->link, MongoCursor);


  // fake a MongoDB object
  MAKE_STD_ZVAL(db);
  object_init_ex(db, mongo_ce_DB);
  db_struct = (mongo_db*)zend_object_store_get_object(db TSRMLS_CC);

  db_struct->link = cursor->resource;
  zval_add_ref(&cursor->resource);
  MAKE_STD_ZVAL(db_struct->name);
  ZVAL_STRING(db_struct->name, estrndup(cursor->ns, strchr(cursor->ns, '.') - cursor->ns), 0);


  // create query
  MAKE_STD_ZVAL(data);
  object_init(data);

  // "count" => "collectionName"
  add_property_string(data, "count", strchr(cursor->ns, '.')+1, 1);

  if (cursor->query) {
    zval **inner_query;
    if (zend_hash_find(HASH_P(cursor->query), "query", strlen("query")+1, (void**)&inner_query) == SUCCESS) {
      add_property_zval(data, "query", *inner_query);
      zval_add_ref(inner_query);
    }
  }
  if (cursor->fields) {
    add_property_zval(data, "fields", cursor->fields);
    zval_add_ref(&cursor->fields);
  }

  MAKE_STD_ZVAL(response);

  PUSH_PARAM(data); PUSH_PARAM((void*)1);
  PUSH_EO_PARAM();
  MONGO_METHOD(MongoDB, command)(1, response, &response, db, return_value_used TSRMLS_CC);
  POP_EO_PARAM();
  POP_PARAM(); POP_PARAM();

  zval_ptr_dtor(&data);

  // prep results
  if (zend_hash_find(HASH_P(response), "n", 2, (void**)&n) == SUCCESS) {
    // don't allow count to return more than cursor->limit
    if (cursor->limit > 0 && Z_DVAL_PP(n) > cursor->limit) {
      RETVAL_LONG(cursor->limit);
    }
    else {
      convert_to_long(*n);
      RETVAL_ZVAL(*n, 1, 0);
    }
    zval_ptr_dtor(&response);
  }
  else {
    RETURN_ZVAL(response, 0, 0);
  }

  zend_objects_store_del_ref(db TSRMLS_CC);
  zval_ptr_dtor(&db);
}