<?xml version="1.0"?>
<extension name="uuid" version="0.0.4">
 <summary>uuid extension</summary>
 <description>libuuid binding</description>
 <deps language="c">
  <with name="libuuid" defaults="/lib:/usr:/usr/local" testfile="include/uuid/uuid.h">
   <header name="uuid/uuid.h" />
   <lib name="uuid" />
  </with>
 </deps>
 <license>PHP</license>
 <maintainer>
  <user>shimooka</user>
  <name>SHIMOOKA Hideyuki</name>
  <email>shimooka@doyouphp.jp</email>
  <role>developer</role>
 </maintainer>
 <release>
  <version>0.0.4</version>
  <date>2007-03-23</date>
  <state>alpha</state>
  <notes>First alpha version</notes>
 </release>

 <code position="top">
  <![CDATA[
#define UUID_METHOD_DEFAULT 0
#define UUID_METHOD_RANDOM 1
#define UUID_METHOD_TIME 2
  ]]>
 </code>

 <constant name="UUID_METHOD_DEFAULT" type="int" value="UUID_METHOD_DEFAULT"/>
 <constant name="UUID_METHOD_RANDOM" type="int" value="UUID_METHOD_RANDOM"/>
 <constant name="UUID_METHOD_TIME" type="int" value="UUID_METHOD_TIME"/>

 <function name="uuid_generate">
  <proto>string uuid_generate([int method])</proto>
  <code>
   <![CDATA[
/**
 * @see http://e2fsprogs.sourceforge.net/
 * @see uuidgen.c
 * @see uuid_generate(3)
 * @see uuid_unparse(3)
 */
uuid_t uu;
char str[37];
switch (method) {
case UUID_METHOD_RANDOM:
    uuid_generate_random(uu);
    break;
case UUID_METHOD_TIME:
    uuid_generate_time(uu);
    break;
default:
    uuid_generate(uu);
}
uuid_unparse(uu, str);
RETURN_STRING(str, 1);
]]>
  </code>
  <test>
   <code>
    <![CDATA[
echo strlen(uuid_generate());
echo strlen(uuid_generate(UUID_METHOD_DEFAULT));
echo strlen(uuid_generate(UUID_METHOD_RANDOM));
echo strlen(uuid_generate(UUID_METHOD_TIME));
]]>
   </code>
   <result>36363636</result>
  </test>
 </function>

 <function name="uuid_time">
  <proto>int uuid_time(string uuid)</proto>
  <code>
   <![CDATA[
/**
 * @see uuid_time(3)
 */
uuid_t uu;
if (uuid_parse(uuid, uu)) {
    RETURN_FALSE;
}
if (uuid_is_null(uu) == 1) {
    RETURN_FALSE;
}
if (uuid_type(uu) != 1) {
    RETURN_FALSE;
}
RETURN_LONG(uuid_time(uu, NULL));
]]>
  </code>
  <test>
   <code>
    <![CDATA[
$uuid = uuid_generate();
echo (uuid_time($uuid)  ? 'OK' : 'NG');
$uuid = uuid_generate(UUID_METHOD_DEFAULT);
echo (uuid_time($uuid)  ? 'OK' : 'NG');
$uuid = uuid_generate(UUID_METHOD_RANDOM);
echo (uuid_time($uuid)  ? 'OK' : 'NG');
$uuid = uuid_generate(UUID_METHOD_TIME);
echo (uuid_time($uuid)  ? 'OK' : 'NG');
]]>
   </code>
   <result>NGNGNGOK</result>
  </test>
 </function>

 <function name="uuid_clear">
  <proto>string uuid_clear(string uuid)</proto>
  <code>
   <![CDATA[
/**
 * @see uuid_clear(3)
 */
uuid_t uu;
char str[37];
if (uuid_parse(uuid, uu)) {
    RETURN_FALSE;
}
uuid_clear(uu);
uuid_unparse(uu, str);
RETURN_STRING(str, 1);
]]>
  </code>
  <test>
   <code>
    <![CDATA[
$uuid = uuid_generate();
echo ((uuid_clear($uuid) === '00000000-0000-0000-0000-000000000000') ? 'OK' : 'NG');
$uuid = uuid_generate(UUID_METHOD_RANDOM);
echo ((uuid_clear($uuid) === '00000000-0000-0000-0000-000000000000') ? 'OK' : 'NG');
$uuid = uuid_generate(UUID_METHOD_TIME);
echo ((uuid_clear($uuid) === '00000000-0000-0000-0000-000000000000') ? 'OK' : 'NG');
]]>
   </code>
   <result>OKOKOK</result>
  </test>
 </function>

 <function name="uuid_compare">
  <proto>boolean uuid_compare(string uuid1, string uuid2)</proto>
  <code>
   <![CDATA[
/**
 * @see uuid_compare(3)
 */
uuid_t uu1, uu2;
if (uuid_parse(uuid1, uu1) || uuid_parse(uuid2, uu2)) {
    RETURN_FALSE;
}
RETURN_LONG(uuid_compare(uu1, uu2));
]]>
  </code>
  <test>
   <code>
    <![CDATA[
$uuid1 = uuid_generate();
$uuid2 = $uuid1;
$uuid3 = uuid_generate();
echo ((uuid_compare($uuid1, $uuid2) === 0)  ? 'OK' : 'NG');
echo ((uuid_compare($uuid1, $uuid3) !== 0)  ? 'OK' : 'NG');
]]>
   </code>
   <result>OKOK</result>
  </test>
 </function>

 <function name="uuid_type">
  <proto>boolean uuid_type(string uuid)</proto>
  <code>
   <![CDATA[
uuid_t uu;
if (uuid_parse(uuid, uu)) {
    RETURN_FALSE;
}
RETURN_LONG(uuid_type(uu));
]]>
  </code>
  <test>
   <code>
    <![CDATA[
$uuid = uuid_generate();
echo ((uuid_type($uuid) === 4) ? 'OK' : 'NG');
$uuid = uuid_generate(UUID_METHOD_DEFAULT);
echo ((uuid_type($uuid) === 4) ? 'OK' : 'NG');
$uuid = uuid_generate(UUID_METHOD_RANDOM);
echo ((uuid_type($uuid) === 4) ? 'OK' : 'NG');
$uuid = uuid_generate(UUID_METHOD_TIME);
echo ((uuid_type($uuid) === 1) ? 'OK' : 'NG');
]]>
   </code>
   <result>OKOKOKOK</result>
  </test>
 </function>

</extension>

