comparison libpurple/util.c @ 25478:f444605c27b6

propagate from branch 'im.pidgin.pidgin' (head a78e36058a13ec01e5cb75f8badbf2585519b0e0) to branch 'im.pidgin.pidgin.yaz' (head e7f401ccaaa979509d744d1fba49075a9b5f0676)
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Thu, 03 May 2007 10:14:49 +0000
parents fd6c3dc4641f
children f35329c1094e
comparison
equal deleted inserted replaced
16818:f7466b0379e8 25478:f444605c27b6
1151 1151
1152 if (check_value != '\0' && *p == check_value) 1152 if (check_value != '\0' && *p == check_value)
1153 return FALSE; 1153 return FALSE;
1154 1154
1155 q = strstr(p, end_token); 1155 q = strstr(p, end_token);
1156 if(q == NULL) //yaz
1157 return FALSE;
1156 1158
1157 /* Trim leading blanks */ 1159 /* Trim leading blanks */
1158 while (*p != '\n' && g_ascii_isspace(*p)) { 1160 while (*p != '\n' && g_ascii_isspace(*p)) {
1159 p += 1; 1161 p += 1;
1160 } 1162 }
1163 while (q > p && g_ascii_isspace(*(q - 1))) { 1165 while (q > p && g_ascii_isspace(*(q - 1))) {
1164 q -= 1; 1166 q -= 1;
1165 } 1167 }
1166 1168
1167 /* Don't bother with null strings */ 1169 /* Don't bother with null strings */
1168 if (p == q) 1170 if (p >= q)
1169 return FALSE; 1171 return FALSE;
1170 1172
1171 if (q != NULL && (!no_value_token || 1173 if (q != NULL && (!no_value_token ||
1172 (no_value_token && strncmp(p, no_value_token, 1174 (no_value_token && strncmp(p, no_value_token,
1173 strlen(no_value_token))))) 1175 strlen(no_value_token)))))
4225 signal(SIGXCPU, SIG_DFL); /* 24: exceeded CPU time limit */ 4227 signal(SIGXCPU, SIG_DFL); /* 24: exceeded CPU time limit */
4226 signal(SIGXFSZ, SIG_DFL); /* 25: exceeded file size limit */ 4228 signal(SIGXFSZ, SIG_DFL); /* 25: exceeded file size limit */
4227 #endif /* HAVE_SIGNAL_H */ 4229 #endif /* HAVE_SIGNAL_H */
4228 #endif /* !_WIN32 */ 4230 #endif /* !_WIN32 */
4229 } 4231 }
4232
4233
4234 void botch_ucs(gchar *ucs, gssize len)
4235 {
4236 gint i;
4237
4238 for(i=0;i<len;i+=2){
4239 switch(*(ucs+i)){
4240 case 0x00:
4241 switch(*(ucs+i+1)){
4242 case 0xa2: // ¢
4243 *(ucs+i) = 0xff;
4244 *(ucs+i+1) = 0xe0;
4245 break;
4246 case 0xa3: // £
4247 *(ucs+i) = 0xff;
4248 *(ucs+i+1) = 0xe1;
4249 break;
4250 case 0xac: // ¬
4251 *(ucs+i) = 0xff;
4252 *(ucs+i+1) = 0xe2;
4253 break;
4254 }
4255 break;
4256 case 0x20: // ‖
4257 if(*(ucs+i+1) == 0x16){
4258 *(ucs+i) = 0x22;
4259 *(ucs+i+1) = 0x25;
4260 }
4261 break;
4262 case 0x22: // −
4263 if(*(ucs+i+1) == 0x12){
4264 *(ucs+i) = 0xff;
4265 *(ucs+i+1) = 0x0d;
4266 }
4267 break;
4268 case 0x30: // 〜
4269 if(*(ucs+i+1) == 0x1c){
4270 *(ucs+i) = 0xff;
4271 *(ucs+i+1) = 0x5e;
4272 }
4273 break;
4274 }
4275 }
4276
4277 }
4278
4279 void sanitize_ucs(gchar *ucs, gssize len)
4280 {
4281 gint i;
4282
4283 for(i=0;i<len;i+=2){
4284 switch(*(ucs+i)){
4285 case 0x22:
4286 switch(*(ucs+i+1)){
4287 case 0x25: // ‖
4288 *(ucs+i) = 0x20;
4289 *(ucs+i+1) = 0x16;
4290 break;
4291 }
4292 break;
4293 case 0xff:
4294 switch(*(ucs+i+1)){
4295 case 0x0d: // −
4296 *(ucs+i) = 0x22;
4297 *(ucs+i+1) = 0x12;
4298 break;
4299 case 0x5e: // 〜
4300 *(ucs+i) = 0x30;
4301 *(ucs+i+1) = 0x1c;
4302 break;
4303 case 0xe0: // ¢
4304 *(ucs+i) = 0x00;
4305 *(ucs+i+1) = 0xa2;
4306 break;
4307 case 0xe1: // £
4308 *(ucs+i) = 0x00;
4309 *(ucs+i+1) = 0xa3;
4310 break;
4311 case 0xe2: // ¬
4312 *(ucs+i) = 0x00;
4313 *(ucs+i+1) = 0xac;
4314 break;
4315 }
4316 break;
4317 }
4318 }
4319 }
4320
4321 guchar *sanitize_utf(unsigned char *msg, size_t len, size_t *newlen)
4322 {
4323 gint i;
4324 size_t bytes;
4325 unsigned char *utf;
4326
4327 utf = g_strndup(msg, len);
4328
4329 bytes = len;
4330
4331 for(i=0;i<len;i++){
4332 switch(*(utf+i)){
4333 case 0xe2:
4334 if(*(utf+i+1) == 0x88) {
4335 if(*(utf+i+2) == 0xa5) { // ‖
4336 *(utf+i) = 0xe2;
4337 *(utf+i+1) = 0x80;
4338 *(utf+i+2) = 0x96;
4339 }
4340 }
4341 break;
4342 case 0xef:
4343 switch(*(utf+i+1)){
4344 case 0xbc:
4345 if(*(utf+i+2) == 0x8d) { // −
4346 *(utf+i) = 0xe2;
4347 *(utf+i+1) = 0x88;
4348 *(utf+i+2) = 0x92;
4349 }
4350 break;
4351 case 0xbd:
4352 if(*(utf+i+2) == 0x9e) { // 〜
4353 *(utf+i) = 0xe3;
4354 *(utf+i+1) = 0x80;
4355 *(utf+i+2) = 0x9c;
4356 }
4357 break;
4358 case 0xbf:
4359 switch(*(utf+i+2)){
4360 case 0xa0:// ¢
4361 *(utf+i) = 0xc2;
4362 *(utf+i+1) = 0xa2;
4363 memmove(utf+i+2, utf+i+3,
4364 len-i-3); //1byte詰める
4365 bytes--;
4366 break;
4367 case 0xa1: // £
4368 *(utf+i) = 0xc2;
4369 *(utf+i+1) = 0xa3;
4370 memmove(utf+i+2, utf+i+3,
4371 len-i-3); //1byte詰める
4372 bytes--;
4373 break;
4374 case 0xa2: // ¬
4375 *(utf+i) = 0xc2;
4376 *(utf+i+1) = 0xac;
4377 memmove(utf+i+2, utf+i+3,
4378 len-i-3); //1byte詰める
4379 bytes--;
4380 break;
4381 }
4382 break;
4383 }
4384 break;
4385 }
4386 }
4387 *(utf+bytes)= 0x00; //terminate
4388 *newlen = bytes;
4389 return utf;
4390 }
4391
4392
4393 guchar *botch_utf(const void *msg, size_t len, size_t *newlen)
4394 {
4395 int i,bytes;
4396 unsigned char *utf;
4397
4398 bytes = len;
4399
4400 utf = g_malloc0(bytes*3/2+1); /* new length might be 3/2 in the worst case */
4401 memcpy(utf, msg, bytes);
4402
4403 for(i=0;i<bytes;i++){
4404 switch(*(utf+i)){
4405 case 0xc2:
4406 switch(*(utf+i+1)){
4407 case 0xa2: // ¢
4408 *(utf+i) = 0xef;
4409 *(utf+i+1) = 0xbf;
4410 memmove(utf+i+3, utf+i+2, bytes-i-2);
4411 *(utf+i+2) = 0xa0;
4412 bytes++;
4413 break;
4414 case 0xa3: // £
4415 *(utf+i) = 0xef;
4416 *(utf+i+1) = 0xbf;
4417 memmove(utf+i+3, utf+i+2, bytes-i-2);
4418 *(utf+i+2) = 0xa1;
4419 bytes++;
4420 break;
4421 case 0xac: // ¬
4422 *(utf+i) = 0xef;
4423 *(utf+i+1) = 0xbf;
4424 memmove(utf+i+3, utf+i+2, bytes-i-2);
4425 *(utf+i+2) = 0xa2;
4426 bytes++;
4427 break;
4428 }
4429 break;
4430 case 0xe2:
4431 switch(*(utf+i+1)){
4432 case 0x80: // ‖
4433 if(*(utf+i+2) == 0x96){
4434 *(utf+i) = 0xe2;
4435 *(utf+i+1) = 0x88;
4436 *(utf+i+2) = 0xa5;
4437 }
4438 break;
4439 case 0x88: // −
4440 if(*(utf+i+1) == 0x92){
4441 *(utf+i) = 0xef;
4442 *(utf+i+1) = 0xbc;
4443 *(utf+i+2) = 0x8d;
4444 }
4445 break;
4446 }
4447 break;
4448 case 0xe3: // 〜
4449 if(*(utf+i+1) == 0x80){
4450 if(*(utf+i+2) == 0x9c){
4451 *(utf+i) = 0xef;
4452 *(utf+i+1) = 0xbd;
4453 *(utf+i+2) = 0x9e;
4454 }
4455 }
4456 break;
4457 } //switch
4458 }
4459 *(utf+bytes) = 0x00; //terminate
4460 *newlen = bytes;
4461 return utf;
4462 }