Mercurial > pidgin
comparison libpurple/protocols/oscar/util.c @ 18279:48d2c9dbfcc2
Allow AIM screen names of the form "1abc@example.com" In most places
we determine if a buddy is an ICQ user by checking if the first
character of the screen name is a digit. But this check doesn't work
now that email addresses are allowed for AIM screen names.
This fixes #1430.
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Mon, 25 Jun 2007 08:41:49 +0000 |
parents | 1927f4ead3ca |
children | c298830e237f |
comparison
equal
deleted
inserted
replaced
18278:c3d5b91be081 | 18279:48d2c9dbfcc2 |
---|---|
35 /* | 35 /* |
36 * Tokenizing functions. Used to portably replace strtok/sep. | 36 * Tokenizing functions. Used to portably replace strtok/sep. |
37 * -- DMP. | 37 * -- DMP. |
38 * | 38 * |
39 */ | 39 */ |
40 /* TODO: Get rid of this and use glib functions */ | |
40 int | 41 int |
41 aimutil_tokslen(char *toSearch, int theindex, char dl) | 42 aimutil_tokslen(char *toSearch, int theindex, char dl) |
42 { | 43 { |
43 int curCount = 1; | 44 int curCount = 1; |
44 char *next; | 45 char *next; |
136 | 137 |
137 /** | 138 /** |
138 * Check if the given screen name is a valid AIM screen name. | 139 * Check if the given screen name is a valid AIM screen name. |
139 * Example: BobDole | 140 * Example: BobDole |
140 * Example: Henry_Ford@mac.com | 141 * Example: Henry_Ford@mac.com |
142 * Example: 1KrazyKat@example.com | |
141 * | 143 * |
142 * @return TRUE if the screen name is valid, FALSE if not. | 144 * @return TRUE if the screen name is valid, FALSE if not. |
143 */ | 145 */ |
144 static gboolean | 146 static gboolean |
145 aim_snvalid_aim(const char *sn) | 147 aim_snvalid_aim(const char *sn) |
146 { | 148 { |
147 int i; | 149 int i; |
148 | 150 |
151 if (purple_email_is_valid(sn)) | |
152 return TRUE; | |
153 | |
149 for (i = 0; sn[i] != '\0'; i++) { | 154 for (i = 0; sn[i] != '\0'; i++) { |
150 if (!isalnum(sn[i]) && (sn[i] != ' ') && | 155 if (!isalnum(sn[i]) && (sn[i] != ' ') && |
151 (sn[i] != '@') && (sn[i] != '.') && | 156 (sn[i] != '.') && |
152 (sn[i] != '_') && (sn[i] != '-')) | 157 (sn[i] != '_') && (sn[i] != '-')) |
153 return FALSE; | 158 return FALSE; |
154 } | 159 } |
155 | 160 |
156 return TRUE; | 161 return TRUE; |
167 { | 172 { |
168 int i; | 173 int i; |
169 | 174 |
170 for (i = 0; sn[i] != '\0'; i++) { | 175 for (i = 0; sn[i] != '\0'; i++) { |
171 if (!isdigit(sn[i])) | 176 if (!isdigit(sn[i])) |
172 return 0; | 177 return FALSE; |
173 } | 178 } |
174 | 179 |
175 return 1; | 180 return TRUE; |
176 } | 181 } |
177 | 182 |
178 /** | 183 /** |
179 * Check if the given screen name is a valid SMS screen name. | 184 * Check if the given screen name is a valid SMS screen name. |
180 * Example: +19195551234 | 185 * Example: +19195551234 |
185 aim_snvalid_sms(const char *sn) | 190 aim_snvalid_sms(const char *sn) |
186 { | 191 { |
187 int i; | 192 int i; |
188 | 193 |
189 if (sn[0] != '+') | 194 if (sn[0] != '+') |
190 return 0; | 195 return FALSE; |
191 | 196 |
192 for (i = 1; sn[i] != '\0'; i++) { | 197 for (i = 1; sn[i] != '\0'; i++) { |
193 if (!isdigit(sn[i])) | 198 if (!isdigit(sn[i])) |
194 return 0; | 199 return FALSE; |
195 } | 200 } |
196 | 201 |
197 return 1; | 202 return TRUE; |
198 } | 203 } |
199 | 204 |
200 /** | 205 /** |
201 * Check if the given screen name is a valid oscar screen name. | 206 * Check if the given screen name is a valid oscar screen name. |
202 * | 207 * |
204 */ | 209 */ |
205 gboolean | 210 gboolean |
206 aim_snvalid(const char *sn) | 211 aim_snvalid(const char *sn) |
207 { | 212 { |
208 if ((sn == NULL) || (*sn == '\0')) | 213 if ((sn == NULL) || (*sn == '\0')) |
209 return 0; | 214 return FALSE; |
210 | 215 |
211 if (isalpha(sn[0])) | 216 return aim_snvalid_icq(sn) || aim_snvalid_sms(sn) || aim_snvalid_aim(sn); |
212 return aim_snvalid_aim(sn); | |
213 else if (isdigit(sn[0])) | |
214 return aim_snvalid_icq(sn); | |
215 else if (sn[0] == '+') | |
216 return aim_snvalid_sms(sn); | |
217 | |
218 return 0; | |
219 } | 217 } |
220 | 218 |
221 /** | 219 /** |
222 * Determine if a given screen name is an ICQ screen name | 220 * Determine if a given screen name is an ICQ screen name |
223 * (i.e. it begins with a number). | 221 * (i.e. it is composed of only numbers). |
224 * | 222 * |
225 * @sn A valid AIM or ICQ screen name. | 223 * @param sn A valid AIM or ICQ screen name. |
226 * @return TRUE if the screen name is an ICQ screen name. Otherwise | 224 * @return TRUE if the screen name is an ICQ screen name. Otherwise |
227 * FALSE is returned. | 225 * FALSE is returned. |
228 */ | 226 */ |
229 gboolean | 227 gboolean |
230 aim_sn_is_icq(const char *sn) | 228 aim_sn_is_icq(const char *sn) |
231 { | 229 { |
232 if (isalpha(sn[0])) | 230 return aim_snvalid_icq(sn); |
233 return FALSE; | |
234 return TRUE; | |
235 } | 231 } |
236 | 232 |
237 /** | 233 /** |
238 * Determine if a given screen name is an SMS number | 234 * Determine if a given screen name is an SMS number |
239 * (i.e. it begins with a +). | 235 * (i.e. it begins with a +). |
240 * | 236 * |
241 * @sn A valid AIM or ICQ screen name. | 237 * @param sn A valid AIM or ICQ screen name. |
242 * @return TRUE if the screen name is an SMS number. Otherwise | 238 * @return TRUE if the screen name is an SMS number. Otherwise |
243 * FALSE is returned. | 239 * FALSE is returned. |
244 */ | 240 */ |
245 gboolean | 241 gboolean |
246 aim_sn_is_sms(const char *sn) | 242 aim_sn_is_sms(const char *sn) |
247 { | 243 { |
248 if (sn[0] != '+') | 244 return (sn[0] == '+'); |
249 return FALSE; | |
250 return TRUE; | |
251 } | |
252 | |
253 /** | |
254 * This takes a screen name and returns its length without | |
255 * spaces. If there are no spaces in the SN, then the | |
256 * return is equal to that of strlen(). | |
257 */ | |
258 int | |
259 aim_snlen(const char *sn) | |
260 { | |
261 int i = 0; | |
262 | |
263 if (!sn) | |
264 return 0; | |
265 | |
266 while (*sn != '\0') { | |
267 if (*sn != ' ') | |
268 i++; | |
269 sn++; | |
270 } | |
271 | |
272 return i; | |
273 } | 245 } |
274 | 246 |
275 /** | 247 /** |
276 * This takes two screen names and compares them using the rules | 248 * This takes two screen names and compares them using the rules |
277 * on screen names for AIM/AOL. Mainly, this means case and space | 249 * on screen names for AIM/AOL. Mainly, this means case and space |
278 * insensitivity (all case differences and spacing differences are | 250 * insensitivity (all case differences and spacing differences are |
279 * ignored, with the exception that screen names can not start with | 251 * ignored, with the exception that screen names can not start with |
280 * a space). | 252 * a space). |
281 * | 253 * |
282 * Return: 0 if equal | 254 * @return 0 if equal, non-0 if different |
283 * non-0 if different | 255 */ |
284 */ | 256 /* TODO: Do something different for email addresses. */ |
285 int | 257 int |
286 aim_sncmp(const char *sn1, const char *sn2) | 258 aim_sncmp(const char *sn1, const char *sn2) |
287 { | 259 { |
288 | 260 |
289 if ((sn1 == NULL) || (sn2 == NULL)) | 261 if ((sn1 == NULL) || (sn2 == NULL)) |