10 #define AIMUTIL_USEMACROS
12 #ifdef AIMUTIL_USEMACROS
13 /* macros in faim/aim.h */
15 inline int aimutil_put8(u_char *buf, u_char data)
17 buf[0] = (u_char)data&0xff;
21 inline u_char aimutil_get8(u_char *buf)
27 * Endian-ness issues here?
29 inline int aimutil_put16(u_char *buf, u_short data)
31 buf[0] = (u_char)(data>>8)&0xff;
32 buf[1] = (u_char)(data)&0xff;
36 inline u_short aimutil_get16(u_char *buf)
39 val = (buf[0] << 8) & 0xff00;
40 val+= (buf[1]) & 0xff;
44 inline int aimutil_put32(u_char *buf, u_long data)
46 buf[0] = (u_char)(data>>24)&0xff;
47 buf[1] = (u_char)(data>>16)&0xff;
48 buf[2] = (u_char)(data>>8)&0xff;
49 buf[3] = (u_char)(data)&0xff;
53 inline u_long aimutil_get32(u_char *buf)
56 val = (buf[0] << 24) & 0xff000000;
57 val+= (buf[1] << 16) & 0x00ff0000;
58 val+= (buf[2] << 8) & 0x0000ff00;
59 val+= (buf[3] ) & 0x000000ff;
62 #endif /* AIMUTIL_USEMACROS */
64 inline int aimutil_putstr(u_char *dest, const u_char *src, int len)
66 memcpy(dest, src, len);
71 * Tokenizing functions. Used to portably replace strtok/sep.
75 int aimutil_tokslen(char *toSearch, int index, char dl)
83 next = strchr(toSearch, dl);
85 while(curCount < index && next != NULL)
89 next = strchr(last, dl);
92 if ((curCount < index) || (next == NULL))
93 toReturn = strlen(toSearch) - (curCount - 1);
95 toReturn = next - toSearch - (curCount - 1);
100 int aimutil_itemcnt(char *toSearch, char dl)
107 next = strchr(toSearch, dl);
112 next = strchr(next + 1, dl);
118 char *aimutil_itemidx(char *toSearch, int index, char dl)
128 next = strchr(toSearch, dl);
130 while(curCount < index && next != NULL)
134 next = strchr(last, dl);
137 if (curCount < index)
139 toReturn = malloc(sizeof(char));
142 next = strchr(last, dl);
144 if (curCount < index)
146 toReturn = malloc(sizeof(char));
153 toReturn = malloc((strlen(last) + 1) * sizeof(char));
154 strcpy(toReturn, last);
158 toReturn = malloc((next - last + 1) * sizeof(char));
159 memcpy(toReturn, last, (next - last));
160 toReturn[next - last] = '\0';
167 * int snlen(const char *)
169 * This takes a screen name and returns its length without
170 * spaces. If there are no spaces in the SN, then the
171 * return is equal to that of strlen().
174 int aim_snlen(const char *sn)
177 const char *curPtr = NULL;
183 while ( (*curPtr) != (char) NULL) {
184 if ((*curPtr) != ' ')
193 * int sncmp(const char *, const char *)
195 * This takes two screen names and compares them using the rules
196 * on screen names for AIM/AOL. Mainly, this means case and space
197 * insensitivity (all case differences and spacing differences are
205 int aim_sncmp(const char *sn1, const char *sn2)
207 const char *curPtr1 = NULL, *curPtr2 = NULL;
209 if (aim_snlen(sn1) != aim_snlen(sn2))
214 while ( (*curPtr1 != (char) NULL) && (*curPtr2 != (char) NULL) ) {
215 if ( (*curPtr1 == ' ') || (*curPtr2 == ' ') ) {
221 if ( toupper(*curPtr1) != toupper(*curPtr2))