<commit_before>/*
   +----------------------------------------------------------------------+
   | This library is free software; you can redistribute it and/or        |
   | modify it under the terms of the GNU Lesser General Public           |
   | License as published by the Free Software Foundation; either         |
   | version 2.1 of the License, or (at your option) any later version.   | 
   |                                                                      |
   | This library is distributed in the hope that it will be useful,      |
   | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
   | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    |
   | Lesser General Public License for more details.                      | 
   |                                                                      |
   | You should have received a copy of the GNU Lesser General Public     |
   | License in the file LICENSE along with this library;                 |
   | if not, write to the                                                 | 
   |                                                                      |
   |   Free Software Foundation, Inc.,                                    |
   |   59 Temple Place, Suite 330,                                        |
   |   Boston, MA  02111-1307  USA                                        |
   +----------------------------------------------------------------------+
   | Authors: <NAME> <<EMAIL>>                        |
   +----------------------------------------------------------------------+
*/

/* $ Id: $ */ 

#include "php_uuid.h"

#if HAVE_UUID

/* {{{ uuid_functions[] */
zend_function_entry uuid_functions[] = {
	PHP_FE(uuid_create         , uuid_create_arg_info)
	PHP_FE(uuid_is_valid       , uuid_is_valid_arg_info)
	PHP_FE(uuid_compare        , uuid_compare_arg_info)
	PHP_FE(uuid_is_null        , uuid_is_null_arg_info)
#if HAVE_UUID_TYPE
	PHP_FE(uuid_type           , uuid_type_arg_info)
#endif /* HAVE_UUID_TYPE */
#if HAVE_UUID_VARIANT
	PHP_FE(uuid_variant        , uuid_variant_arg_info)
#endif /* HAVE_UUID_VARIANT */
	PHP_FE(uuid_time           , uuid_time_arg_info)
	PHP_FE(uuid_mac            , uuid_mac_arg_info)
	PHP_FE(uuid_parse          , uuid_parse_arg_info)
	PHP_FE(uuid_unparse        , uuid_unparse_arg_info)
	{ NULL, NULL, NULL }
};
/* }}} */


/* {{{ uuid_module_entry
 */
zend_module_entry uuid_module_entry = {
	STANDARD_MODULE_HEADER,
	"uuid",
	uuid_functions,
	PHP_MINIT(uuid),     /* Replace with NULL if there is nothing to do at php startup   */ 
	PHP_MSHUTDOWN(uuid), /* Replace with NULL if there is nothing to do at php shutdown  */
	PHP_RINIT(uuid),     /* Replace with NULL if there is nothing to do at request start */
	PHP_RSHUTDOWN(uuid), /* Replace with NULL if there is nothing to do at request end   */
	PHP_MINFO(uuid),
	PHP_UUID_VERSION, 
	STANDARD_MODULE_PROPERTIES
};
/* }}} */

#ifdef COMPILE_DL_UUID
ZEND_GET_MODULE(uuid)
#endif


/* {{{ PHP_MINIT_FUNCTION */
PHP_MINIT_FUNCTION(uuid)
{
#if UUID_VARIANT_NCS
	REGISTER_LONG_CONSTANT("UUID_VARIANT_NCS", UUID_VARIANT_NCS, CONST_PERSISTENT | CONST_CS);
#endif /* UUID_VARIANT_NCS */
#if UUID_VARIANT_DCE
	REGISTER_LONG_CONSTANT("UUID_VARIANT_DCE", UUID_VARIANT_DCE, CONST_PERSISTENT | CONST_CS);
#endif /* UUID_VARIANT_DCE */
#if UUID_VARIANT_MICROSOFT
	REGISTER_LONG_CONSTANT("UUID_VARIANT_MICROSOFT", UUID_VARIANT_MICROSOFT, CONST_PERSISTENT | CONST_CS);
#endif /* UUID_VARIANT_MICROSOFT */
#if UUID_VARIANT_OTHER
	REGISTER_LONG_CONSTANT("UUID_VARIANT_OTHER", UUID_VARIANT_OTHER, CONST_PERSISTENT | CONST_CS);
#endif /* UUID_VARIANT_OTHER */
	REGISTER_LONG_CONSTANT("UUID_TYPE_DEFAULT", 0, CONST_PERSISTENT | CONST_CS);
	REGISTER_LONG_CONSTANT("UUID_TYPE_TIME", UUID_TYPE_DCE_TIME, CONST_PERSISTENT | CONST_CS);
	REGISTER_LONG_CONSTANT("UUID_TYPE_DCE", UUID_TYPE_DCE_RANDOM, CONST_PERSISTENT | CONST_CS);
	REGISTER_LONG_CONSTANT("UUID_TYPE_NAME", UUID_TYPE_DCE_TIME, CONST_PERSISTENT | CONST_CS);
	REGISTER_LONG_CONSTANT("UUID_TYPE_RANDOM", UUID_TYPE_DCE_RANDOM, CONST_PERSISTENT | CONST_CS);
	REGISTER_LONG_CONSTANT("UUID_TYPE_NULL", -1, CONST_PERSISTENT | CONST_CS);
	REGISTER_LONG_CONSTANT("UUID_TYPE_INVALID", -42, CONST_PERSISTENT | CONST_CS);

	/* add your stuff here */

	return SUCCESS;
}
/* }}} */


