formatted source code

This commit is contained in:
Felix Wallin 2010-08-16 17:20:12 +08:00 committed by FacialTurd
parent c86c224265
commit 6bd48d059f
6 changed files with 9311 additions and 7659 deletions

10
font.h Executable file → Normal file

File diff suppressed because one or more lines are too long

1178
http.c Executable file → Normal file

File diff suppressed because it is too large Load Diff

67
md5.c Executable file → Normal file
View File

@ -33,34 +33,37 @@ void md5_update(struct md5_context *ctx, unsigned char const *buf, unsigned len)
// update bit count // update bit count
t = ctx->bits[0]; t = ctx->bits[0];
if((ctx->bits[0] = (t + ((unsigned)len << 3)) & 0xffffffff) < t) if((ctx->bits[0] = (t + ((unsigned)len << 3)) & 0xffffffff) < t)
ctx->bits[1]++; // carry ctx->bits[1]++; // carry
ctx->bits[1] += len >> 29; ctx->bits[1] += len >> 29;
t = (t >> 3) & 0x3f; t = (t >> 3) & 0x3f;
// use leading data to top up the buffer // use leading data to top up the buffer
if(t) { if(t)
unsigned char *p = ctx->in + t; {
unsigned char *p = ctx->in + t;
t = 64-t; t = 64-t;
if (len < t) { if (len < t)
memcpy(p, buf, len); {
return; memcpy(p, buf, len);
} return;
memcpy(p, buf, t); }
md5_transform(ctx->buf, ctx->in); memcpy(p, buf, t);
buf += t; md5_transform(ctx->buf, ctx->in);
len -= t; buf += t;
len -= t;
} }
// following 64-byte chunks // following 64-byte chunks
while(len >= 64) { while(len >= 64)
memcpy(ctx->in, buf, 64); {
md5_transform(ctx->buf, ctx->in); memcpy(ctx->in, buf, 64);
buf += 64; md5_transform(ctx->buf, ctx->in);
len -= 64; buf += 64;
len -= 64;
} }
// save rest of bytes for later // save rest of bytes for later
@ -84,14 +87,17 @@ void md5_final(unsigned char digest[16], struct md5_context *ctx)
count = 64 - 1 - count; count = 64 - 1 - count;
// Pad out to 56 mod 64 // Pad out to 56 mod 64
if(count < 8) { if(count < 8)
// we need to finish a whole block before padding {
memset(p, 0, count); // we need to finish a whole block before padding
md5_transform(ctx->buf, ctx->in); memset(p, 0, count);
memset(ctx->in, 0, 56); md5_transform(ctx->buf, ctx->in);
} else { memset(ctx->in, 0, 56);
// just pad to 56 bytes }
memset(p, 0, count-8); else
{
// just pad to 56 bytes
memset(p, 0, count-8);
} }
// append length & final transform // append length & final transform
@ -121,7 +127,7 @@ void md5_transform(unsigned buf[4], const unsigned char inraw[64])
int i; int i;
for (i = 0; i < 16; ++i) for (i = 0; i < 16; ++i)
in[i] = getu32 (inraw + 4 * i); in[i] = getu32 (inraw + 4 * i);
a = buf[0]; a = buf[0];
b = buf[1]; b = buf[1];
@ -210,15 +216,16 @@ void md5_ascii(char *result, unsigned char const *buf, unsigned len)
int i; int i;
if(len==0) if(len==0)
len = strlen((char *)buf); len = strlen((char *)buf);
md5_init(&md5); md5_init(&md5);
md5_update(&md5, buf, len); md5_update(&md5, buf, len);
md5_final(hash, &md5); md5_final(hash, &md5);
for(i=0;i<16;i++) { for(i=0; i<16; i++)
result[i*2] = hex[(hash[i]>>4)&0xF]; {
result[i*2+1] = hex[hash[i]&0x0F]; result[i*2] = hex[(hash[i]>>4)&0xF];
result[i*2+1] = hex[hash[i]&0x0F];
} }
result[32] = 0; result[32] = 0;
} }

9
md5.h Executable file → Normal file
View File

@ -1,10 +1,11 @@
#ifndef MD5_H #ifndef MD5_H
#define MD5_H #define MD5_H
struct md5_context { struct md5_context
unsigned buf[4]; {
unsigned bits[2]; unsigned buf[4];
unsigned char in[64]; unsigned bits[2];
unsigned char in[64];
}; };
void md5_init(struct md5_context *context); void md5_init(struct md5_context *context);

15589
powder.c Executable file → Normal file

File diff suppressed because it is too large Load Diff

117
update.c Executable file → Normal file
View File

