[php] gg_http_hash - jak w php ?
: śr kwie 25, 2007 7:22 am
Witam 
Interesuje mnie przerobienie ponizszej funkcji na kod php :>
Jest mi to niezbedne do kilku operacji z protokolem gadu-gadu .
Niestety nie wiem jak to ugryzc ,wiec moglby ktos pomoc ?
Z gory dziekuje
Kod w c (libgadu - common.c) :
int gg_http_hash(const char *format, ...)
{
unsigned int a, c, i, j;
va_list ap;
int b = -1;
va_start(ap, format);
for (j = 0; j < strlen(format); j++) {
char *arg, buf[16];
if (format[j] == 'u') {
snprintf(buf, sizeof(buf), "%d", va_arg(ap, uin_t));
arg = buf;
} else {
if (!(arg = va_arg(ap, char*)))
arg = "";
}
i = 0;
while ((c = (unsigned char) arg[i++]) != 0) {
a = (c ^ b) + (c <<
;
b = (a >> 24) | (a <<
;
}
}
va_end(ap);
return (b < 0 ? -b : b);
}
Kod w delphi (gglite.pas) :
function TGGLite.HTTPHashCode (MultiParam: array of string):integer;
var b,i,j:integer;
var a,c:longword;
begin
result:=-1;
if length(multiparam)=0 then exit;
b:=-1;
for i:=low(multiparam) to high(multiparam) do
begin
for j:=1 to length(multiparam) do
begin
c:=ord(multiparam[j]);
a:=(c xor b) + (c shl
;
b:=(a shr 24) or (a shl
;
end;
end;
if (b < 0) then result:=-b
else result:=b;
end;
Interesuje mnie przerobienie ponizszej funkcji na kod php :>
Jest mi to niezbedne do kilku operacji z protokolem gadu-gadu .
Niestety nie wiem jak to ugryzc ,wiec moglby ktos pomoc ?
Z gory dziekuje
Kod w c (libgadu - common.c) :
int gg_http_hash(const char *format, ...)
{
unsigned int a, c, i, j;
va_list ap;
int b = -1;
va_start(ap, format);
for (j = 0; j < strlen(format); j++) {
char *arg, buf[16];
if (format[j] == 'u') {
snprintf(buf, sizeof(buf), "%d", va_arg(ap, uin_t));
arg = buf;
} else {
if (!(arg = va_arg(ap, char*)))
arg = "";
}
i = 0;
while ((c = (unsigned char) arg[i++]) != 0) {
a = (c ^ b) + (c <<
b = (a >> 24) | (a <<
}
}
va_end(ap);
return (b < 0 ? -b : b);
}
Kod w delphi (gglite.pas) :
function TGGLite.HTTPHashCode (MultiParam: array of string):integer;
var b,i,j:integer;
var a,c:longword;
begin
result:=-1;
if length(multiparam)=0 then exit;
b:=-1;
for i:=low(multiparam) to high(multiparam) do
begin
for j:=1 to length(multiparam) do
begin
c:=ord(multiparam[j]);
a:=(c xor b) + (c shl
b:=(a shr 24) or (a shl
end;
end;
if (b < 0) then result:=-b
else result:=b;
end;