|
From: xevuz <xe...@us...> - 2007-07-15 10:03:52
|
Update of /cvsroot/chix/chix/src/lib In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv26848/src/lib Modified Files: chix.c chix_client.c chix_status.c chix_status.h Log Message: fix status once and for all. (i hope) Index: chix_status.c =================================================================== RCS file: /cvsroot/chix/chix/src/lib/chix_status.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- chix_status.c 12 Jul 2007 13:54:29 -0000 1.8 +++ chix_status.c 15 Jul 2007 10:03:47 -0000 1.9 @@ -57,29 +57,29 @@ * Chix Status Internal Routines * *****************************************************************************/ -CHIX_INTERN char * +CHIX_INTERN int chix_status_away_set_extern(Chix_Status *stat, int away) { if ((away > 3) || (away < 0)) - return NULL; - stat->away = _status_away[away].type; - return strdup(_status_away[away].string); + return -1; + stat->away = away; + return _status_away[away].type; } -CHIX_INTERN char * +CHIX_INTERN void chix_status_away_set_intern(Chix_Status *stat, int away) { if ((away > 5) || (away < 0)) - return NULL; + return; switch (away) { - case 0: - stat->away = AWAY_AWAY; - break; case 2: stat->away = AWAY_AVAILABLE; break; + case 0: + stat->away = AWAY_AWAY; + break; case 4: stat->away = AWAY_BUSY; break; @@ -87,10 +87,9 @@ stat->away = AWAY_OFFLINE; break; default: - /* 1 or 3 */ + stat->away = AWAY_UNKNOWN; break; } - return strdup(_status_away[stat->away].string); } CHIX_INTERN int @@ -105,6 +104,7 @@ chix_status_away_get(Chix_Status *stat, char *buf, int size) { if ((!buf) || (size < 15)) return stat->away; + printf("%i\n", stat->away); snprintf(buf, size, "%s", _status_away[stat->away].string); return stat->away; } Index: chix_status.h =================================================================== RCS file: /cvsroot/chix/chix/src/lib/chix_status.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- chix_status.h 10 Jul 2007 16:46:26 -0000 1.6 +++ chix_status.h 15 Jul 2007 10:03:47 -0000 1.7 @@ -54,10 +54,10 @@ int mood; }; -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); +CHIX_API void chix_status_away_set_intern(Chix_Status *stat, int away); +CHIX_API int 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); #endif Index: chix_client.c =================================================================== RCS file: /cvsroot/chix/chix/src/lib/chix_client.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- chix_client.c 10 Jul 2007 16:46:25 -0000 1.8 +++ chix_client.c 15 Jul 2007 10:03:47 -0000 1.9 @@ -136,20 +136,20 @@ chix_client_away_set(Chix_Client *cl, Chix_Away_Type away) { Chix_Packet *pkt; - char *str; + char buf[16]; + int type; CHECK_TYPE(cl, CLIENT_TYPE, 0); - str = chix_status_away_set_extern(&cl->stat, away); - if (!str) return 0; + type = chix_status_away_set_extern(&cl->stat, away); + chix_status_away_get(&cl->stat, buf, sizeof(buf)); 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, cl->stat.away); - chix_packet_set_str(pkt, KEY_STATUS_STRING, str); - free(str); + chix_packet_set_int(pkt, KEY_CLIENT_STATUS, type); + chix_packet_set_str(pkt, KEY_STATUS_STRING, buf); return chix_flush(cl, pkt); } Index: chix.c =================================================================== RCS file: /cvsroot/chix/chix/src/lib/chix.c,v retrieving revision 1.26 retrieving revision 1.27 diff -u -d -r1.26 -r1.27 --- chix.c 14 Jul 2007 02:46:40 -0000 1.26 +++ chix.c 15 Jul 2007 10:03:47 -0000 1.27 @@ -253,7 +253,7 @@ if (!chix_packet_read(pkt, buf->str.ptr, buf->str.len)) return 0; if (!__call(pkt->code, cl, pkt)) - return 0; + return 0; chix_packet_free(pkt); } while (__chix_buffer_string(buf)); @@ -408,7 +408,7 @@ Chix_Buddy *bud; Chix_Packet *ack; int num; - + num = chix_packet_get_int(pkt, KEY_BUDDY_NUMBER); bud = chix_blist_search_num(cl->blist, num); if (!bud) return 0; @@ -440,7 +440,7 @@ */ if (!bud->online) chix_status_away_set_extern(&bud->stat, AWAY_OFFLINE); - else + else if ((!bud->pc) && (bud->mb)) chix_status_away_set_extern(&bud->stat, AWAY_AVAILABLE); chix_event_set(cl, bud, EVENT_BUDDY_NOTIFY, pkt->seqn, NULL); @@ -472,8 +472,9 @@ } else { - /* The buddy's away status changed */ - free(chix_status_away_set_intern(&bud->stat, type)); + /* The buddy's away status changed */ + chix_status_away_set_intern(&bud->stat, type); + if (type == 4) bud->pc = 0; } chix_event_set(cl, bud, EVENT_BUDDY_NOTIFY, 0, NULL); |