@ -43,34 +43,39 @@ static char *exe_name(void)
{ {
#if defined WIN32 #if defined WIN32
char *name= (char *)malloc(64), max=64, res; char *name= (char *)malloc(64), max=64, res;
while((res = (char)GetModuleFileName(NULL, name, max)) >= max) { while((res = (char)GetModuleFileName(NULL, name, max)) >= max)
{
#elif defined MACOSX #elif defined MACOSX
char *fn=malloc(64),*name=malloc(PATH_MAX), max=64, res; char *fn=malloc(64),*name=malloc(PATH_MAX), max=64, res;
if(_NSGetExecutablePath(fn, &max) != 0) { if(_NSGetExecutablePath(fn, &max) != 0)
fn = realloc(fn, max); {
_NSGetExecutablePath(fn, &max); fn = realloc(fn, max);
_NSGetExecutablePath(fn, &max);
} }
if(realpath(fn, name) == NULL) { if(realpath(fn, name) == NULL)
free(fn); {
free(name); free(fn);
return NULL; free(name);
return NULL;
} }
res = 1; res = 1;
#else #else
char fn[64], *name=malloc(64), max=64, res; char fn[64], *name=malloc(64), max=64, res;
sprintf(fn, "/proc/self/exe"); sprintf(fn, "/proc/self/exe");
memset(name, 0, max); memset(name, 0, max);
while((res = readlink(fn, name, max)) >= max-1) { while((res = readlink(fn, name, max)) >= max-1)
{
#endif #endif
#ifndef MACOSX #ifndef MACOSX
max *= 2; max *= 2;
name = realloc(name, max); name = realloc(name, max);
memset(name, 0, max); memset(name, 0, max);
} }
#endif #endif
if(res <= 0) { if(res <= 0)
free(name); {
return NULL; free(name);
return NULL;
} }
return name; return name;
} }
@ -85,34 +90,36 @@ int update_start(char *data, int len)
int res = 1; int res = 1;
if(!self) if(!self)
return 1; return 1;
#ifdef WIN32 #ifdef WIN32
temp = malloc(strlen(self)+12); temp = malloc(strlen(self)+12);
strcpy(temp, self); strcpy(temp, self);
p = temp + strlen(temp) - 4; p = temp + strlen(temp) - 4;
if(_stricmp(p, ".exe")) if(_stricmp(p, ".exe"))
p += 4; p += 4;
strcpy(p, "_update.exe"); strcpy(p, "_update.exe");
if(!MoveFile(self, temp)) if(!MoveFile(self, temp))
goto fail; goto fail;
f = fopen(self, "wb"); f = fopen(self, "wb");
if(!f) if(!f)
goto fail; goto fail;
if(fwrite(data, 1, len, f) != len) { if(fwrite(data, 1, len, f) != len)
fclose(f); {
DeleteFile(self); fclose(f);
goto fail; DeleteFile(self);
goto fail;
} }
fclose(f); fclose(f);
if((int)ShellExecute(NULL, "open", self, NULL, NULL, SW_SHOWNORMAL) <= 32) { if((int)ShellExecute(NULL, "open", self, NULL, NULL, SW_SHOWNORMAL) <= 32)
DeleteFile(self); {
goto fail; DeleteFile(self);
goto fail;
} }
return 0; return 0;
#else #else
temp = malloc(strlen(self)+8); temp = malloc(strlen(self)+8);
@ -121,22 +128,25 @@ int update_start(char *data, int len)
f = fopen(temp, "w"); f = fopen(temp, "w");
if(!f) if(!f)
goto fail; goto fail;
if(fwrite(data, 1, len, f) != len) { if(fwrite(data, 1, len, f) != len)
fclose(f); {
unlink(temp); fclose(f);
goto fail; unlink(temp);
goto fail;
} }
fclose(f); fclose(f);
if(chmod(temp, 0755)) { if(chmod(temp, 0755))
unlink(temp); {
goto fail; unlink(temp);
goto fail;
} }
if(rename(temp, self)) { if(rename(temp, self))
unlink(temp); {
goto fail; unlink(temp);
goto fail;
} }
execl(self, "powder-update", NULL); execl(self, "powder-update", NULL);
@ -158,22 +168,25 @@ int update_finish(void)
strcpy(temp, self); strcpy(temp, self);
p = temp + strlen(temp) - 4; p = temp + strlen(temp) - 4;
if(_stricmp(p, ".exe")) if(_stricmp(p, ".exe"))
p += 4; p += 4;
strcpy(p, "_update.exe"); strcpy(p, "_update.exe");
while(!DeleteFile(temp)) { while(!DeleteFile(temp))
err = GetLastError(); {
if(err == ERROR_FILE_NOT_FOUND) { err = GetLastError();
// just as well, then if(err == ERROR_FILE_NOT_FOUND)
free(temp); {
return 0; // just as well, then
} free(temp);
Sleep(500); return 0;
timeout--; }
if(timeout <= 0) { Sleep(500);
free(temp); timeout--;
return 1; if(timeout <= 0)
} {
free(temp);
return 1;
}
} }
free(temp); free(temp);
#endif #endif