comparison libpurple/util.c @ 25500:24d035ad12cd

propagate from branch 'im.pidgin.pidgin' (head cf74b964fddd2185233987f6e7743623bf21efb8) to branch 'im.pidgin.pidgin.yaz' (head e611312336fc5f025cfd6ef561ee9318827cae80)
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Thu, 07 Jun 2007 07:32:06 +0000
parents 647bfc2b2a7b 67ad619bd97f
children ff69c2a9ccf2
comparison
equal deleted inserted replaced
17772:a8d6f071eb6d 25500:24d035ad12cd
1152 1152
1153 if (check_value != '\0' && *p == check_value) 1153 if (check_value != '\0' && *p == check_value)
1154 return FALSE; 1154 return FALSE;
1155 1155
1156 q = strstr(p, end_token); 1156 q = strstr(p, end_token);
1157 if(q == NULL) //yaz
1158 return FALSE;
1157 1159
1158 /* Trim leading blanks */ 1160 /* Trim leading blanks */
1159 while (*p != '\n' && g_ascii_isspace(*p)) { 1161 while (*p != '\n' && g_ascii_isspace(*p)) {
1160 p += 1; 1162 p += 1;
1161 } 1163 }
1164 while (q > p && g_ascii_isspace(*(q - 1))) { 1166 while (q > p && g_ascii_isspace(*(q - 1))) {
1165 q -= 1; 1167 q -= 1;
1166 } 1168 }
1167 1169
1168 /* Don't bother with null strings */ 1170 /* Don't bother with null strings */
1169 if (p == q) 1171 if (p >= q)
1170 return FALSE; 1172 return FALSE;
1171 1173
1172 if (q != NULL && (!no_value_token || 1174 if (q != NULL && (!no_value_token ||
1173 (no_value_token && strncmp(p, no_value_token, 1175 (no_value_token && strncmp(p, no_value_token,
1174 strlen(no_value_token))))) 1176 strlen(no_value_token)))))
4333 signal(SIGXCPU, SIG_DFL); /* 24: exceeded CPU time limit */ 4335 signal(SIGXCPU, SIG_DFL); /* 24: exceeded CPU time limit */
4334 signal(SIGXFSZ, SIG_DFL); /* 25: exceeded file size limit */ 4336 signal(SIGXFSZ, SIG_DFL); /* 25: exceeded file size limit */
4335 #endif /* HAVE_SIGNAL_H */ 4337 #endif /* HAVE_SIGNAL_H */
4336 #endif /* !_WIN32 */ 4338 #endif /* !_WIN32 */
4337 } 4339 }
4340
4341
4342 void botch_ucs(gchar *ucs, gssize len)
4343 {
4344 gint i;
4345
4346 for(i=0;i<len;i+=2){
4347 switch(*(ucs+i)){
4348 case 0x00:
4349 switch(*(ucs+i+1)){
4350 case 0xa2: // ¢
4351 *(ucs+i) = 0xff;
4352 *(ucs+i+1) = 0xe0;
4353 break;
4354 case 0xa3: // £
4355 *(ucs+i) = 0xff;
4356 *(ucs+i+1) = 0xe1;
4357 break;
4358 case 0xac: // ¬
4359 *(ucs+i) = 0xff;
4360 *(ucs+i+1) = 0xe2;
4361 break;
4362 }
4363 break;
4364 case 0x20: // ‖
4365 if(*(ucs+i+1) == 0x16){
4366 *(ucs+i) = 0x22;
4367 *(ucs+i+1) = 0x25;
4368 }
4369 break;
4370 case 0x22: // −
4371 if(*(ucs+i+1) == 0x12){
4372 *(ucs+i) = 0xff;
4373 *(ucs+i+1) = 0x0d;
4374 }
4375 break;
4376 case 0x30: // 〜
4377 if(*(ucs+i+1) == 0x1c){
4378 *(ucs+i) = 0xff;
4379 *(ucs+i+1) = 0x5e;
4380 }
4381 break;
4382 }
4383 }
4384
4385 }
4386
4387 void sanitize_ucs(gchar *ucs, gssize len)
4388 {
4389 gint i;
4390
4391 for(i=0;i<len;i+=2){
4392 switch(*(ucs+i)){
4393 case 0x22:
4394 switch(*(ucs+i+1)){
4395 case 0x25: // ‖
4396 *(ucs+i) = 0x20;
4397 *(ucs+i+1) = 0x16;
4398 break;
4399 }
4400 break;
4401 case 0xff:
4402 switch(*(ucs+i+1)){
4403 case 0x0d: // −
4404 *(ucs+i) = 0x22;
4405 *(ucs+i+1) = 0x12;
4406 break;
4407 case 0x5e: // 〜
4408 *(ucs+i) = 0x30;
4409 *(ucs+i+1) = 0x1c;
4410 break;
4411 case 0xe0: // ¢
4412 *(ucs+i) = 0x00;
4413 *(ucs+i+1) = 0xa2;
4414 break;
4415 case 0xe1: // £
4416 *(ucs+i) = 0x00;
4417 *(ucs+i+1) = 0xa3;
4418 break;
4419 case 0xe2: // ¬
4420 *(ucs+i) = 0x00;
4421 *(ucs+i+1) = 0xac;
4422 break;
4423 }
4424 break;
4425 }
4426 }
4427 }
4428
4429 guchar *sanitize_utf(unsigned char *msg, size_t len, size_t *newlen)
4430 {
4431 gint i;
4432 size_t bytes;
4433 unsigned char *utf;
4434
4435 utf = g_strndup(msg, len);
4436
4437 bytes = len;
4438
4439 for(i=0;i<len;i++){
4440 switch(*(utf+i)){
4441 case 0xe2:
4442 if(*(utf+i+1) == 0x88) {
4443 if(*(utf+i+2) == 0xa5) { // ‖
4444 *(utf+i) = 0xe2;
4445 *(utf+i+1) = 0x80;
4446 *(utf+i+2) = 0x96;
4447 }
4448 }
4449 break;
4450 case 0xef:
4451 switch(*(utf+i+1)){
4452 case 0xbc:
4453 if(*(utf+i+2) == 0x8d) { // −
4454 *(utf+i) = 0xe2;
4455 *(utf+i+1) = 0x88;
4456 *(utf+i+2) = 0x92;
4457 }
4458 break;
4459 case 0xbd:
4460 if(*(utf+i+2) == 0x9e) { // 〜
4461 *(utf+i) = 0xe3;
4462 *(utf+i+1) = 0x80;
4463 *(utf+i+2) = 0x9c;
4464 }
4465 break;
4466 case 0xbf:
4467 switch(*(utf+i+2)){
4468 case 0xa0:// ¢
4469 *(utf+i) = 0xc2;
4470 *(utf+i+1) = 0xa2;
4471 memmove(utf+i+2, utf+i+3,
4472 len-i-3); //1byte詰める
4473 bytes--;
4474 break;
4475 case 0xa1: // £
4476 *(utf+i) = 0xc2;
4477 *(utf+i+1) = 0xa3;
4478 memmove(utf+i+2, utf+i+3,
4479 len-i-3); //1byte詰める
4480 bytes--;
4481 break;
4482 case 0xa2: // ¬
4483 *(utf+i) = 0xc2;
4484 *(utf+i+1) = 0xac;
4485 memmove(utf+i+2, utf+i+3,
4486 len-i-3); //1byte詰める
4487 bytes--;
4488 break;
4489 }
4490 break;
4491 }
4492 break;
4493 }
4494 }
4495 *(utf+bytes)= 0x00; //terminate
4496 *newlen = bytes;
4497 return utf;
4498 }
4499
4500
4501 guchar *botch_utf(const void *msg, size_t len, size_t *newlen)
4502 {
4503 int i,bytes;
4504 unsigned char *utf;
4505
4506 bytes = len;
4507
4508 utf = g_malloc0(bytes*3/2+1); /* new length might be 3/2 in the worst case */
4509 memcpy(utf, msg, bytes);
4510
4511 for(i=0;i<bytes;i++){
4512 switch(*(utf+i)){
4513 case 0xc2:
4514 switch(*(utf+i+1)){
4515 case 0xa2: // ¢
4516 *(utf+i) = 0xef;
4517 *(utf+i+1) = 0xbf;
4518 memmove(utf+i+3, utf+i+2, bytes-i-2);
4519 *(utf+i+2) = 0xa0;
4520 bytes++;
4521 break;
4522 case 0xa3: // £
4523 *(utf+i) = 0xef;
4524 *(utf+i+1) = 0xbf;
4525 memmove(utf+i+3, utf+i+2, bytes-i-2);
4526 *(utf+i+2) = 0xa1;
4527 bytes++;
4528 break;
4529 case 0xac: // ¬
4530 *(utf+i) = 0xef;
4531 *(utf+i+1) = 0xbf;
4532 memmove(utf+i+3, utf+i+2, bytes-i-2);
4533 *(utf+i+2) = 0xa2;
4534 bytes++;
4535 break;
4536 }
4537 break;
4538 case 0xe2:
4539 switch(*(utf+i+1)){
4540 case 0x80: // ‖
4541 if(*(utf+i+2) == 0x96){
4542 *(utf+i) = 0xe2;
4543 *(utf+i+1) = 0x88;
4544 *(utf+i+2) = 0xa5;
4545 }
4546 break;
4547 case 0x88: // −
4548 if(*(utf+i+1) == 0x92){
4549 *(utf+i) = 0xef;
4550 *(utf+i+1) = 0xbc;
4551 *(utf+i+2) = 0x8d;
4552 }
4553 break;
4554 }
4555 break;
4556 case 0xe3: // 〜
4557 if(*(utf+i+1) == 0x80){
4558 if(*(utf+i+2) == 0x9c){
4559 *(utf+i) = 0xef;
4560 *(utf+i+1) = 0xbd;
4561 *(utf+i+2) = 0x9e;
4562 }
4563 }
4564 break;
4565 } //switch
4566 }
4567 *(utf+bytes) = 0x00; //terminate
4568 *newlen = bytes;
4569 return utf;
4570 }