Initializes all syslog-related variables */
PHP_FUNCTION(define_syslog_variables)
{
+ if (ZEND_NUM_ARGS() != 0) {
+ php_error(E_WARNING, "%s() expects no parameters, %d given",
+ get_active_function_name(TSRMLS_C), ZEND_NUM_ARGS());
+ return;
+ }
+
if (!BG(syslog_started)) {
start_syslog(TSRMLS_C);
}
*/
PHP_FUNCTION(openlog)
{
- pval **ident, **option, **facility;
+ char *ident;
+ long option, facility;
+ int ident_len;
- if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &ident, &option, &facility) == FAILURE) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sll", &ident, &option,
+ &facility) == FAILURE) {
+ return;
}
- convert_to_string_ex(ident);
- convert_to_long_ex(option);
- convert_to_long_ex(facility);
if (BG(syslog_device)) {
efree(BG(syslog_device));
}
- BG(syslog_device) = estrndup(Z_STRVAL_PP(ident), Z_STRLEN_PP(ident));
- openlog(BG(syslog_device), Z_LVAL_PP(option), Z_LVAL_PP(facility));
+ BG(syslog_device) = estrndup(ident, ident_len);
+ openlog(BG(syslog_device), option, facility);
RETURN_TRUE;
}
/* }}} */
Close connection to system logger */
PHP_FUNCTION(closelog)
{
+ if (ZEND_NUM_ARGS() != 0) {
+ php_error(E_WARNING, "%s() expects no parameters, %d given",
+ get_active_function_name(TSRMLS_C), ZEND_NUM_ARGS());
+ return;
+ }
+
closelog();
if (BG(syslog_device)) {
efree(BG(syslog_device));
Generate a system log message */
PHP_FUNCTION(syslog)
{
- pval **priority, **message;
+ long priority;
+ char *message;
+ int message_len;
- if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &priority, &message) == FAILURE) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &priority,
+ &message, &message_len) == FAILURE) {
+ return;
}
- convert_to_long_ex(priority);
- convert_to_string_ex(message);
/*
* CAVEAT: if the message contains patterns such as "%s",
* this will cause problems.
*/
- php_syslog(Z_LVAL_PP(priority), "%.500s", Z_STRVAL_PP(message));
+ php_syslog(priority, "%.500s", message);
RETURN_TRUE;
}
/* }}} */
#include "php_lcg.h"
#include "uniqid.h"
-#define MORE_ENTROPY (argc == 2 && Z_LVAL_PP(flags))
-
/* {{{ proto string uniqid(string prefix, [bool more_entropy])
Generate a unique id */
PHP_FUNCTION(uniqid)
{
#ifdef HAVE_GETTIMEOFDAY
- pval **prefix, **flags;
+ char *prefix;
+ zend_bool more_entropy = 0;
char uniqid[138];
- int sec, usec, argc;
+ int sec, usec, argc, prefix_len;
struct timeval tv;
argc = ZEND_NUM_ARGS();
- if (argc < 1 || argc > 2 || zend_get_parameters_ex(argc, &prefix, &flags)) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(prefix);
- if (argc == 2) {
- convert_to_boolean_ex(flags);
+ if (zend_parse_parameters(argc TSRMLS_CC, "s|b", &prefix, &prefix_len,
+ &more_entropy)) {
+ return;
}
/* Do some bounds checking since we are using a char array. */
- if (Z_STRLEN_PP(prefix) > 114) {
+ if (prefix_len > 114) {
php_error(E_WARNING, "The prefix to uniqid should not be more than 114 characters.");
return;
}
#if HAVE_USLEEP && !defined(PHP_WIN32)
- if (!MORE_ENTROPY) {
+ if (!more_entropy) {
usleep(1);
}
#endif
/* The max value usec can have is 0xF423F, so we use only five hex
* digits for usecs.
*/
- if (MORE_ENTROPY) {
- sprintf(uniqid, "%s%08x%05x%.8f", Z_STRVAL_PP(prefix), sec, usec, php_combined_lcg(TSRMLS_C) * 10);
+ if (more_entropy) {
+ sprintf(uniqid, "%s%08x%05x%.8f", prefix, sec, usec, php_combined_lcg(TSRMLS_C) * 10);
} else {
- sprintf(uniqid, "%s%08x%05x", Z_STRVAL_PP(prefix), sec, usec);
+ sprintf(uniqid, "%s%08x%05x", prefix, sec, usec);
}
RETURN_STRING(uniqid, 1);