Página 1 de 1
Como implementar UUID / GUID em xHarbour
Enviado: 19 Set 2016 13:47
por clodoaldomonteiro
Boa tarde amigos,
Uso o compilador xHarbour versão 1.00 e queria saber se nessa versão temos LIBs para gerar códigos UUID ou GUID?
Desde já agradeço a ajuda.
Como implementar UUID / GUID em xHarbour
Enviado: 20 Set 2016 02:54
por JoséQuintas
Sempre tem chance de repetir.
Uma sugestão está aqui:
Código: Selecionar todos
In the OSF-specified algorithm for generating new (V1) GUIDs, the user's network card MAC address is used as a base for the last group of GUID digits, which means, for example, that a document can be tracked back to the computer that created it. This privacy hole was used when locating the creator of the Melissa virus.[6] Most of the other digits are based on the time while generating the GUID.
The other parts of a V1 GUID make use of the time since the implementation of the Gregorian calendar in 1582. V1 GUIDs, containing a MAC address and time, can be identified by the digit "1" in the first position of the third group of digits, for example {2F1E4FC0-81FD-11DA-9156-00036A0F876A}. Version 1 GUIDs generated between about 1995 and 2010 have Data3 starting with 11D, while more recent ones have 11E.
Version 4 GUIDs simply use a pseudo-random number for filling in all but six of the bits. They have a "4" in the 4-bit version position, and the first two bits of 'data4' are 1 and 0 (so the first hex digit of 'data4' is 8, 9, A, or B), for example {38A52BE4-9352-453E-AF97-5C3B448652F0}. More specifically, the 'data3' bit pattern would be 0001xxxxxxxxxxxx in V1, and 0100xxxxxxxxxxxx in V4. Cryptanalysis of the WinAPI GUID generator shows that, since the sequence of V4 GUIDs is pseudo-random, given full knowledge of the internal state, it is possible to predict previous and subsequent values.[7]
https://en.wikipedia.org/wiki/Globally_ ... identifier
Como implementar UUID / GUID em xHarbour
Enviado: 20 Set 2016 08:45
por clodoaldomonteiro
Vi um exemplo com essa função em C, mas não consegui rodá-la no xharbour:
Código: Selecionar todos
srand (clock());
unsigned char GUID[40] = {0};
int t = 0;
char *szTemp = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
char *szHex = "0123456789ABCDEF-";
int nLen = strlen (szTemp);
for (t=0; t<nLen+1; t++)
{
int r = rand () % 16;
char c = ' ';
switch (szTemp[t])
{
case 'x' : { c = szHex [r]; } break;
case 'y' : { c = szHex [r & 0x03 | 0x08]; } break;
case '-' : { c = '-'; } break;
case '4' : { c = '4'; } break;
}
GUID[t] = ( t < nLen ) ? c : 0x00;
}
printf ("%s\r\n", GUID);
}
Como implementar UUID / GUID em xHarbour
Enviado: 20 Set 2016 09:44
por JoséQuintas
Um chute, faltaria acertar o principal:
- Sortear um número base 16 convertido pra Hex
- Entender o que seria o Y, parece ser faixa específica de número
Código: Selecionar todos
PROCEDURE Main
LOCAL cTemp := "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
LOCAL cHex := "0123456789ABCDEF-"
LOCAL oElement, r
FOR EACH oElement IN cTemp
// r = rand () % 16
DO CASE
CASE oElement == "-"
CASE oElement == "4"
CASE oElement == "x" ; oElement := oElement // int r = rand () % 16; { c = szHex [r]; } // Hex( r )
CASE oElement == "y" ; oElement := oElement // { c = szHex [r & 0x03 | 0x08]; } // Substr( szHex, r ? 0x03 ? 0x08, 1 )
ENDCASE
NEXT
? cTemp
RETURN
Como implementar UUID / GUID em xHarbour
Enviado: 20 Set 2016 10:06
por clodoaldomonteiro
Valeu a Resposta,
Vi essa função em C:
Código: Selecionar todos
#pragma BEGINDUMP
#pragma comment( lib, "shell32.lib" )
#include "hbapi.h"
#include <windows.h>
//------------------------------------------------------------------
// standard 32 byte's M$ guid
// Link: http://forums.fivetechsupport.com/viewtopic.php?f=3&t=28026&p=156570&hilit=guid#p156570
// Link: http://forums.fivetechsupport.com/viewtopic.php?f=3&t=21719&start=30
//------------------------------------------------------------------
HB_FUNC( NEWGUID32 )
{
GUID guid;
char obuff[38];
memset( obuff, 0x0, 38 );
if ( CoCreateGuid(&guid) == NULL )
{
OLECHAR tmpbuff[76];
StringFromGUID2(&guid,tmpbuff,76);
WideCharToMultiByte(CP_OEMCP,0,tmpbuff,-1,obuff,38,NULL,NULL);
}
hb_retclen(obuff,38);
}
#pragma ENDDUMP
Retorna um GUID 32 em UPPERCASE.
Como implementar UUID / GUID em xHarbour
Enviado: 20 Set 2016 10:11
por JoséQuintas
A explicação do y está no texto que eu mesmo postei. rs
so the first hex digit of 'data4' is 8, 9, A, or B),
Os demais, seria o sorteio de um número hexadecimal qualquer
A partir daí, definir seu critério pra evitar duplicação.
Tá explicado porque tem software que não se entende com outro.... rs
Como implementar UUID / GUID em xHarbour
Enviado: 20 Set 2016 10:20
por JoséQuintas
Sugestão:
Talvez pra simplificar e evitar duplicação, aproveitar o serial do HD como parte do número.
Ou, como indicado no texto, o endereço MAC da placa de rede.
Talvez um CNPJ ou CPF, ou CEP, ou telefone... rs
São só alternativas pra criar números únicos que ninguém usou.
Se fosse só Brasil, CNPJ/CPF + um randômico resolveria.
Como implementar UUID / GUID em xHarbour
Enviado: 20 Set 2016 10:29
por JoséQuintas
Uma explicação mais simples disso:
https://msdn.microsoft.com/en-us/librar ... s.85).aspx
É um número de 128 bits, em hexadecimal, formatado como 1 grupo de 8 dígitos, 3 grupos de 4 dígitos, e um grupo de 12 dígitos.
Tanto faz o número, só não pode ter dois componentes com números iguais na mesma máquina.
Como implementar UUID / GUID em xHarbour
Enviado: 20 Set 2016 11:05
por Kapiaba
Bom dia, não entendi muito bem o queres fazer, mas acho que com xHarbour, tens que usar o comando RANDOM() ou RANDOM_UUID(), veja se não é por ai. abs.
Como implementar UUID / GUID em xHarbour
Enviado: 20 Set 2016 11:08
por Kapiaba
por exemplo:
Código: Selecionar todos
static function random_uuid()
return hb_strformat( "%04x%04x-%04x-%04x-%04x-%04x%04x%04x",;
hb_Random( 0, 0xffff ), hb_Random( 0, 0xffff ),;
hb_Random( 0, 0xffff ),;
hb_BitOr( Int( hb_Random( 0, 0x0fff ) ), 0x4000 ),;
hb_BitOr( Int( hb_Random( 0, 0x3fff ) ), 0x8000 ),;
hb_Random( 0, 0xffff ), hb_Random( 0, 0xffff ), hb_Random( 0, 0xffff ) )
Espero que t ajude. Abs
Como implementar UUID / GUID em xHarbour
Enviado: 20 Set 2016 13:36
por clodoaldomonteiro
Muito Obrigado pela resposta de todos, vou testar tudo agora.
Kapiaba, no xHarbour 1.00 tem uma equivalente para a função hb_StrFormat()?
Como implementar UUID / GUID em xHarbour
Enviado: 20 Set 2016 15:03
por Kapiaba
Como implementar UUID / GUID em xHarbour
Enviado: 20 Set 2016 17:06
por clodoaldomonteiro
Kapiaba escreveu:Eu acho que sim. Só não entendo porquê insistes em usar uma versão tão vechia.
Abs.
É que pra mim ficaria difícil converter, pois tenho uns 100 relatorio PDF que uso a NewHPDF.PRG e outras coisa que fui colocando.
Vc se interessaria em converter uma aplicação pra mim, informando seu preço é claro?
Como implementar UUID / GUID em xHarbour
Enviado: 20 Set 2016 17:23
por Kapiaba
Não entendi? Se você compila em xHarbour 1.00, compilará nas novas versões, lógico que dará um "xiste" ou outro, mas nada que você não descubra qual é o comando equivalente ou "modernizado". Agora, se o converter for para FOR WINDOWS, ai, é nóis: Mas, uso FIVEWIN for xHarbour, nada mais. Abs.