annotate src/protocols/oscar/util.c @ 8210:9758dcf0afcc

[gaim-migrate @ 8933] "There ya go kid, something for the old sweet tooth." "You keep a horse in the basement?" "The kids a meatball." "I've never seen that. I've never seen anyone drive their garbage to the street and then bang the hell out of it with a stick. I've never seen that." "This is no ordinary furnace." "Sardine?" committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Thu, 05 Feb 2004 04:43:14 +0000
parents 697221d5d0ff
children 990314a962fb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1 /*
4246
2a2d6d21f1d7 [gaim-migrate @ 4496]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
2 * A little bit of this
2a2d6d21f1d7 [gaim-migrate @ 4496]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
3 * A little bit of that
2a2d6d21f1d7 [gaim-migrate @ 4496]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
4 * It started with a kiss
2a2d6d21f1d7 [gaim-migrate @ 4496]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
5 * Now we're up to bat
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
6 */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
7
2672
c41030cfed76 [gaim-migrate @ 2685]
Adam Fritzler <mid@auk.cx>
parents: 2246
diff changeset
8 #define FAIM_INTERNAL
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
9 #include <aim.h>
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
10 #include <ctype.h>
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
11
4246
2a2d6d21f1d7 [gaim-migrate @ 4496]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
12 #ifdef _WIN32
2a2d6d21f1d7 [gaim-migrate @ 4496]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
13 #include "win32dep.h"
2a2d6d21f1d7 [gaim-migrate @ 4496]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
14 #endif
2a2d6d21f1d7 [gaim-migrate @ 4496]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
15
2a2d6d21f1d7 [gaim-migrate @ 4496]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
16 faim_internal void faimdprintf(aim_session_t *sess, int dlevel, const char *format, ...)
2a2d6d21f1d7 [gaim-migrate @ 4496]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
17 {
2a2d6d21f1d7 [gaim-migrate @ 4496]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
18 if (!sess) {
2a2d6d21f1d7 [gaim-migrate @ 4496]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
19 fprintf(stderr, "faimdprintf: no session! boo! (%d, %s)\n", dlevel, format);
2a2d6d21f1d7 [gaim-migrate @ 4496]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
20 return;
2a2d6d21f1d7 [gaim-migrate @ 4496]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
21 }
2a2d6d21f1d7 [gaim-migrate @ 4496]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
22 if ((dlevel <= sess->debug) && sess->debugcb) {
2a2d6d21f1d7 [gaim-migrate @ 4496]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
23 va_list ap;
2a2d6d21f1d7 [gaim-migrate @ 4496]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
24 va_start(ap, format);
2a2d6d21f1d7 [gaim-migrate @ 4496]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
25 sess->debugcb(sess, dlevel, format, ap);
2a2d6d21f1d7 [gaim-migrate @ 4496]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
26 va_end(ap);
2a2d6d21f1d7 [gaim-migrate @ 4496]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
27 }
2a2d6d21f1d7 [gaim-migrate @ 4496]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
28
2a2d6d21f1d7 [gaim-migrate @ 4496]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
29 return;
2a2d6d21f1d7 [gaim-migrate @ 4496]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
30 }
2a2d6d21f1d7 [gaim-migrate @ 4496]
Mark Doliner <mark@kingant.net>
parents: 3952
diff changeset
31
5927
04dc7fe68889 [gaim-migrate @ 6367]
Mark Doliner <mark@kingant.net>
parents: 5800
diff changeset
32 faim_export int aimutil_putstr(char *dest, const char *src, int len)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
33 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
34 memcpy(dest, src, len);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
35 return len;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
36 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
37
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
38 /*
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
39 * Tokenizing functions. Used to portably replace strtok/sep.
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
40 * -- DMP.
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
41 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
42 */
6323
5d7063e137da [gaim-migrate @ 6822]
Mark Doliner <mark@kingant.net>
parents: 6322
diff changeset
43 faim_export int aimutil_tokslen(char *toSearch, int theindex, char dl)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
44 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
45 int curCount = 1;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
46 char *next;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
47 char *last;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
48 int toReturn;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
49
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
50 last = toSearch;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
51 next = strchr(toSearch, dl);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
52
6323
5d7063e137da [gaim-migrate @ 6822]
Mark Doliner <mark@kingant.net>
parents: 6322
diff changeset
53 while(curCount < theindex && next != NULL) {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
54 curCount++;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
55 last = next + 1;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
56 next = strchr(last, dl);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
57 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
58
6323
5d7063e137da [gaim-migrate @ 6822]
Mark Doliner <mark@kingant.net>
parents: 6322
diff changeset
59 if ((curCount < theindex) || (next == NULL))
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
60 toReturn = strlen(toSearch) - (curCount - 1);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
61 else
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
62 toReturn = next - toSearch - (curCount - 1);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
63
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
64 return toReturn;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
65 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
66
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
67 faim_export int aimutil_itemcnt(char *toSearch, char dl)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
68 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
69 int curCount;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
70 char *next;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
71
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
72 curCount = 1;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
73
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
74 next = strchr(toSearch, dl);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
75
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
76 while(next != NULL) {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
77 curCount++;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
78 next = strchr(next + 1, dl);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
79 }
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
80
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
81 return curCount;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
82 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
83
6323
5d7063e137da [gaim-migrate @ 6822]
Mark Doliner <mark@kingant.net>
parents: 6322
diff changeset
84 faim_export char *aimutil_itemindex(char *toSearch, int theindex, char dl)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
85 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
86 int curCount;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
87 char *next;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
88 char *last;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
89 char *toReturn;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
90
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
91 curCount = 0;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
92
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
93 last = toSearch;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
94 next = strchr(toSearch, dl);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
95
6323
5d7063e137da [gaim-migrate @ 6822]
Mark Doliner <mark@kingant.net>
parents: 6322
diff changeset
96 while (curCount < theindex && next != NULL) {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
97 curCount++;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
98 last = next + 1;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
99 next = strchr(last, dl);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
100 }
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
101
6323
5d7063e137da [gaim-migrate @ 6822]
Mark Doliner <mark@kingant.net>
parents: 6322
diff changeset
102 if (curCount < theindex) {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
103 toReturn = malloc(sizeof(char));
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
104 *toReturn = '\0';
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
105 }
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
106 next = strchr(last, dl);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
107
6323
5d7063e137da [gaim-migrate @ 6822]
Mark Doliner <mark@kingant.net>
parents: 6322
diff changeset
108 if (curCount < theindex) {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
109 toReturn = malloc(sizeof(char));
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
110 *toReturn = '\0';
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
111 } else {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
112 if (next == NULL) {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
113 toReturn = malloc((strlen(last) + 1) * sizeof(char));
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
114 strcpy(toReturn, last);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
115 } else {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
116 toReturn = malloc((next - last + 1) * sizeof(char));
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
117 memcpy(toReturn, last, (next - last));
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
118 toReturn[next - last] = '\0';
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
119 }
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
120 }
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
121 return toReturn;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
122 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
123
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
124 /**
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
125 * Calculate the checksum of a given icon.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
126 *
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
127 */
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
128 faim_export fu16_t aimutil_iconsum(const fu8_t *buf, int buflen)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
129 {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
130 fu32_t sum;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
131 int i;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
132
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
133 for (i=0, sum=0; i+1<buflen; i+=2)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
134 sum += (buf[i+1] << 8) + buf[i];
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
135 if (i < buflen)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
136 sum += buf[i];
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
137 sum = ((sum & 0xffff0000) >> 16) + (sum & 0x0000ffff);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
138
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
139 return sum;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
140 }
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
141
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
142 faim_export int aim_util_getlocalip(fu8_t *ip)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
143 {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
144 struct hostent *hptr;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
145 char localhost[129];
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
146
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
147 /* XXX if available, use getaddrinfo() */
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
148 /* XXX allow client to specify which IP to use for multihomed boxes */
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
149
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
150 if (gethostname(localhost, 128) < 0)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
151 return -1;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
152
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
153 if (!(hptr = gethostbyname(localhost)))
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
154 return -1;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
155 memcpy(ip, hptr->h_addr_list[0], 4);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
156
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
157 return 0;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
158 }
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
159
8092
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
160 /**
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
161 * Check if the given screen name is a valid AIM or ICQ screen name.
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
162 *
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
163 * @return 1 if the screen name is valid, 0 if not.
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
164 */
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
165 faim_export int aim_snvalid(const char *sn)
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
166 {
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
167 int isICQ = 0;
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
168 int i = 0;
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
169
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
170 if (!sn)
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
171 return 0;
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
172
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
173 if (isdigit(sn[0]))
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
174 isICQ = 1;
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
175
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
176 while (sn[i] != '\0') {
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
177 /* If it started with a digit then it betta be all digits, ho */
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
178 if (isICQ) {
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
179 if (!isdigit(sn[i]))
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
180 return 0;
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
181 } else {
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
182 if (!isalnum(sn[i]) && (sn[i] != ' '))
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
183 return 0;
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
184 }
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
185 i++;
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
186 }
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
187
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
188 return 1;
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
189 }
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
190
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
191 /*
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
192 * int snlen(const char *)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
193 *
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
194 * This takes a screen name and returns its length without
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
195 * spaces. If there are no spaces in the SN, then the
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
196 * return is equal to that of strlen().
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
197 *
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
198 */
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
199 faim_export int aim_snlen(const char *sn)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
200 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
201 int i = 0;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
202
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
203 if (!sn)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
204 return 0;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
205
5556
8ab1875e6d09 [gaim-migrate @ 5957]
Mark Doliner <mark@kingant.net>
parents: 5414
diff changeset
206 while (*sn != '\0') {
8ab1875e6d09 [gaim-migrate @ 5957]
Mark Doliner <mark@kingant.net>
parents: 5414
diff changeset
207 if (*sn != ' ')
8ab1875e6d09 [gaim-migrate @ 5957]
Mark Doliner <mark@kingant.net>
parents: 5414
diff changeset
208 i++;
8ab1875e6d09 [gaim-migrate @ 5957]
Mark Doliner <mark@kingant.net>
parents: 5414
diff changeset
209 sn++;
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
210 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
211
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
212 return i;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
213 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
214
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
215 /*
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
216 * int sncmp(const char *, const char *)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
217 *
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
218 * This takes two screen names and compares them using the rules
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
219 * on screen names for AIM/AOL. Mainly, this means case and space
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
220 * insensitivity (all case differences and spacing differences are
5628
9a34e950792e [gaim-migrate @ 6035]
Mark Doliner <mark@kingant.net>
parents: 5556
diff changeset
221 * ignored, with the exception that screen names can not start with
9a34e950792e [gaim-migrate @ 6035]
Mark Doliner <mark@kingant.net>
parents: 5556
diff changeset
222 * a space).
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
223 *
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
224 * Return: 0 if equal
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
225 * non-0 if different
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
226 *
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
227 */
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
228 faim_export int aim_sncmp(const char *sn1, const char *sn2)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
229 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
230
5928
395c7f769e05 [gaim-migrate @ 6368]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
231 do {
5556
8ab1875e6d09 [gaim-migrate @ 5957]
Mark Doliner <mark@kingant.net>
parents: 5414
diff changeset
232 while (*sn2 == ' ')
5724
c4e0b20cf466 [gaim-migrate @ 6146]
Mark Doliner <mark@kingant.net>
parents: 5628
diff changeset
233 sn2++;
5556
8ab1875e6d09 [gaim-migrate @ 5957]
Mark Doliner <mark@kingant.net>
parents: 5414
diff changeset
234 while (*sn1 == ' ')
5724
c4e0b20cf466 [gaim-migrate @ 6146]
Mark Doliner <mark@kingant.net>
parents: 5628
diff changeset
235 sn1++;
5928
395c7f769e05 [gaim-migrate @ 6368]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
236 if (toupper(*sn1) != toupper(*sn2))
395c7f769e05 [gaim-migrate @ 6368]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
237 return 1;
395c7f769e05 [gaim-migrate @ 6368]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
238 } while ((*sn1 != '\0') && sn1++ && sn2++);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
239
5928
395c7f769e05 [gaim-migrate @ 6368]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
240 return 0;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
241 }