Permalink
Browse files

cleanup kodu.

  • Loading branch information...
darkjames
darkjames committed Oct 21, 2008
1 parent f0e868e commit 26ca475f761c8ed75dcd7d628a8dde1482df6d0b
Showing with 43 additions and 92 deletions.
  1. +3 −3 auth.c
  2. +4 −60 dynstuff.c
  3. +1 −2 dynstuff.h
  4. +15 −11 protocol.c
  5. +20 −16 usg.c
6 auth.c
@@ -29,7 +29,7 @@

#include "usg.h"

unsigned int gg_login_hash(const char *pass, unsigned int seed)
static unsigned int gg_login_hash(const char *pass, unsigned int seed)
{
const unsigned char *password = (const unsigned char *) pass;

@@ -55,7 +55,7 @@ unsigned int gg_login_hash(const char *pass, unsigned int seed)
return y;
}

void gg_login_hash_sha1(const char *pass, unsigned int seed, unsigned char *result)
static void gg_login_hash_sha1(const char *pass, unsigned int seed, unsigned char *result)
{
SHA_CTX ctx;

@@ -66,7 +66,7 @@ void gg_login_hash_sha1(const char *pass, unsigned int seed, unsigned char *resu
SHA1_Final(result, &ctx);
}

const char *get_password(int uin) {
static const char *get_password(int uin) {
FILE *f;
struct passwd *p;

@@ -27,79 +27,23 @@
#include "dynstuff.h"
#include "xmalloc.h"

/*
* list_add_sorted()
*
* dodaje do listy dany element. przy okazji mo¿e te¿ skopiowaæ zawarto¶æ.
* je¶li poda siê jako ostatni parametr funkcjê porównuj±c± zawarto¶æ
* elementów, mo¿e posortowaæ od razu.
*
* - list - wska¼nik do listy,
* - data - wska¼nik do elementu,
* - alloc_size - rozmiar elementu, je¶li chcemy go skopiowaæ.
*
* zwraca wska¼nik zaalokowanego elementu lub NULL w przpadku b³êdu.
*/
void *list_add_sorted(struct list **list, void *data, int alloc_size, int (*comparision)(void *, void *))
{
struct list *new, *tmp;
void *list_add(struct list **list, void *data) {
list_t new;

if (!list) {
errno = EFAULT;
return NULL;
}

new = xmalloc(sizeof(struct list));
new->next = *list;
*list = new;

new->data = data;
new->next = NULL;

if (alloc_size) {
new->data = xmalloc(alloc_size);
memcpy(new->data, data, alloc_size);
}

if (!(tmp = *list)) {
*list = new;
} else {
if (!comparision) {
while (tmp->next)
tmp = tmp->next;
tmp->next = new;
} else {
struct list *prev = NULL;

while (comparision(new->data, tmp->data) > 0) {
prev = tmp;
tmp = tmp->next;
if (!tmp)
break;
}

if (!prev) {
tmp = *list;
*list = new;
new->next = tmp;
} else {
prev->next = new;
new->next = tmp;
}
}
}

return new->data;
}

/*
* list_add()
*
* wrapper do list_add_sorted(), który zachowuje poprzedni± sk³adniê.
*/
void *list_add(struct list **list, void *data, int alloc_size)
{
return list_add_sorted(list, data, alloc_size, NULL);
}

/*
* list_remove()
*
@@ -28,8 +28,7 @@ struct list {
};

typedef struct list * list_t;
void *list_add(struct list **list, void *data, int alloc_size);
void *list_add_sorted(struct list **list, void *data, int alloc_size, int (*comparision)(void *, void *));
void *list_add(struct list **list, void *data);
int list_remove(struct list **list, void *data, int free_data);
int list_count(struct list *list);
int list_destroy(struct list *list, int free_data);
@@ -34,9 +34,9 @@
#include "auth.h"
#include "msgqueue.h"

static char motd_text[] = "Witaj na wolnym serwerze gg! (usg 0.2)";
static char motd_text[] = "Witaj na wolnym serwerze gg! (usg 0.2)";

client_t *get_client(client_t *c, int uin) {
static client_t *get_client(client_t *c, int uin) {
client_t *f;

if (uin == c->uin)
@@ -448,11 +448,13 @@ static int gg_notify_handler(client_t *c, void *data, uint32_t len) {
printf("received notify list from %d\n", c->uin);

for (i = 0; i < len / sizeof(*n); i++) {
friend_t f;
friend_t *f;

f.uin = n[i].uin;
f.flags = n[i].dunno1;
list_add(&c->friends, &f, sizeof(f));
f = xmalloc(sizeof(friend_t));

f->uin = n[i].uin;
f->flags = n[i].dunno1;
list_add(&c->friends, f);
}
return 0;
}
@@ -477,7 +479,7 @@ static int gg_list_empty_handler(client_t *c, void *data, uint32_t len) {

static int gg_notify_add_handler(client_t *c, void *data, uint32_t len) {
struct gg_add_remove *ar = (struct gg_add_remove *) data;
friend_t f;
friend_t *f;

if (len < sizeof(struct gg_add_remove))
return -1;
@@ -498,11 +500,13 @@ static int gg_notify_add_handler(client_t *c, void *data, uint32_t len) {
* libgadu nie umie wysylac, potestowac z oryginalnym serwerem
*/

f.uin = ar->uin;
f.flags = ar->dunno1;
f = xmalloc(sizeof(friend_t));

f->uin = ar->uin;
f->flags = ar->dunno1;

list_add(&c->friends, &f, sizeof(f));
c->notify_reply(c, f.uin);
list_add(&c->friends, f);
c->notify_reply(c, f->uin);

return 0;
}
36 usg.c
@@ -139,7 +139,7 @@ void changed_status(client_t *c)
/* obs³uguje przychodz±ce po³±cznia */
static int handle_connection(client_t *c)
{
client_t n;
client_t *n;
struct sockaddr_in sin;
int fd, sin_len = sizeof(sin), nb = 1;
struct gg_welcome w;
@@ -155,19 +155,21 @@ static int handle_connection(client_t *c)
return 0;
}

memset(&n, 0, sizeof(n));
n.fd = fd;
n.state = STATE_LOGIN;
n.timeout = time(NULL) + TIMEOUT_CONNECT;
n = xmalloc(sizeof(client_t));

n.seed = w.key = random();
n.ibuf = string_init(NULL);
n.obuf = string_init(NULL);
memset(n, 0, sizeof(client_t));

write_full_packet(&n, GG_WELCOME, &w, sizeof(w));
n->fd = fd;
n->state = STATE_LOGIN;
n->timeout = time(NULL) + TIMEOUT_CONNECT;

list_add(&clients, &n, sizeof(n));
n->seed = w.key = random();
n->ibuf = string_init(NULL);
n->obuf = string_init(NULL);

write_full_packet(n, GG_WELCOME, &w, sizeof(w));

list_add(&clients, n);
return 0;
}

@@ -267,7 +269,7 @@ int main(int argc, char **argv)
{
struct sockaddr_in sin;
int sock, opt = 1;
client_t cl;
client_t *cl;

srand(time(NULL));

@@ -295,11 +297,13 @@ int main(int argc, char **argv)
return 1;
}

memset(&cl, 0, sizeof(cl));
cl.fd = sock;
cl.state = STATE_LISTENING;
cl.timeout = -1;
list_add(&clients, &cl, sizeof(cl));
cl = malloc(sizeof(client_t));
memset(cl, 0, sizeof(client_t));

cl->fd = sock;
cl->state = STATE_LISTENING;
cl->timeout = -1;
list_add(&clients, cl);

while (1) {
int nfds = 0, i, ret;

0 comments on commit 26ca475

Please sign in to comment.