/* {{{ PHP_MSHUTDOWN_FUNCTION */
PHP_MSHUTDOWN_FUNCTION(uuid)
{

	/* add your stuff here */

	return SUCCESS;
}
/* }}} */


/* {{{ PHP_RINIT_FUNCTION */
PHP_RINIT_FUNCTION(uuid)
{
	/* add your stuff here */

	return SUCCESS;
}
/* }}} */


/* {{{ PHP_RSHUTDOWN_FUNCTION */
PHP_RSHUTDOWN_FUNCTION(uuid)
{
	/* add your stuff here */

	return SUCCESS;
}
/* }}} */


/* {{{ PHP_MINFO_FUNCTION */
PHP_MINFO_FUNCTION(uuid)
{
	php_printf("UUID extension\n");
	php_info_print_table_start();
	php_info_print_table_row(2, "Version",PHP_UUID_VERSION " (stable)");
	php_info_print_table_row(2, "Released", "2008-04-01");
	php_info_print_table_row(2, "CVS Revision", "$Id$");
	php_info_print_table_row(2, "Authors", "<NAME> '<EMAIL>' (lead)\n");
	php_info_print_table_end();
	/* add your stuff here */

}
/* }}} */


/* {{{ proto string uuid_create([int uuid_type])
  Generate a new UUID */
