Mercurial > pidgin.yaz
comparison libpurple/protocols/zephyr/zephyr.c @ 25362:65cfc59858cf
propagate from branch 'im.pidgin.pidgin' (head d5bb29138cbe033bbfd8ec689203d73818765327)
to branch 'im.pidgin.pidgin.next.minor' (head 35ee8e40db640867e5b9239030cdc326e7f0a005)
author | Gary Kramlich <grim@reaperworld.com> |
---|---|
date | Sat, 13 Dec 2008 05:45:27 +0000 |
parents | 9bdd3ab8087f d8452c0bec7b |
children |
comparison
equal
deleted
inserted
replaced
25361:d9da15c9e2a1 | 25362:65cfc59858cf |
---|---|
62 | 62 |
63 typedef enum { | 63 typedef enum { |
64 PURPLE_ZEPHYR_NONE, /* Non-kerberized ZEPH0.2 */ | 64 PURPLE_ZEPHYR_NONE, /* Non-kerberized ZEPH0.2 */ |
65 PURPLE_ZEPHYR_KRB4, /* ZEPH0.2 w/ KRB4 support */ | 65 PURPLE_ZEPHYR_KRB4, /* ZEPH0.2 w/ KRB4 support */ |
66 PURPLE_ZEPHYR_TZC, /* tzc executable proxy */ | 66 PURPLE_ZEPHYR_TZC, /* tzc executable proxy */ |
67 PURPLE_ZEPHYR_INTERGALACTIC_KRB4, /* Kerberized ZEPH0.3 */ | 67 PURPLE_ZEPHYR_INTERGALACTIC_KRB4 /* Kerberized ZEPH0.3 */ |
68 } zephyr_connection_type; | 68 } zephyr_connection_type; |
69 | 69 |
70 struct _zephyr_account { | 70 struct _zephyr_account { |
71 PurpleAccount* account; | 71 PurpleAccount* account; |
72 char *username; | 72 char *username; |
1628 if (pid == 0) { | 1628 if (pid == 0) { |
1629 unsigned int i=0; | 1629 unsigned int i=0; |
1630 gboolean found_ps = FALSE; | 1630 gboolean found_ps = FALSE; |
1631 gchar ** tzc_cmd_array = g_strsplit(purple_account_get_string(gc->account,"tzc_command","/usr/bin/tzc -e %s")," ",0); | 1631 gchar ** tzc_cmd_array = g_strsplit(purple_account_get_string(gc->account,"tzc_command","/usr/bin/tzc -e %s")," ",0); |
1632 if (close(1) == -1) { | 1632 if (close(1) == -1) { |
1633 purple_debug_error("zephyr", "stdout couldn't be closed. dying\n"); | |
1634 exit(-1); | 1633 exit(-1); |
1635 } | 1634 } |
1636 if (dup2(zephyr->fromtzc[1], 1) == -1) { | 1635 if (dup2(zephyr->fromtzc[1], 1) == -1) { |
1637 purple_debug_error("zephyr", "dup2 of stdout failed \n"); | |
1638 exit(-1); | 1636 exit(-1); |
1639 } | 1637 } |
1640 if (close(zephyr->fromtzc[1]) == -1) { | 1638 if (close(zephyr->fromtzc[1]) == -1) { |
1641 purple_debug_error("zephyr", "closing of piped stdout failed\n"); | |
1642 exit(-1); | 1639 exit(-1); |
1643 } | 1640 } |
1644 if (close(0) == -1) { | 1641 if (close(0) == -1) { |
1645 purple_debug_error("zephyr", "stdin couldn't be closed. dying\n"); | |
1646 exit(-1); | 1642 exit(-1); |
1647 } | 1643 } |
1648 if (dup2(zephyr->totzc[0], 0) == -1) { | 1644 if (dup2(zephyr->totzc[0], 0) == -1) { |
1649 purple_debug_error("zephyr", "dup2 of stdin failed \n"); | |
1650 exit(-1); | 1645 exit(-1); |
1651 } | 1646 } |
1652 if (close(zephyr->totzc[0]) == -1) { | 1647 if (close(zephyr->totzc[0]) == -1) { |
1653 purple_debug_error("zephyr", "closing of piped stdin failed\n"); | |
1654 exit(-1); | 1648 exit(-1); |
1655 } | 1649 } |
1656 /* tzc_command should really be of the form | 1650 /* tzc_command should really be of the form |
1657 path/to/tzc -e %s | 1651 path/to/tzc -e %s |
1658 or | 1652 or |
1672 } | 1666 } |
1673 i++; | 1667 i++; |
1674 } | 1668 } |
1675 | 1669 |
1676 if (!found_ps) { | 1670 if (!found_ps) { |
1677 purple_connection_error(gc,"Tzc command needs %s to set the exposure\n"); | 1671 exit(-1); |
1678 return; | |
1679 } | 1672 } |
1680 | 1673 |
1681 execvp(tzc_cmd_array[0], tzc_cmd_array); | 1674 execvp(tzc_cmd_array[0], tzc_cmd_array); |
1675 exit(-1); | |
1682 } | 1676 } |
1683 else { | 1677 else { |
1684 fd_set rfds; | 1678 fd_set rfds; |
1685 int bufsize = 2048; | 1679 int bufsize = 2048; |
1686 char *buf = (char *)calloc(bufsize, 1); | 1680 char *buf = (char *)calloc(bufsize, 1); |
1688 struct timeval tv; | 1682 struct timeval tv; |
1689 char *ptr; | 1683 char *ptr; |
1690 int parenlevel=0; | 1684 int parenlevel=0; |
1691 char* tempstr; | 1685 char* tempstr; |
1692 int tempstridx; | 1686 int tempstridx; |
1687 int select_status; | |
1693 | 1688 |
1694 zephyr->tzc_pid = pid; | 1689 zephyr->tzc_pid = pid; |
1695 /* wait till we have data to read from ssh */ | 1690 /* wait till we have data to read from ssh */ |
1696 FD_ZERO(&rfds); | 1691 FD_ZERO(&rfds); |
1697 FD_SET(zephyr->fromtzc[ZEPHYR_FD_READ], &rfds); | 1692 FD_SET(zephyr->fromtzc[ZEPHYR_FD_READ], &rfds); |
1699 tv.tv_sec = 10; | 1694 tv.tv_sec = 10; |
1700 tv.tv_usec = 0; | 1695 tv.tv_usec = 0; |
1701 | 1696 |
1702 purple_debug_info("zephyr", "about to read from tzc\n"); | 1697 purple_debug_info("zephyr", "about to read from tzc\n"); |
1703 | 1698 |
1704 select(zephyr->fromtzc[ZEPHYR_FD_READ] + 1, &rfds, NULL, NULL, NULL); | 1699 if (waitpid(pid, NULL, WNOHANG) == 0) { /* Only select if tzc is still running */ |
1700 purple_debug_info("zephyr", "about to read from tzc\n"); | |
1701 select_status = select(zephyr->fromtzc[ZEPHYR_FD_READ] + 1, &rfds, NULL, NULL, NULL); | |
1702 } | |
1703 else { | |
1704 purple_debug_info("zephyr", "tzc exited early\n"); | |
1705 select_status = -1; | |
1706 } | |
1705 | 1707 |
1706 FD_ZERO(&rfds); | 1708 FD_ZERO(&rfds); |
1707 FD_SET(zephyr->fromtzc[ZEPHYR_FD_READ], &rfds); | 1709 FD_SET(zephyr->fromtzc[ZEPHYR_FD_READ], &rfds); |
1708 while (select(zephyr->fromtzc[ZEPHYR_FD_READ] + 1, &rfds, NULL, NULL, &tv)) { | 1710 while (select_status > 0 && |
1711 select(zephyr->fromtzc[ZEPHYR_FD_READ] + 1, &rfds, NULL, NULL, &tv) > 0) { | |
1709 read(zephyr->fromtzc[ZEPHYR_FD_READ], bufcur, 1); | 1712 read(zephyr->fromtzc[ZEPHYR_FD_READ], bufcur, 1); |
1710 bufcur++; | 1713 bufcur++; |
1711 if ((bufcur - buf) > (bufsize - 1)) { | 1714 if ((bufcur - buf) > (bufsize - 1)) { |
1712 if ((buf = realloc(buf, bufsize * 2)) == NULL) { | 1715 if ((buf = realloc(buf, bufsize * 2)) == NULL) { |
1713 exit(-1); | 1716 exit(-1); |