Sun, 28 Jan 2001 01:52:27 +0000
[gaim-migrate @ 1442]
icqlib 1.1.5
| 1152 | 1 | /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
| 2 | /* | |
|
1432
ab10a52f94a7
[gaim-migrate @ 1442]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1309
diff
changeset
|
3 | $Id: util.c 1442 2001-01-28 01:52:27Z warmenhoven $ |
| 1152 | 4 | $Log$ |
|
1432
ab10a52f94a7
[gaim-migrate @ 1442]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1309
diff
changeset
|
5 | Revision 1.3 2001/01/28 01:52:27 warmenhoven |
|
ab10a52f94a7
[gaim-migrate @ 1442]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1309
diff
changeset
|
6 | icqlib 1.1.5 |
|
1309
dccfec27ffd4
[gaim-migrate @ 1319]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1152
diff
changeset
|
7 | |
|
dccfec27ffd4
[gaim-migrate @ 1319]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1152
diff
changeset
|
8 | Revision 1.33 2000/08/13 19:26:50 denis |
|
dccfec27ffd4
[gaim-migrate @ 1319]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1152
diff
changeset
|
9 | icq_Genders[] array have been added. |
| 1152 | 10 | |
| 11 | Revision 1.32 2000/07/22 16:49:32 denis | |
| 12 | Trinidad and Tobago country was added. | |
| 13 | ||
| 14 | Revision 1.31 2000/07/21 16:51:20 denis | |
| 15 | All languages, possible in original icq were added. | |
| 16 | Occupation array fixed. | |
| 17 | ||
| 18 | Revision 1.30 2000/07/20 09:58:59 denis | |
| 19 | Occupation table corrected to comply with original ICQ. | |
| 20 | ||
| 21 | Revision 1.29 2000/07/04 07:25:29 pcadach | |
| 22 | icq_FmtLog() crashed when it receives NULL at link argument. | |
| 23 | ||
| 24 | Revision 1.28 2000/06/30 13:59:43 denis | |
| 25 | Slovak Republic country code fixed. | |
| 26 | ||
| 27 | Revision 1.27 2000/06/25 17:00:32 denis | |
| 28 | icq_MetaOccupation[], icq_MetaPastBackgrounds[], | |
| 29 | icq_MetaAffiliations[] and icq_MetaLanguages[] arrays were added along | |
| 30 | with icq_GetMetaOccupationName(), icq_GetMetaBackgroundName(), | |
| 31 | icq_GetMetaAffiliationName() and icq_GetMetaLanguageName() functions | |
| 32 | to access them. | |
| 33 | ||
| 34 | Revision 1.26 2000/05/21 17:42:51 denis | |
| 35 | Bulgaria country code was added. Thanks to | |
| 36 | "Napalm Death" <napalmbox@hotmail.com> | |
| 37 | ||
| 38 | Revision 1.25 2000/05/03 18:29:15 denis | |
| 39 | Callbacks have been moved to the ICQLINK structure. | |
| 40 | ||
| 41 | Revision 1.24 2000/04/10 16:36:04 denis | |
| 42 | Some more Win32 compatibility from Guillaume Rosanis <grs@mail.com> | |
| 43 | ||
| 44 | Revision 1.23 2000/04/05 14:37:02 denis | |
| 45 | Applied patch from "Guillaume R." <grs@mail.com> for basic Win32 | |
| 46 | compatibility. | |
| 47 | ||
| 48 | Revision 1.22 2000/03/31 12:49:15 nofate | |
| 49 | remove static variable | |
| 50 | ||
| 51 | Revision 1.21 1999/11/11 15:10:33 guruz | |
| 52 | - Added Base for Webpager Messages. Please type "make fixme" | |
| 53 | - Removed Segfault when kicq is started the first time | |
| 54 | ||
| 55 | Revision 1.20 1999/10/07 18:01:40 denis | |
| 56 | Cleanups. | |
| 57 | ||
| 58 | Revision 1.19 1999/09/29 17:16:45 denis | |
| 59 | Cleanups. | |
| 60 | ||
| 61 | Revision 1.18 1999/07/18 20:24:27 bills | |
| 62 | removed old byte order and contact list functions | |
| 63 | ||
| 64 | Revision 1.17 1999/07/16 15:46:03 denis | |
| 65 | Cleaned up. | |
| 66 | ||
| 67 | Revision 1.16 1999/07/16 12:04:49 denis | |
| 68 | Status support changed. | |
| 69 | ||
| 70 | Revision 1.15 1999/07/12 15:13:46 cproch | |
| 71 | - added definition of ICQLINK to hold session-specific global variabled | |
| 72 | applications which have more than one connection are now possible | |
| 73 | - changed nearly every function defintion to support ICQLINK parameter | |
| 74 | ||
| 75 | Revision 1.14 1999/04/17 19:20:35 bills | |
| 76 | removed *_link entries from icq_ContactItem, including cleanup/init code | |
| 77 | ||
| 78 | Revision 1.13 1999/04/14 15:06:51 denis | |
| 79 | Cleanups for "strict" compiling (-ansi -pedantic) | |
| 80 | ||
| 81 | */ | |
| 82 | ||
| 83 | #include <stdlib.h> | |
| 84 | #include <ctype.h> | |
| 85 | ||
| 86 | #ifndef _WIN32 | |
| 87 | #include <unistd.h> | |
| 88 | #endif | |
| 89 | ||
| 90 | #include "icqtypes.h" | |
| 91 | #include "icq.h" | |
| 92 | #include "icqlib.h" | |
| 93 | #include "stdpackets.h" | |
| 94 | #include "util.h" | |
| 95 | #include "stdarg.h" | |
| 96 | ||
| 97 | /* | |
| 98 | * This list of countries should be sorted according to country code. | |
| 99 | * When adding new country, please preserve the order! | |
| 100 | */ | |
| 101 | icq_ArrayType icq_Countries[] = { | |
| 102 | {"USA",1}, | |
| 103 | {"Russia",7}, | |
| 104 | {"Egypt",20}, | |
| 105 | {"South Africa",27}, | |
| 106 | {"Greece",30}, | |
| 107 | {"Netherlands",31}, | |
| 108 | {"Belgium",32}, | |
| 109 | {"France",33}, | |
| 110 | {"Monaco",33}, | |
| 111 | {"Spain",34}, | |
| 112 | {"Hungary",36}, | |
| 113 | {"Yugoslavia",38}, | |
| 114 | {"Italy",39}, | |
| 115 | {"San Marino",39}, | |
| 116 | {"Vatican City",39}, | |
| 117 | {"Romania",40}, | |
| 118 | {"Liechtenstein",41}, | |
| 119 | {"Switzerland",41}, | |
| 120 | {"Czech Republic",42}, | |
| 121 | {"Austria",43}, | |
| 122 | {"UK",44}, | |
| 123 | {"Denmark",45}, | |
| 124 | {"Sweden",46}, | |
| 125 | {"Norway",47}, | |
| 126 | {"Poland",48}, | |
| 127 | {"Germany",49}, | |
| 128 | {"Peru",51}, | |
| 129 | {"Mexico",52}, | |
| 130 | {"Guantanomo Bay",53}, | |
| 131 | {"Argentina",54}, | |
| 132 | {"Brazil",55}, | |
| 133 | {"Chile",56}, | |
| 134 | {"Columbia",57}, | |
| 135 | {"Venezuela",58}, | |
| 136 | {"Malaysia",60}, | |
| 137 | {"Australia",61}, | |
| 138 | {"Indonesia",62}, | |
| 139 | {"Philippines",63}, | |
| 140 | {"New Zealand",64}, | |
| 141 | {"Singapore",65}, | |
| 142 | {"Thailand",66}, | |
| 143 | {"Japan",81}, | |
| 144 | {"South Korea",82}, | |
| 145 | {"Vietnam",84}, | |
| 146 | {"China",86}, | |
| 147 | {"Turkey",90}, | |
| 148 | {"India",91}, | |
| 149 | {"Pakistan",92}, | |
| 150 | {"Sri Lanka",94}, | |
| 151 | {"Iran",98}, | |
| 152 | {"Canada",107}, | |
| 153 | {"Morocco",212}, | |
| 154 | {"Algeria",213}, | |
| 155 | {"Tunisia",216}, | |
| 156 | {"Libya",218}, | |
| 157 | {"Senegal",221}, | |
| 158 | {"Mali",223}, | |
| 159 | {"Ivory Coast",225}, | |
| 160 | {"Liberia",231}, | |
| 161 | {"Ghana",233}, | |
| 162 | {"Nigeria",234}, | |
| 163 | {"Cameroon",237}, | |
| 164 | {"Gabon",241}, | |
| 165 | {"Zaire",243}, | |
| 166 | {"Ethiopia",251}, | |
| 167 | {"Kenya",254}, | |
| 168 | {"Tanzania",255}, | |
| 169 | {"Zimbabwe",263}, | |
| 170 | {"Namibia",264}, | |
| 171 | {"Malawi",265}, | |
| 172 | {"Aruba",297}, | |
| 173 | {"Portugal",351}, | |
| 174 | {"Luxembourg",352}, | |
| 175 | {"Ireland",353}, | |
| 176 | {"Iceland",354}, | |
| 177 | {"Malta",356}, | |
| 178 | {"Cyprus",357}, | |
| 179 | {"Finland",358}, | |
| 180 | {"Bulgaria",359}, | |
| 181 | {"Ukraine",380}, | |
| 182 | {"Belize",501}, | |
| 183 | {"Guatemala",502}, | |
| 184 | {"El Salvador",503}, | |
| 185 | {"Honduras",504}, | |
| 186 | {"Nicaragua",505}, | |
| 187 | {"Costa Rice",506}, | |
| 188 | {"Panama",507}, | |
| 189 | {"Haiti",509}, | |
| 190 | {"Guadeloupe",590}, | |
| 191 | {"Bolivia",591}, | |
| 192 | {"Guyana",592}, | |
| 193 | {"Ecuador",593}, | |
| 194 | {"Paraguay",595}, | |
| 195 | {"French Antilles",596}, | |
| 196 | {"Suriname",597}, | |
| 197 | {"Uruguay",598}, | |
| 198 | {"Netherlands Antilles",599}, | |
| 199 | {"Saipan",670}, | |
| 200 | {"Saipan",670}, | |
| 201 | {"Guam",671}, | |
| 202 | {"Papua New Guinea",675}, | |
| 203 | {"Fiji",679}, | |
| 204 | {"American Samoa",684}, | |
| 205 | {"New Caledonia",687}, | |
| 206 | {"French Polynesia",689}, | |
| 207 | {"Hong Kong",852}, | |
| 208 | {"Trinidad and Tobago",868}, | |
| 209 | {"Bangladesh",880}, | |
| 210 | {"Taiwan",886}, | |
| 211 | {"Jordan",962}, | |
| 212 | {"Iraq",964}, | |
| 213 | {"Kuwait",965}, | |
| 214 | {"Saudia Arabia",966}, | |
| 215 | {"Yemen",967}, | |
| 216 | {"Oman",968}, | |
| 217 | {"United Arab Emirates",971}, | |
| 218 | {"Israel",972}, | |
| 219 | {"Bahrain",973}, | |
| 220 | {"Qatar",974}, | |
| 221 | {"Nepal",977}, | |
| 222 | {"Slovak Republic",4201}, | |
| 223 | {"Not entered",0xffff}, | |
| 224 | }; | |
| 225 | ||
| 226 | icq_ArrayType icq_MetaOccupation[] = { | |
| 227 | {"Academic", 1}, | |
| 228 | {"Administrative", 2}, | |
| 229 | {"Art/Entertainment", 3}, | |
| 230 | {"College Student", 4}, | |
| 231 | {"Computers", 5}, | |
| 232 | {"Community & Social", 6}, | |
| 233 | {"Education", 7}, | |
| 234 | {"Engineering", 8}, | |
| 235 | {"Financial Services", 9}, | |
| 236 | {"Government", 10}, | |
| 237 | {"High School Student", 11}, | |
| 238 | {"Home", 12}, | |
| 239 | {"ICQ - Providing Help", 13}, | |
| 240 | {"Law", 14}, | |
| 241 | {"Managerial", 15}, | |
| 242 | {"Manufacturing", 16}, | |
| 243 | {"Medical/Health", 17}, | |
| 244 | {"Military", 18}, | |
| 245 | {"Non-Government Organization", 19}, | |
| 246 | {"Professional", 20}, | |
| 247 | {"Retail", 21}, | |
| 248 | {"Retired", 22}, | |
| 249 | {"Science & Research", 23}, | |
| 250 | {"Sports", 24}, | |
| 251 | {"Technical", 25}, | |
| 252 | {"University Student", 26}, | |
| 253 | {"Web Building", 27}, | |
| 254 | {"Other Services", 99}, | |
| 255 | }; | |
| 256 | ||
| 257 | icq_ArrayType icq_MetaPastBackgrounds[] = { | |
| 258 | {"Elementary School", 300}, | |
| 259 | {"High School", 301}, | |
| 260 | {"College", 302}, | |
| 261 | {"University", 303}, | |
| 262 | {"Military", 304}, | |
| 263 | {"Past Work Place", 305}, | |
| 264 | {"Past Organization", 306}, | |
| 265 | {"Other", 399}, | |
| 266 | }; | |
| 267 | ||
| 268 | icq_ArrayType icq_MetaAffiliations[] = { | |
| 269 | {"Alumni Org.", 200}, | |
| 270 | {"Charity Org.", 201}, | |
| 271 | {"Club/Social Org.", 202}, | |
| 272 | {"Community Org.", 203}, | |
| 273 | {"Cultural Org.", 204}, | |
| 274 | {"Fan Clubs", 205}, | |
| 275 | {"Fraternity/Sorority", 206}, | |
| 276 | {"Hobbyists Org.", 207}, | |
| 277 | {"International Org.", 208}, | |
| 278 | {"Nature and Environment Org.", 209}, | |
| 279 | {"Professional Org.", 210}, | |
| 280 | {"Scientific/Technical Org.", 211}, | |
| 281 | {"Self Improvement Group", 212}, | |
| 282 | {"Spiritual/Religious Org.", 213}, | |
| 283 | {"Sports Org.", 214}, | |
| 284 | {"Support Org.", 215}, | |
| 285 | {"Trade and Business Org.", 216}, | |
| 286 | {"Union", 217}, | |
| 287 | {"Voluntary Org.", 218}, | |
| 288 | {"Other", 299}, | |
| 289 | }; | |
| 290 | ||
| 291 | icq_ArrayType icq_MetaLanguages[] = { | |
| 292 | {"Not Entered", 0}, | |
| 293 | {"Arabic", 1}, | |
| 294 | {"Bhojpuri", 2}, | |
| 295 | {"Bulgarian", 3}, | |
| 296 | {"Burmese", 4}, | |
| 297 | {"Cantonese", 5}, | |
| 298 | {"Catalan", 6}, | |
| 299 | {"Chinese", 7}, | |
| 300 | {"Croatian", 8}, | |
| 301 | {"Czech", 9}, | |
| 302 | {"Danish", 10}, | |
| 303 | {"Dutch", 11}, | |
| 304 | {"English", 12}, | |
| 305 | {"Esperanto", 13}, | |
| 306 | {"Estonian", 14}, | |
| 307 | {"Farsi", 15}, | |
| 308 | {"Finnish", 16}, | |
| 309 | {"French", 17}, | |
| 310 | {"Gaelic", 18}, | |
| 311 | {"German", 19}, | |
| 312 | {"Greek", 20}, | |
| 313 | {"Hebrew", 21}, | |
| 314 | {"Hindi", 22}, | |
| 315 | {"Hungarian", 23}, | |
| 316 | {"Icelandic", 24}, | |
| 317 | {"Indonesian", 25}, | |
| 318 | {"Italian", 26}, | |
| 319 | {"Japanese", 27}, | |
| 320 | {"Khmer", 28}, | |
| 321 | {"Korean", 29}, | |
| 322 | {"Lao", 30}, | |
| 323 | {"Latvian", 31}, | |
| 324 | {"Lithuanian", 32}, | |
| 325 | {"Malay", 33}, | |
| 326 | {"Norwegian", 34}, | |
| 327 | {"Polish", 35}, | |
| 328 | {"Portuguese", 36}, | |
| 329 | {"Romanian", 37}, | |
| 330 | {"Russian", 38}, | |
| 331 | {"Serbian", 39}, | |
| 332 | {"Slovak", 40}, | |
| 333 | {"Slovenian", 41}, | |
| 334 | {"Somali", 42}, | |
| 335 | {"Spanish", 43}, | |
| 336 | {"Swahili", 44}, | |
| 337 | {"Swedish", 45}, | |
| 338 | {"Tagalog", 46}, | |
| 339 | {"Tatar", 47}, | |
| 340 | {"Thai", 48}, | |
| 341 | {"Turkish", 49}, | |
| 342 | {"Ukrainian", 50}, | |
| 343 | {"Urdu", 51}, | |
| 344 | {"Vietnamese", 52}, | |
| 345 | {"Yiddish", 53}, | |
| 346 | {"Yoruba", 54}, | |
| 347 | {"Afrikaans", 55}, | |
| 348 | {"Bosnian", 56}, | |
| 349 | {"Persian", 57}, | |
| 350 | {"Albanian", 58}, | |
| 351 | {"Armenian", 59}, | |
| 352 | {"Punjabi", 60}, | |
| 353 | {"Chamorro", 61}, | |
| 354 | {"Mongolian", 62}, | |
| 355 | {"Mandarin", 63}, | |
| 356 | {"Taiwaness", 64}, | |
| 357 | {"Macedonian", 65}, | |
| 358 | {"Sindhi", 66}, | |
| 359 | {"Welsh", 67}, | |
| 360 | }; | |
| 361 | ||
|
1309
dccfec27ffd4
[gaim-migrate @ 1319]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1152
diff
changeset
|
362 | icq_ArrayType icq_Genders[] = { |
|
dccfec27ffd4
[gaim-migrate @ 1319]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1152
diff
changeset
|
363 | {"Not Specified", 0}, |
|
dccfec27ffd4
[gaim-migrate @ 1319]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1152
diff
changeset
|
364 | {"Female", 1}, |
|
dccfec27ffd4
[gaim-migrate @ 1319]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1152
diff
changeset
|
365 | {"Male", 2}, |
|
dccfec27ffd4
[gaim-migrate @ 1319]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1152
diff
changeset
|
366 | }; |
|
dccfec27ffd4
[gaim-migrate @ 1319]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1152
diff
changeset
|
367 | |
| 1152 | 368 | void hex_dump(char *data, long size) |
| 369 | { | |
| 370 | long i; | |
| 371 | long x; | |
| 372 | int r=1; | |
| 373 | char d[32]; | |
| 374 | unsigned char bfr[64]; | |
| 375 | for(i=0, x=0;;i++) | |
| 376 | { | |
| 377 | if(i<size) | |
| 378 | { | |
| 379 | if(x==0) | |
| 380 | printf("%04lx: ", i); | |
| 381 | #ifdef _WIN32 | |
| 382 | sprintf(d, "%08x", data[i]); | |
| 383 | #else | |
| 384 | snprintf(d, 9, "%08x", data[i]); | |
| 385 | #endif | |
| 386 | printf("%c%c ", d[6], d[7]); | |
| 387 | bfr[x]=data[i]; | |
| 388 | if(bfr[x]<0x20) | |
| 389 | bfr[x]='.'; | |
| 390 | if(bfr[x]>0x7f) | |
| 391 | bfr[x]='.'; | |
| 392 | } | |
| 393 | else | |
| 394 | { | |
| 395 | if(x==0) | |
| 396 | break; | |
| 397 | else | |
| 398 | { | |
| 399 | printf(" "); | |
| 400 | bfr[x]=' '; | |
| 401 | r=0; | |
| 402 | } | |
| 403 | } | |
| 404 | x++; | |
| 405 | if(!(x<16)) | |
| 406 | { | |
| 407 | bfr[x]=0; | |
| 408 | printf("%s\n", bfr); | |
| 409 | x=0; | |
| 410 | if(!r) | |
| 411 | break; | |
| 412 | } | |
| 413 | } | |
| 414 | } | |
| 415 | ||
| 416 | /* simple mapping for udp status->tcp status translation function */ | |
| 417 | struct icq_TCPStatusRec | |
| 418 | { | |
| 419 | unsigned long udp_status; | |
| 420 | long tcp_status; | |
| 421 | } icq_TCPStatusMap[] = { | |
| 422 | { STATUS_OFFLINE , 0 }, | |
| 423 | { STATUS_ONLINE , ICQ_TCP_STATUS_ONLINE }, | |
| 424 | { STATUS_INVISIBLE , ICQ_TCP_STATUS_INVISIBLE }, | |
| 425 | { STATUS_NA , ICQ_TCP_STATUS_NA }, | |
| 426 | { STATUS_FREE_CHAT , ICQ_TCP_STATUS_FREE_CHAT }, | |
| 427 | { STATUS_OCCUPIED , ICQ_TCP_STATUS_OCCUPIED }, | |
| 428 | { STATUS_AWAY , ICQ_TCP_STATUS_AWAY }, | |
| 429 | { STATUS_DND , ICQ_TCP_STATUS_DND }, | |
| 430 | }; | |
| 431 | ||
| 432 | long icq_TCPXlateStatus(unsigned long udp_status) | |
| 433 | { | |
| 434 | unsigned int i; | |
| 435 | for(i=0;i<sizeof(icq_TCPStatusMap)/sizeof(struct icq_TCPStatusRec);i++) | |
| 436 | if(icq_TCPStatusMap[i].udp_status==udp_status) | |
| 437 | return icq_TCPStatusMap[i].tcp_status; | |
| 438 | /* warning: "couldn't find tcp status for %d, assuming 0", udp_status */ | |
| 439 | return 0; | |
| 440 | } | |
| 441 | ||
| 442 | void icq_FmtLog(ICQLINK *link, int level, const char *fmt, ...) | |
| 443 | { | |
| 444 | char buffer[2048]; | |
| 445 | va_list ap; | |
| 446 | va_start(ap, fmt); | |
| 447 | ||
| 448 | if(!link) | |
| 449 | return; | |
| 450 | #ifdef _MSVC_ | |
| 451 | _vsnprintf(buffer, 1024, fmt, ap); | |
| 452 | #else | |
| 453 | (void)vsnprintf(buffer, 1024, fmt, ap); | |
| 454 | #endif | |
| 455 | va_end(ap); | |
| 456 | ||
| 457 | if(link->icq_Log && icq_LogLevel>=level) | |
| 458 | (*link->icq_Log)(link, time(0L), level, buffer); | |
| 459 | } | |
| 460 | ||
| 461 | /** | |
| 462 | * Following functions used by qsort and bsearch to | |
| 463 | * compare 2 pointers to icq_ArrayType object. | |
| 464 | */ | |
| 465 | int array_code_compare(const void *x, const void *y) | |
| 466 | { | |
| 467 | return ((icq_ArrayType*)x)->code - ((icq_ArrayType*)y)->code; | |
| 468 | } | |
| 469 | ||
| 470 | const char *icq_GetCountryName(unsigned short code) | |
| 471 | { | |
| 472 | icq_ArrayType *res,key; | |
| 473 | ||
| 474 | key.code=code; | |
| 475 | res=bsearch(&key, icq_Countries, sizeof(icq_Countries)/sizeof(icq_ArrayType), | |
| 476 | sizeof(icq_ArrayType), array_code_compare); | |
| 477 | ||
| 478 | return res?res->name:"Unknown"; | |
| 479 | } | |
| 480 | ||
| 481 | const char *icq_GetMetaOccupationName(unsigned short code) | |
| 482 | { | |
| 483 | icq_ArrayType *res,key; | |
| 484 | ||
| 485 | key.code=code; | |
| 486 | res=bsearch(&key, icq_MetaOccupation, sizeof(icq_MetaOccupation)/sizeof(icq_ArrayType), | |
| 487 | sizeof(icq_ArrayType), array_code_compare); | |
| 488 | ||
| 489 | return res?res->name:"Unknown"; | |
| 490 | } | |
| 491 | ||
| 492 | const char *icq_GetMetaBackgroundName(unsigned short code) | |
| 493 | { | |
| 494 | icq_ArrayType *res,key; | |
| 495 | ||
| 496 | key.code=code; | |
| 497 | res=bsearch(&key, icq_MetaPastBackgrounds, sizeof(icq_MetaPastBackgrounds)/sizeof(icq_ArrayType), | |
| 498 | sizeof(icq_ArrayType), array_code_compare); | |
| 499 | ||
| 500 | return res?res->name:"Unknown"; | |
| 501 | } | |
| 502 | ||
| 503 | const char *icq_GetMetaAffiliationName(unsigned short code) | |
| 504 | { | |
| 505 | icq_ArrayType *res,key; | |
| 506 | ||
| 507 | key.code=code; | |
| 508 | res=bsearch(&key, icq_MetaAffiliations, sizeof(icq_MetaAffiliations)/sizeof(icq_ArrayType), | |
| 509 | sizeof(icq_ArrayType), array_code_compare); | |
| 510 | ||
| 511 | return res?res->name:"Unknown"; | |
| 512 | } | |
| 513 | ||
| 514 | const char *icq_GetMetaLanguageName(unsigned short code) | |
| 515 | { | |
| 516 | icq_ArrayType *res,key; | |
| 517 | ||
| 518 | key.code=code; | |
| 519 | res=bsearch(&key, icq_MetaLanguages, sizeof(icq_MetaLanguages)/sizeof(icq_ArrayType), | |
| 520 | sizeof(icq_ArrayType), array_code_compare); | |
| 521 | ||
| 522 | return res?res->name:"Unknown"; | |
| 523 | } | |
| 524 | ||
| 525 | /******************************************** | |
| 526 | returns a string describing the status or | |
| 527 | a "Error" if no such string exists | |
| 528 | *********************************************/ | |
| 529 | const char *icq_ConvertStatus2Str(unsigned long status) | |
| 530 | { | |
| 531 | if((unsigned long)STATUS_OFFLINE == status) /* this because -1 & 0x01FF is not -1 */ | |
| 532 | return "Offline"; | |
| 533 | ||
| 534 | if((status & STATUS_INVISIBLE) == STATUS_INVISIBLE) | |
| 535 | return "Invisible"; | |
| 536 | else if((status & STATUS_FREE_CHAT) == STATUS_FREE_CHAT) | |
| 537 | return "Free for chat"; | |
| 538 | else if((status & STATUS_DND) == STATUS_DND) | |
| 539 | return "Do not disturb"; | |
| 540 | else if((status & STATUS_OCCUPIED) == STATUS_OCCUPIED) | |
| 541 | return "Occupied"; | |
| 542 | else if((status & STATUS_NA) == STATUS_NA) | |
| 543 | return "Not available"; | |
| 544 | else if((status & STATUS_AWAY) == STATUS_AWAY) | |
| 545 | return "Away"; | |
| 546 | else if(!(status & 0x01FF)) | |
| 547 | return "Online"; | |
| 548 | else | |
| 549 | return "Error"; | |
| 550 | } |