PHP_FUNCTION(uuid_create)
{

	long uuid_type = 0;



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

	do {
		uuid_t uuid;
		char uuid_str[37];

		switch(uuid_type) {
		  case UUID_TYPE_DCE_TIME:
			uuid_generate_time(uuid);
			break;
		  case UUID_TYPE_DCE_RANDOM:<commit_msg>use constant instead of value (readability)<commit_after>/*
   +----------------------------------------------------------------------+
   | This library is free software; you can redistribute it and/or        |
   | modify it under the terms of the GNU Lesser General Public           |
   | License as published by the Free Software Foundation; either         |
   | version 2.1 of the License, or (at your option) any later version.   | 
   |                                                                      |
   | This library is distributed in the hope that it will be useful,      |
   | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
   | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    |
   | Lesser General Public License for more details.                      | 
   |                                                                      |
   | You should have received a copy of the GNU Lesser General Public     |
   | License in the file LICENSE along with this library;                 |
   | if not, write to the                                                 | 
   |                                                                      |
   |   Free Software Foundation, Inc.,                                    |
   |   59 Temple Place, Suite 330,                                        |
   |   Boston, MA  02111-1307  USA                                        |
   +----------------------------------------------------------------------+
   | Authors: <NAME> <<EMAIL>>                        |
   +----------------------------------------------------------------------+
*/

/* $ Id: $ */ 

#include "php_uuid.h"

#if HAVE_UUID

/* {{{ uuid_functions[] */
zend_function_entry uuid_functions[] = {
	PHP_FE(uuid_create         , uuid_create_arg_info)
	PHP_FE(uuid_is_valid       , uuid_is_valid_arg_info)
	PHP_FE(uuid_compare        , uuid_compare_arg_info)
	PHP_FE(uuid_is_null        , uuid_is_null_arg_info)
#if HAVE_UUID_TYPE
	PHP_FE(uuid_type           , uuid_type_arg_info)
#endif /* HAVE_UUID_TYPE */
#if HAVE_UUID_VARIANT
	PHP_FE(uuid_variant        , uuid_variant_arg_info)
#endif /* HAVE_UUID_VARIANT */
	PHP_FE(uuid_time           , uuid_time_arg_info)
	PHP_FE(uuid_mac            , uuid_mac_arg_info)
	PHP_FE(uuid_parse          , uuid_parse_arg_info)
	PHP_FE(uuid_unparse        , uuid_unparse_arg_info)
	{ NULL, NULL, NULL }
};
/* }}} */


/* {{{ uuid_module_entry
 */
zend_module_entry uuid_module_entry = {
	STANDARD_MODULE_HEADER,
	"uuid",
	uuid_functions,
	PHP_MINIT(uuid),     /* Replace with NULL if there is nothing to do at php startup   */ 
	PHP_MSHUTDOWN(uuid), /* Replace with NULL if there is nothing to do at php shutdown  */
	PHP_RINIT(uuid),     /* Replace with NULL if there is nothing to do at request start */
	PHP_RSHUTDOWN(uuid), /* Replace with NULL if there is nothing to do at request end   */
	PHP_MINFO(uuid),
	PHP_UUID_VERSION, 
	STANDARD_MODULE_PROPERTIES
};
/* }}} */

#ifdef COMPILE_DL_UUID
ZEND_GET_MODULE(uuid)
#endif


/* {{{ PHP_MINIT_FUNCTION */
PHP_MINIT_FUNCTION(uuid)
{
#if UUID_VARIANT_NCS
	REGISTER_LONG_CONSTANT("UUID_VARIANT_NCS", UUID_VARIANT_NCS, CONST_PERSISTENT | CONST_CS);
#endif /* UUID_VARIANT_NCS */
#if UUID_VARIANT_DCE
	REGISTER_LONG_CONSTANT("UUID_VARIANT_DCE", UUID_VARIANT_DCE, CONST_PERSISTENT | CONST_CS);
#endif /* UUID_VARIANT_DCE */
#if UUID_VARIANT_MICROSOFT
	REGISTER_LONG_CONSTANT("UUID_VARIANT_MICROSOFT", UUID_VARIANT_MICROSOFT, CONST_PERSISTENT | CONST_CS);
#endif /* UUID_VARIANT_MICROSOFT */
#if UUID_VARIANT_OTHER
	REGISTER_LONG_CONSTANT("UUID_VARIANT_OTHER", UUID_VARIANT_OTHER, CONST_PERSISTENT | CONST_CS);
#endif /* UUID_VARIANT_OTHER */
	REGISTER_LONG_CONSTANT("UUID_TYPE_DEFAULT", 0, CONST_PERSISTENT | CONST_CS);
	REGISTER_LONG_CONSTANT("UUID_TYPE_TIME", UUID_TYPE_DCE_TIME, CONST_PERSISTENT | CONST_CS);
	REGISTER_LONG_CONSTANT("UUID_TYPE_DCE", UUID_TYPE_DCE_RANDOM, CONST_PERSISTENT | CONST_CS);
	REGISTER_LONG_CONSTANT("UUID_TYPE_NAME", UUID_TYPE_DCE_TIME, CONST_PERSISTENT | CONST_CS);
	REGISTER_LONG_CONSTANT("UUID_TYPE_RANDOM", UUID_TYPE_DCE_RANDOM, CONST_PERSISTENT | CONST_CS);
	REGISTER_LONG_CONSTANT("UUID_TYPE_NULL", -1, CONST_PERSISTENT | CONST_CS);
	REGISTER_LONG_CONSTANT("UUID_TYPE_INVALID", -42, CONST_PERSISTENT | CONST_CS);

	/* add your stuff here */

	return SUCCESS;
}
/* }}} */


/* {{{ PHP_MSHUTDOWN_FUNCTION */
PHP_MSHUTDOWN_FUNCTION(uuid)
{

	/* add your stuff here */

	return SUCCESS;
}
/* }}} */


/* {{{ PHP_RINIT_FUNCTION */
PHP_RINIT_FUNCTION(uuid)
{
	/* add your stuff here */

	return SUCCESS;
}
/* }}} */


/* {{{ PHP_RSHUTDOWN_FUNCTION */
PHP_RSHUTDOWN_FUNCTION(uuid)
{
	/* add your stuff here */

	return SUCCESS;
}
/* }}} */


/* {{{ PHP_MINFO_FUNCTION */
PHP_MINFO_FUNCTION(uuid)
{
	php_printf("UUID extension\n");
	php_info_print_table_start();
	php_info_print_table_row(2, "Version",PHP_UUID_VERSION " (stable)");
	php_info_print_table_row(2, "Released", "2008-04-01");
	php_info_print_table_row(2, "CVS Revision", "$Id$");
	php_info_print_table_row(2, "Authors", "<NAME> '<EMAIL>' (lead)\n");
	php_info_print_table_end();
	/* add your stuff here */

}
/* }}} */


/* {{{ proto string uuid_create([int uuid_type])
  Generate a new UUID */
PHP_FUNCTION(uuid_create)
{

	long uuid_type = UUID_TYPE_DEFAULT;



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

	do {
		uuid_t uuid;
		char uuid_str[37];

		switch(uuid_type) {
		  case UUID_TYPE_DCE_TIME:
			uuid_generate_time(uuid);
			break;
		  case UUID_TYPE_DCE_RANDOM:
{'fraction_non_alphanumeric': 0.137987012987013, 'fraction_numerical': 0.006222943722943723, 'mean_word_length': 2.493698802772527, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '687183', 'n_tokens_mistral': 3847, 'n_tokens_neox': 3780, 'n_words': 756}