comparison src/protocols/zephyr/zephyr.c @ 3277:ec20536eaeb0

[gaim-migrate @ 3295] Arun says to do this. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Tue, 28 May 2002 08:40:48 +0000
parents ea6f8d8d74e5
children 8fa61405af2b
comparison
equal deleted inserted replaced
3276:a334dada69c3 3277:ec20536eaeb0
314 } 314 }
315 315
316 static void handle_message(ZNotice_t notice, struct sockaddr_in from) 316 static void handle_message(ZNotice_t notice, struct sockaddr_in from)
317 { 317 {
318 if (!g_strcasecmp(notice.z_class, LOGIN_CLASS)) { 318 if (!g_strcasecmp(notice.z_class, LOGIN_CLASS)) {
319 /* well, we'll be updating in 2 seconds anyway, might as well ignore this. */ 319 /* well, we'll be updating in 20 seconds anyway, might as well ignore this. */
320 } else if (!g_strcasecmp(notice.z_class, LOCATE_CLASS)) { 320 } else if (!g_strcasecmp(notice.z_class, LOCATE_CLASS)) {
321 if (!g_strcasecmp(notice.z_opcode, LOCATE_LOCATE)) { 321 if (!g_strcasecmp(notice.z_opcode, LOCATE_LOCATE)) {
322 int nlocs; 322 int nlocs;
323 char *user; 323 char *user;
324 struct buddy *b; 324 struct buddy *b;
357 free(user); 357 free(user);
358 } 358 }
359 } else { 359 } else {
360 char *buf, *buf2; 360 char *buf, *buf2;
361 char *send_inst; 361 char *send_inst;
362 char *realmptr;
363 char *sendertmp;
362 char *ptr = notice.z_message + strlen(notice.z_message) + 1; 364 char *ptr = notice.z_message + strlen(notice.z_message) + 1;
363 int len = notice.z_message_len - (ptr - notice.z_message); 365 int len = notice.z_message_len - (ptr - notice.z_message);
364 int away; 366 int away;
365 if (len > 0) { 367 if (len > 0) {
366 buf = g_malloc(len + 1); 368 buf = g_malloc(len + 1);
385 } else { 387 } else {
386 if (!zt2->open) { 388 if (!zt2->open) {
387 zt2->open = TRUE; 389 zt2->open = TRUE;
388 serv_got_joined_chat(zgc, zt2->id, zt2->name); 390 serv_got_joined_chat(zgc, zt2->id, zt2->name);
389 } 391 }
390 send_inst = g_strdup_printf("%s %s", notice.z_sender, 392 /* If the person is in the default Realm, then strip the
391 notice.z_class_inst); 393 Realm from the sender field */
394 sendertmp = g_strdup_printf("%s",notice.z_sender);
395 realmptr = strchr(sendertmp,'@');
396 realmptr++;
397 if (!g_strcasecmp(realmptr,ZGetRealm())) {
398 realmptr--;
399 sprintf(realmptr,"%c",'\0');
400 send_inst = g_strdup_printf("%s %s",sendertmp,
401 notice.z_class_inst);
402
403 } else {
404 send_inst = g_strdup_printf("%s %s",notice.z_sender,
405 notice.z_class_inst);
406 }
392 serv_got_chat_in(zgc, zt2->id, send_inst, FALSE, 407 serv_got_chat_in(zgc, zt2->id, send_inst, FALSE,
393 buf2, time(NULL)); 408 buf2, time(NULL));
409 g_free(sendertmp);
394 g_free(send_inst); 410 g_free(send_inst);
395 } 411 }
396 free_triple(zt1); 412 free_triple(zt1);
397 } 413 }
398 g_free(buf2); 414 g_free(buf2);
496 char *recip; 512 char *recip;
497 while (fgets(buff, BUFSIZ, f)) { 513 while (fgets(buff, BUFSIZ, f)) {
498 strip_comments(buff); 514 strip_comments(buff);
499 if (buff[0]) { 515 if (buff[0]) {
500 triple = g_strsplit(buff, ",", 3); 516 triple = g_strsplit(buff, ",", 3);
501 if (triple[0] && triple[1] && triple[2]) { 517 if (triple[0] && triple[1] ) {
502 char *tmp = g_strdup_printf("%s@%s", g_getenv("USER"), 518 char *tmp = g_strdup_printf("%s@%s", g_getenv("USER"),
503 ZGetRealm()); 519 ZGetRealm());
504 char *atptr; 520 char *atptr;
505 sub.zsub_class = triple[0]; 521 sub.zsub_class = triple[0];
506 sub.zsub_classinst = triple[1]; 522 sub.zsub_classinst = triple[1];
507 if (!g_strcasecmp(triple[2], "%me%")) { 523 if(triple[2] == NULL) {
524 recip = g_malloc0(1);
525 } else if (!g_strcasecmp(triple[2], "%me%")) {
508 recip = g_strdup_printf("%s@%s", g_getenv("USER"), 526 recip = g_strdup_printf("%s@%s", g_getenv("USER"),
509 ZGetRealm()); 527 ZGetRealm());
510 } else if (!g_strcasecmp(triple[2], "*")) { 528 } else if (!g_strcasecmp(triple[2], "*")) {
511 /* wildcard 529 /* wildcard
512 * form of class,instance,* */ 530 * form of class,instance,* */
606 GSList *s = subscrips; 624 GSList *s = subscrips;
607 zephyr_triple *zt; 625 zephyr_triple *zt;
608 FILE *fd; 626 FILE *fd;
609 char *fname; 627 char *fname;
610 628
629 char** triple;
611 fname = g_strdup_printf("%s/.zephyr.subs", g_get_home_dir()); 630 fname = g_strdup_printf("%s/.zephyr.subs", g_get_home_dir());
612 fd = fopen(fname, "w"); 631 fd = fopen(fname, "w");
613 632
614 if (!fd) { 633 if (!fd) {
615 g_free(fname); 634 g_free(fname);
616 return; 635 return;
617 } 636 }
618 637
619 while (s) { 638 while (s) {
620 zt = s->data; 639 zt = s->data;
621 fprintf(fd, "%s\n", zt->name); 640 triple = g_strsplit(zt->name,",",3);
641 if (triple[2] != NULL) {
642 if (!g_strcasecmp(triple[2], "")) {
643 fprintf(fd, "%s,%s,*\n", triple[0], triple[1]);
644 } else if (!g_strcasecmp(triple[2], ZGetSender())) {
645 fprintf(fd, "%s,%s,%%me%%\n",triple[0],triple[1]);
646 } else {
647 fprintf(fd, "%s\n", zt->name);
648 }
649 } else {
650 fprintf(fd, "%s,%s,*\n",triple[0], triple[1]);
651 }
652 g_free(triple);
622 s = s->next; 653 s = s->next;
623 } 654 }
624 g_free(fname); 655 g_free(fname);
625 fclose(fd); 656 fclose(fd);
626 } 657 }
628 static void write_anyone() 659 static void write_anyone()
629 { 660 {
630 GSList *gr, *m; 661 GSList *gr, *m;
631 struct group *g; 662 struct group *g;
632 struct buddy *b; 663 struct buddy *b;
633 char *ptr, *fname; 664 char *ptr, *fname, *ptr2;
634 FILE *fd; 665 FILE *fd;
635 666
636 fname = g_strdup_printf("%s/.anyone", g_get_home_dir()); 667 fname = g_strdup_printf("%s/.anyone", g_get_home_dir());
637 fd = fopen(fname, "w"); 668 fd = fopen(fname, "w");
638 if (!fd) { 669 if (!fd) {
644 while (gr) { 675 while (gr) {
645 g = gr->data; 676 g = gr->data;
646 m = g->members; 677 m = g->members;
647 while (m) { 678 while (m) {
648 b = m->data; 679 b = m->data;
649 if ((ptr = strchr(b->name, '@')) != NULL) 680 if ((ptr = strchr(b->name, '@')) != NULL) {
650 *ptr = '\0'; 681 ptr2 = ptr + 1;
682 /* We should only strip the realm name if the principal
683 is in the user's realm
684 */
685 if (!g_strcasecmp(ptr2,ZGetRealm())) {
686 *ptr = '\0';
687 }
688 }
651 fprintf(fd, "%s\n", b->name); 689 fprintf(fd, "%s\n", b->name);
652 if (ptr) 690 if (ptr)
653 *ptr = '@'; 691 *ptr = '@';
654 m = m->next; 692 m = m->next;
655 } 693 }