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

9
md5.h Executable file → Normal file
View File

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