blob: 7b67df8b54438662c42aa7813830217b648e4849 [file] [log] [blame]
Benny Prijono4766ffe2005-11-01 17:56:59 +00001/* $Id$
2 *
Benny Prijonodd859a62005-11-01 16:42:51 +00003 */
4#include <pj/guid.h>
5#include <pj/string.h>
6#include <pj/sock.h>
7#include <windows.h>
8#include <objbase.h>
9#include <pj/os.h>
10
11
12const unsigned PJ_GUID_STRING_LENGTH=32;
13
14PJ_INLINE(void) hex2digit(unsigned value, char *p)
15{
16 static char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7',
17 '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
18 *p++ = hex[ (value & 0xF0) >> 4 ];
19 *p++ = hex[ (value & 0x0F) ];
20}
21
22static void guid_to_str( const GUID *guid, pj_str_t *str )
23{
24 unsigned i;
25 GUID guid_copy;
26 const unsigned char *src = (const unsigned char*)&guid_copy;
27 char *dst = str->ptr;
28
29 pj_memcpy(&guid_copy, guid, sizeof(*guid));
30 guid_copy.Data1 = pj_ntohl(guid_copy.Data1);
31 guid_copy.Data2 = pj_ntohs(guid_copy.Data2);
32 guid_copy.Data3 = pj_ntohs(guid_copy.Data3);
33
34 for (i=0; i<16; ++i) {
35 hex2digit( *src, dst );
36 dst += 2;
37 ++src;
38 }
39 str->slen = 32;
40}
41
42
43PJ_DEF(pj_str_t*) pj_generate_unique_string(pj_str_t *str)
44{
45 GUID guid;
46
47 PJ_CHECK_STACK();
48
49 CoCreateGuid(&guid);
50 guid_to_str( &guid, str );
51 return str;
52}
53