Update of /cvsroot/chix/chix/src/lib In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv31130/src/lib Modified Files: chix.c chix_buddy.h chix_client.c chix_credit.c chix_mesg.c chix_packet.c chix_status.c chix_status.h Log Message: status setting should work properly now Index: chix_credit.c =================================================================== RCS file: /cvsroot/chix/chix/src/lib/chix_credit.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- chix_credit.c 25 Jul 2006 12:07:07 -0000 1.7 +++ chix_credit.c 10 Jul 2007 16:46:25 -0000 1.8 @@ -115,10 +115,14 @@ _chix_credit_free(Chix_Credit *cr) { CHECK_TYPE(cr, CREDIT_TYPE,); - if (cr->provider) free(cr->provider); - if (cr->alloted) free(cr->alloted); - if (cr->used) free(cr->used); - if (cr->left) free(cr->left); + if (cr->provider) + free(cr->provider); + if (cr->alloted) + free(cr->alloted); + if (cr->used) + free(cr->used); + if (cr->left) + free(cr->left); free(cr); } Index: chix_buddy.h =================================================================== RCS file: /cvsroot/chix/chix/src/lib/chix_buddy.h,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- chix_buddy.h 25 Jul 2006 12:07:07 -0000 1.12 +++ chix_buddy.h 10 Jul 2007 16:46:25 -0000 1.13 @@ -41,8 +41,8 @@ union { struct { - int mb : 8; int pc : 8; + int mb : 8; }; int online; }; Index: chix_status.c =================================================================== RCS file: /cvsroot/chix/chix/src/lib/chix_status.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- chix_status.c 25 Jul 2006 12:07:07 -0000 1.6 +++ chix_status.c 10 Jul 2007 16:46:26 -0000 1.7 @@ -57,19 +57,38 @@ *****************************************************************************/ CHIX_INTERN char * -chix_status_away_set(Chix_Status *stat, int away) +chix_status_away_set_extern(Chix_Status *stat, int away) { - if ((away > 5) || (away < 0)) + if ((away > 3) || (away < 0)) return NULL; - if (away == _status_away[0].type) - stat->away = AWAY_AVAILABLE; - else if (away == _status_away[1].type) - stat->away = AWAY_AWAY; - else if (away == _status_away[2].type) - stat->away = AWAY_BUSY; - else if (away == _status_away[3].type) - stat->away = AWAY_OFFLINE; - else return NULL; + stat->away = _status_away[away].type; + return strdup(_status_away[away].string); +} + +CHIX_INTERN char * +chix_status_away_set_intern(Chix_Status *stat, int away) +{ + if ((away > 5) || (away < 0)) + return NULL; + + switch (away) + { + case 0: + stat->away = AWAY_AWAY; + break; + case 2: + stat->away = AWAY_AVAILABLE; + break; + case 4: + stat->away = AWAY_BUSY; + break; + case 5: + stat->away = AWAY_OFFLINE; + break; + default: + /* 1 or 3 */ + break; + } return strdup(_status_away[stat->away].string); } Index: chix_status.h =================================================================== RCS file: /cvsroot/chix/chix/src/lib/chix_status.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- chix_status.h 25 Jul 2006 12:07:07 -0000 1.5 +++ chix_status.h 10 Jul 2007 16:46:26 -0000 1.6 @@ -54,7 +54,8 @@ int mood; }; -CHIX_API char *chix_status_away_set (Chix_Status *stat, int away); +CHIX_API char *chix_status_away_set_intern(Chix_Status *stat, int away); +CHIX_API char *chix_status_away_set_extern(Chix_Status *stat, int away); CHIX_API int chix_status_mood_set (Chix_Status *stat, int mood); CHIX_API int chix_status_away_get (Chix_Status *stat, char *buf, int size); CHIX_API int chix_status_mood_get (Chix_Status *stat, char *buf, int size); Index: chix_client.c =================================================================== RCS file: /cvsroot/chix/chix/src/lib/chix_client.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- chix_client.c 25 Jul 2006 12:07:07 -0000 1.7 +++ chix_client.c 10 Jul 2007 16:46:25 -0000 1.8 @@ -140,14 +140,14 @@ CHECK_TYPE(cl, CLIENT_TYPE, 0); - str = chix_status_away_set(&cl->stat, away); + str = chix_status_away_set_extern(&cl->stat, away); if (!str) return 0; pkt = chix_packet_new(); if (!pkt) return 0; chix_packet_set_hdr(pkt, CODE_STATUS, __seqn(cl)); - chix_packet_set_int(pkt, KEY_CLIENT_STATUS, away); + chix_packet_set_int(pkt, KEY_CLIENT_STATUS, cl->stat.away); chix_packet_set_str(pkt, KEY_STATUS_STRING, str); free(str); Index: chix_mesg.c =================================================================== RCS file: /cvsroot/chix/chix/src/lib/chix_mesg.c,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- chix_mesg.c 25 Jul 2006 12:07:07 -0000 1.13 +++ chix_mesg.c 10 Jul 2007 16:46:26 -0000 1.14 @@ -133,7 +133,13 @@ msg->time = _chix_mesg_time(chix_packet_get_ptr(pkt, KEY_MESG_TIME)); SET_TYPE(msg, MESG_TYPE); - chix_event_set(cl, msg, EVENT_MESG, 0,CHIX_FUNC_FREE(_chix_mesg_free)); + printf("DEBUG: MESSAGE RECIEVED\n"); + printf("Time: %s\n", ctime(&msg->time)); + printf("From: %s\n", msg->buddy->alias); + printf("Mesg: %s\n", msg->mesg); + + + chix_event_set(cl, msg, EVENT_MESG, 0,CHIX_FUNC_FREE(_chix_mesg_free)); return _chix_mesg_ack(cl, pkt); } Index: chix.c =================================================================== RCS file: /cvsroot/chix/chix/src/lib/chix.c,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -r1.23 -r1.24 --- chix.c 26 Jul 2006 12:15:33 -0000 1.23 +++ chix.c 10 Jul 2007 16:46:25 -0000 1.24 @@ -456,15 +456,15 @@ { Chix_Buddy *bud; Chix_Packet *ack; - int num, away; + int num, type; /* This get's called when the buddy changes status. */ num = chix_packet_get_int(pkt, KEY_BUDDY_NUMBER); bud = chix_blist_search_num(cl->blist, num); - away = chix_packet_get_int(pkt, KEY_STATUS_AWAY); + type = chix_packet_get_int(pkt, KEY_STATUS_TYPE); - if (away == VAL_STATUS_MOOD) + if (type == VAL_STATUS_MOOD) { /* The buddy's mood status changed. */ int mood = chix_packet_get_int(pkt, KEY_STATUS_MOODTYPE); @@ -473,7 +473,7 @@ else { /* The buddy's away status changed */ - free(chix_status_away_set(&bud->stat, away)); + free(chix_status_away_set_intern(&bud->stat, type)); } chix_event_set(cl, bud, EVENT_BUDDY_NOTIFY, 0, NULL); Index: chix_packet.c =================================================================== RCS file: /cvsroot/chix/chix/src/lib/chix_packet.c,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- chix_packet.c 25 Jul 2006 12:07:07 -0000 1.16 +++ chix_packet.c 10 Jul 2007 16:46:26 -0000 1.17 @@ -46,31 +46,31 @@ for (pos = 8; str[pos + 2] != 0x03; pos++) { - int key = 0; - int end; - - if (str[pos + 3] == 0x3a) - { - key = __parse(str, pos, 3, 10, &err); - if ((err) || (key > 63) || (key < 0)) return 0; - pkt->keys[pkt->cnt++] = key; - pos += 4; + int key = 0; + int end; - end = __find(str, 0x09, pos); - if (end < 0) return 0; - pkt->data[key] = __substr(str, pos, end - pos); - if (!pkt->data[key]) return 0; - pos = end; - } - else - { - if (!pkt->cnt) return 0; - key = pkt->keys[pkt->cnt - 1]; - end = __find(str, 0x09, pos); - pkt->data[key] = __append(pkt->data[key], str, pos - 1, (end + 1) - pos); - if (!pkt->data[key]) return 0; - pos = end; - } + if (str[pos + 3] == 0x3a) + { + key = __parse(str, pos, 3, 10, &err); + if ((err) || (key > 63) || (key < 0)) return 0; + pkt->keys[pkt->cnt++] = key; + pos += 4; + + end = __find(str, 0x09, pos); + if (end < 0) return 0; + pkt->data[key] = __substr(str, pos, end - pos); + if (!pkt->data[key]) return 0; + pos = end; + } + else + { + if (!pkt->cnt) return 0; + key = pkt->keys[pkt->cnt - 1]; + end = __find(str, 0x09, pos); + pkt->data[key] = __append(pkt->data[key], str, pos - 1, (end + 1) - pos); + if (!pkt->data[key]) return 0; + pos = end; + } } return 1; @@ -86,9 +86,7 @@ len = snprintf(buf, sizeof(buf), "\002%02i:%03i\t", pkt->code, pkt->seqn); for (key = pkt->keys; *key; key++) - len += snprintf(buf + len, sizeof(buf) - len, "%03i:%s\t", - *key, pkt->data[*key]); - + len += snprintf(buf + len, sizeof(buf) - len, "%03i:%s\t", *key, pkt->data[*key]); len += snprintf(buf + len, sizeof(buf) - len, "%02X\003", __checksum(buf, len)); *out_str = strdup(buf); @@ -151,17 +149,17 @@ fprintf(stdout, "\n:: %s ::", str); fprintf(stdout, "\n ============================" - "\n | Code: %02i" - "\n | Sequence: %03i" - "\n ============================\n", - pkt->code, pkt->seqn); + "\n | Code: %02i" + "\n | Sequence: %03i" + "\n ============================\n", + pkt->code, pkt->seqn); for (key = pkt->keys; *key; key++) { - fprintf(stdout, " | Key: %03i\n" - " | Val: %s\n" - " |----------------------------\n", - *key, pkt->data[*key]); + fprintf(stdout, " | Key: %03i\n" + " | Val: %s\n" + " |----------------------------\n", + *key, pkt->data[*key]); } } @@ -192,7 +190,7 @@ return strchr(str + offset, c) - str; } -static inline int +static inline int __parse(const char *str, int offset, int len, int base, int *err) { char *eptr; @@ -201,8 +199,8 @@ if ((eptr - ptr) != len) { - *err = 1; - return 0; + *err = 1; + return 0; } *err = 0; @@ -232,10 +230,10 @@ while ((ptr = strchr(ptr + 1, 0x09))) { - if ((ptr + 4) > (str + len)) - break; - if ((ptr[4] == 0x3a)) - *ptr = ' '; + if ((ptr + 4) > (str + len)) + break; + if ((ptr[4] == 0x3a)) + *ptr = ' '; } } @@ -256,19 +254,19 @@ if ((len < 11) || (str[0] != 0x02) || (str[pos] != 0x09)) { - printf("Packet seems to be smelly.\n"); - printf("%s\n", str); - return 0; + printf("Packet seems to be smelly.\n"); + printf("%s\n", str); + return 0; } if ((__checksum(str, pos + 1) != __parse(str, pos + 1, 2, 16, &err)) || (err)) { - printf("Checksum failed.\n"); - return 0; + printf("Checksum failed.\n"); + return 0; } if ((str[3] != 0x3a) || (str[7] != 0x09)) { - printf("Bad header.\n"); - return 0; + printf("Bad header.\n"); + return 0; } return 1; } |