annotate src/protocols/oscar/util.c @ 12756:6ef1cdc26b40

[gaim-migrate @ 15103] Cleanup to STUN code. Fixed endianness. Fixed to work where sizeof(short) != 2 or sizeof(int) != 4. Close the socket when we're done with it. Instead of using a bunch of static variables, pass data around the various callbacks. Don't invoke the specified StunCallback before the initial function has returned. Deal with requerying if the STUN server has changed since last query, or the last query was unsuccessful and 5 minutes have elapsed. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Sat, 07 Jan 2006 22:10:18 +0000
parents 7d31d61e6438
children bdb8d7beb5a7
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
5927
04dc7fe68889 [gaim-migrate @ 6367]
Mark Doliner <mark@kingant.net>
parents: 5800
diff changeset
16 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
17 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
18 memcpy(dest, src, len);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
19 return len;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
20 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
21
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
22 /*
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
23 * Tokenizing functions. Used to portably replace strtok/sep.
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
24 * -- DMP.
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
25 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
26 */
6323
5d7063e137da [gaim-migrate @ 6822]
Mark Doliner <mark@kingant.net>
parents: 6322
diff changeset
27 faim_export int aimutil_tokslen(char *toSearch, int theindex, char dl)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
28 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
29 int curCount = 1;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
30 char *next;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
31 char *last;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
32 int toReturn;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
33
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
34 last = toSearch;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
35 next = strchr(toSearch, dl);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
36
6323
5d7063e137da [gaim-migrate @ 6822]
Mark Doliner <mark@kingant.net>
parents: 6322
diff changeset
37 while(curCount < theindex && next != NULL) {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
38 curCount++;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
39 last = next + 1;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
40 next = strchr(last, dl);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
41 }
2086
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 if ((curCount < theindex) || (next == NULL))
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
44 toReturn = strlen(toSearch) - (curCount - 1);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
45 else
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
46 toReturn = next - toSearch - (curCount - 1);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
47
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
48 return toReturn;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
49 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
50
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
51 faim_export int aimutil_itemcnt(char *toSearch, char dl)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
52 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
53 int curCount;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
54 char *next;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
55
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
56 curCount = 1;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
57
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
58 next = strchr(toSearch, dl);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
59
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
60 while(next != NULL) {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
61 curCount++;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
62 next = strchr(next + 1, dl);
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
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
65 return curCount;
2086
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
6323
5d7063e137da [gaim-migrate @ 6822]
Mark Doliner <mark@kingant.net>
parents: 6322
diff changeset
68 faim_export char *aimutil_itemindex(char *toSearch, int theindex, char dl)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
69 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
70 int curCount;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
71 char *next;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
72 char *last;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
73 char *toReturn;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
74
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
75 curCount = 0;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
76
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
77 last = toSearch;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
78 next = strchr(toSearch, dl);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
79
6323
5d7063e137da [gaim-migrate @ 6822]
Mark Doliner <mark@kingant.net>
parents: 6322
diff changeset
80 while (curCount < theindex && next != NULL) {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
81 curCount++;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
82 last = next + 1;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
83 next = strchr(last, dl);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
84 }
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
85
6323
5d7063e137da [gaim-migrate @ 6822]
Mark Doliner <mark@kingant.net>
parents: 6322
diff changeset
86 if (curCount < theindex) {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
87 toReturn = malloc(sizeof(char));
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
88 *toReturn = '\0';
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
89 }
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
90 next = strchr(last, dl);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
91
6323
5d7063e137da [gaim-migrate @ 6822]
Mark Doliner <mark@kingant.net>
parents: 6322
diff changeset
92 if (curCount < theindex) {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
93 toReturn = malloc(sizeof(char));
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
94 *toReturn = '\0';
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
95 } else {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
96 if (next == NULL) {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
97 toReturn = malloc((strlen(last) + 1) * sizeof(char));
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
98 strcpy(toReturn, last);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
99 } else {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
100 toReturn = malloc((next - last + 1) * sizeof(char));
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
101 memcpy(toReturn, last, (next - last));
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
102 toReturn[next - last] = '\0';
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
103 }
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
104 }
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
105 return toReturn;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
106 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
107
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
108 /**
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
109 * Calculate the checksum of a given icon.
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
110 *
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
111 */
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
112 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
113 {
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
114 fu32_t sum;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
115 int i;
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
116
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
117 for (i=0, sum=0; i+1<buflen; i+=2)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
118 sum += (buf[i+1] << 8) + buf[i];
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
119 if (i < buflen)
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
120 sum += buf[i];
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
121 sum = ((sum & 0xffff0000) >> 16) + (sum & 0x0000ffff);
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
122
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 4246
diff changeset
123 return sum;
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
8092
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
126 /**
8972
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
127 * Check if the given screen name is a valid AIM screen name.
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
128 * Example: BobDole
9681
6fd2bd5446e4 [gaim-migrate @ 10533]
Mark Doliner <mark@kingant.net>
parents: 8982
diff changeset
129 * Example: Henry_Ford@mac.com
8972
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
130 *
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
131 * @return 1 if the screen name is valid, 0 if not.
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
132 */
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
133 static int aim_snvalid_aim(const char *sn)
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
134 {
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
135 int i;
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
136
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
137 for (i = 0; sn[i] != '\0'; i++) {
9681
6fd2bd5446e4 [gaim-migrate @ 10533]
Mark Doliner <mark@kingant.net>
parents: 8982
diff changeset
138 if (!isalnum(sn[i]) && (sn[i] != ' ') &&
6fd2bd5446e4 [gaim-migrate @ 10533]
Mark Doliner <mark@kingant.net>
parents: 8982
diff changeset
139 (sn[i] != '@') && (sn[i] != '.') &&
6fd2bd5446e4 [gaim-migrate @ 10533]
Mark Doliner <mark@kingant.net>
parents: 8982
diff changeset
140 (sn[i] != '_') && (sn[i] != '-'))
8972
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
141 return 0;
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
142 }
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
143
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
144 return 1;
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
145 }
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
146
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
147 /**
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
148 * Check if the given screen name is a valid ICQ screen name.
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
149 * Example: 1234567
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
150 *
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
151 * @return 1 if the screen name is valid, 0 if not.
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
152 */
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
153 static int aim_snvalid_icq(const char *sn)
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
154 {
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
155 int i;
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
156
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
157 for (i = 0; sn[i] != '\0'; i++) {
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
158 if (!isdigit(sn[i]))
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
159 return 0;
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
160 }
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
161
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
162 return 1;
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
163 }
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
164
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
165 /**
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
166 * Check if the given screen name is a valid SMS screen name.
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
167 * Example: +19195551234
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
168 *
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
169 * @return 1 if the screen name is valid, 0 if not.
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
170 */
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
171 static int aim_snvalid_sms(const char *sn)
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
172 {
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
173 int i;
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
174
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
175 if (sn[0] != '+')
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
176 return 0;
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
177
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
178 for (i = 1; sn[i] != '\0'; i++) {
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
179 if (!isdigit(sn[i]))
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
180 return 0;
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
181 }
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
182
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
183 return 1;
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
184 }
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
185
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
186 /**
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
187 * Check if the given screen name is a valid oscar screen name.
8092
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
188 *
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
189 * @return 1 if the screen name is valid, 0 if not.
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
190 */
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
191 faim_export int aim_snvalid(const char *sn)
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
192 {
8972
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
193 if ((sn == NULL) || (*sn == '\0'))
8092
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
194 return 0;
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
195
8972
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
196 if (isalpha(sn[0]))
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
197 return aim_snvalid_aim(sn);
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
198 else if (isdigit(sn[0]))
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
199 return aim_snvalid_icq(sn);
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
200 else if (sn[0] == '+')
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
201 return aim_snvalid_sms(sn);
8092
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
202
8972
f09801513729 [gaim-migrate @ 9746]
Mark Doliner <mark@kingant.net>
parents: 8885
diff changeset
203 return 0;
8092
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
204 }
697221d5d0ff [gaim-migrate @ 8791]
Mark Doliner <mark@kingant.net>
parents: 6323
diff changeset
205
9975
c66345b33b88 [gaim-migrate @ 10886]
Mark Doliner <mark@kingant.net>
parents: 9681
diff changeset
206 /**
c66345b33b88 [gaim-migrate @ 10886]
Mark Doliner <mark@kingant.net>
parents: 9681
diff changeset
207 * Determine if a given screen name is an ICQ screen name
c66345b33b88 [gaim-migrate @ 10886]
Mark Doliner <mark@kingant.net>
parents: 9681
diff changeset
208 * (i.e. it begins with a number).
c66345b33b88 [gaim-migrate @ 10886]
Mark Doliner <mark@kingant.net>
parents: 9681
diff changeset
209 *
c66345b33b88 [gaim-migrate @ 10886]
Mark Doliner <mark@kingant.net>
parents: 9681
diff changeset
210 * @sn A valid AIM or ICQ screen name.
c66345b33b88 [gaim-migrate @ 10886]
Mark Doliner <mark@kingant.net>
parents: 9681
diff changeset
211 * @return 1 if the screen name is an ICQ screen name. Otherwise 0
c66345b33b88 [gaim-migrate @ 10886]
Mark Doliner <mark@kingant.net>
parents: 9681
diff changeset
212 * is returned.
c66345b33b88 [gaim-migrate @ 10886]
Mark Doliner <mark@kingant.net>
parents: 9681
diff changeset
213 */
c66345b33b88 [gaim-migrate @ 10886]
Mark Doliner <mark@kingant.net>
parents: 9681
diff changeset
214 faim_export int aim_sn_is_icq(const char *sn)
c66345b33b88 [gaim-migrate @ 10886]
Mark Doliner <mark@kingant.net>
parents: 9681
diff changeset
215 {
c66345b33b88 [gaim-migrate @ 10886]
Mark Doliner <mark@kingant.net>
parents: 9681
diff changeset
216 if (isalpha(sn[0]))
c66345b33b88 [gaim-migrate @ 10886]
Mark Doliner <mark@kingant.net>
parents: 9681
diff changeset
217 return 0;
c66345b33b88 [gaim-migrate @ 10886]
Mark Doliner <mark@kingant.net>
parents: 9681
diff changeset
218 return 1;
c66345b33b88 [gaim-migrate @ 10886]
Mark Doliner <mark@kingant.net>
parents: 9681
diff changeset
219 }
c66345b33b88 [gaim-migrate @ 10886]
Mark Doliner <mark@kingant.net>
parents: 9681
diff changeset
220
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
221 /*
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
222 * int snlen(const char *)
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 * This takes a screen name and returns its length without
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
225 * spaces. If there are no spaces in the SN, then the
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
226 * return is equal to that of strlen().
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
227 *
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
228 */
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
229 faim_export int aim_snlen(const char *sn)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
230 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
231 int i = 0;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
232
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
233 if (!sn)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
234 return 0;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
235
5556
8ab1875e6d09 [gaim-migrate @ 5957]
Mark Doliner <mark@kingant.net>
parents: 5414
diff changeset
236 while (*sn != '\0') {
8ab1875e6d09 [gaim-migrate @ 5957]
Mark Doliner <mark@kingant.net>
parents: 5414
diff changeset
237 if (*sn != ' ')
8ab1875e6d09 [gaim-migrate @ 5957]
Mark Doliner <mark@kingant.net>
parents: 5414
diff changeset
238 i++;
8ab1875e6d09 [gaim-migrate @ 5957]
Mark Doliner <mark@kingant.net>
parents: 5414
diff changeset
239 sn++;
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
240 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
241
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
242 return i;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
243 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
244
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
245 /*
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
246 * int sncmp(const char *, const char *)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
247 *
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
248 * This takes two screen names and compares them using the rules
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
249 * 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
250 * insensitivity (all case differences and spacing differences are
5628
9a34e950792e [gaim-migrate @ 6035]
Mark Doliner <mark@kingant.net>
parents: 5556
diff changeset
251 * ignored, with the exception that screen names can not start with
9a34e950792e [gaim-migrate @ 6035]
Mark Doliner <mark@kingant.net>
parents: 5556
diff changeset
252 * a space).
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
253 *
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
254 * Return: 0 if equal
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
255 * non-0 if different
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
256 *
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
257 */
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
258 faim_export int aim_sncmp(const char *sn1, const char *sn2)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
259 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
260
10116
9f358a718f38 [gaim-migrate @ 11153]
Stu Tomlinson <stu@nosnilmot.com>
parents: 9975
diff changeset
261 if ((sn1 == NULL) || (sn2 == NULL))
9f358a718f38 [gaim-migrate @ 11153]
Stu Tomlinson <stu@nosnilmot.com>
parents: 9975
diff changeset
262 return -1;
9f358a718f38 [gaim-migrate @ 11153]
Stu Tomlinson <stu@nosnilmot.com>
parents: 9975
diff changeset
263
5928
395c7f769e05 [gaim-migrate @ 6368]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
264 do {
5556
8ab1875e6d09 [gaim-migrate @ 5957]
Mark Doliner <mark@kingant.net>
parents: 5414
diff changeset
265 while (*sn2 == ' ')
5724
c4e0b20cf466 [gaim-migrate @ 6146]
Mark Doliner <mark@kingant.net>
parents: 5628
diff changeset
266 sn2++;
5556
8ab1875e6d09 [gaim-migrate @ 5957]
Mark Doliner <mark@kingant.net>
parents: 5414
diff changeset
267 while (*sn1 == ' ')
5724
c4e0b20cf466 [gaim-migrate @ 6146]
Mark Doliner <mark@kingant.net>
parents: 5628
diff changeset
268 sn1++;
5928
395c7f769e05 [gaim-migrate @ 6368]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
269 if (toupper(*sn1) != toupper(*sn2))
395c7f769e05 [gaim-migrate @ 6368]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
270 return 1;
395c7f769e05 [gaim-migrate @ 6368]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
271 } while ((*sn1 != '\0') && sn1++ && sn2++);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
272
5928
395c7f769e05 [gaim-migrate @ 6368]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
273 return 0;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
274 }