Mercurial > pidgin
view src/protocols/oscar/util.c @ 8341:fec4c1fb2ac8
[gaim-migrate @ 9065]
Alright, I had to lay down a little bit of smack. Here goes:
-Work around the rate-limit problem caused by Gaim auto-requesting
away messages too quickly. Basically there is now a 1.2sec gap
between each request. The downside is that it takes a bit longer
for Gaim to get everyone's away message initially. Adium shouldn't
need to do anything to take advantage of this. Fire (they use
libfaim, right?) will need to add a callback for
AIM_CB_LOC_REQUESTINFOTIMEOUT. Just search oscar.c for
gaim_reqinfo_timeout() and copy what that thing does.
-Attempt to do a better job showing away messages in tooltips.
Hopefully & and greater than and less than will show up correctly
now. I don't think there should be any side effects, but if you
mouse over someone and it crashes or you get a pango error let me know.
-Remove/combine some silly functions in util.c that few things use.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Thu, 26 Feb 2004 08:29:32 +0000 |
parents | 697221d5d0ff |
children | 990314a962fb |
line wrap: on
line source
/* * A little bit of this * A little bit of that * It started with a kiss * Now we're up to bat */ #define FAIM_INTERNAL #include <aim.h> #include <ctype.h> #ifdef _WIN32 #include "win32dep.h" #endif faim_internal void faimdprintf(aim_session_t *sess, int dlevel, const char *format, ...) { if (!sess) { fprintf(stderr, "faimdprintf: no session! boo! (%d, %s)\n", dlevel, format); return; } if ((dlevel <= sess->debug) && sess->debugcb) { va_list ap; va_start(ap, format); sess->debugcb(sess, dlevel, format, ap); va_end(ap); } return; } faim_export int aimutil_putstr(char *dest, const char *src, int len) { memcpy(dest, src, len); return len; } /* * Tokenizing functions. Used to portably replace strtok/sep. * -- DMP. * */ faim_export int aimutil_tokslen(char *toSearch, int theindex, char dl) { int curCount = 1; char *next; char *last; int toReturn; last = toSearch; next = strchr(toSearch, dl); while(curCount < theindex && next != NULL) { curCount++; last = next + 1; next = strchr(last, dl); } if ((curCount < theindex) || (next == NULL)) toReturn = strlen(toSearch) - (curCount - 1); else toReturn = next - toSearch - (curCount - 1); return toReturn; } faim_export int aimutil_itemcnt(char *toSearch, char dl) { int curCount; char *next; curCount = 1; next = strchr(toSearch, dl); while(next != NULL) { curCount++; next = strchr(next + 1, dl); } return curCount; } faim_export char *aimutil_itemindex(char *toSearch, int theindex, char dl) { int curCount; char *next; char *last; char *toReturn; curCount = 0; last = toSearch; next = strchr(toSearch, dl); while (curCount < theindex && next != NULL) { curCount++; last = next + 1; next = strchr(last, dl); } if (curCount < theindex) { toReturn = malloc(sizeof(char)); *toReturn = '\0'; } next = strchr(last, dl); if (curCount < theindex) { toReturn = malloc(sizeof(char)); *toReturn = '\0'; } else { if (next == NULL) { toReturn = malloc((strlen(last) + 1) * sizeof(char)); strcpy(toReturn, last); } else { toReturn = malloc((next - last + 1) * sizeof(char)); memcpy(toReturn, last, (next - last)); toReturn[next - last] = '\0'; } } return toReturn; } /** * Calculate the checksum of a given icon. * */ faim_export fu16_t aimutil_iconsum(const fu8_t *buf, int buflen) { fu32_t sum; int i; for (i=0, sum=0; i+1<buflen; i+=2) sum += (buf[i+1] << 8) + buf[i]; if (i < buflen) sum += buf[i]; sum = ((sum & 0xffff0000) >> 16) + (sum & 0x0000ffff); return sum; } faim_export int aim_util_getlocalip(fu8_t *ip) { struct hostent *hptr; char localhost[129]; /* XXX if available, use getaddrinfo() */ /* XXX allow client to specify which IP to use for multihomed boxes */ if (gethostname(localhost, 128) < 0) return -1; if (!(hptr = gethostbyname(localhost))) return -1; memcpy(ip, hptr->h_addr_list[0], 4); return 0; } /** * Check if the given screen name is a valid AIM or ICQ screen name. * * @return 1 if the screen name is valid, 0 if not. */ faim_export int aim_snvalid(const char *sn) { int isICQ = 0; int i = 0; if (!sn) return 0; if (isdigit(sn[0])) isICQ = 1; while (sn[i] != '\0') { /* If it started with a digit then it betta be all digits, ho */ if (isICQ) { if (!isdigit(sn[i])) return 0; } else { if (!isalnum(sn[i]) && (sn[i] != ' ')) return 0; } i++; } return 1; } /* * int snlen(const char *) * * This takes a screen name and returns its length without * spaces. If there are no spaces in the SN, then the * return is equal to that of strlen(). * */ faim_export int aim_snlen(const char *sn) { int i = 0; if (!sn) return 0; while (*sn != '\0') { if (*sn != ' ') i++; sn++; } return i; } /* * int sncmp(const char *, const char *) * * This takes two screen names and compares them using the rules * on screen names for AIM/AOL. Mainly, this means case and space * insensitivity (all case differences and spacing differences are * ignored, with the exception that screen names can not start with * a space). * * Return: 0 if equal * non-0 if different * */ faim_export int aim_sncmp(const char *sn1, const char *sn2) { do { while (*sn2 == ' ') sn2++; while (*sn1 == ' ') sn1++; if (toupper(*sn1) != toupper(*sn2)) return 1; } while ((*sn1 != '\0') && sn1++ && sn2++); return 0; }