comparison plugins/yay/libyahoo.c @ 1409:17e544f8c7fb

[gaim-migrate @ 1419] no more hanging trees. also libyahoo updates. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Tue, 16 Jan 2001 02:02:32 +0000
parents b167222b5c93
children
comparison
equal deleted inserted replaced
1408:815e3000467e 1409:17e544f8c7fb
267 converts a comma seperated list to an array of strings 267 converts a comma seperated list to an array of strings
268 used primarily in conference code 268 used primarily in conference code
269 269
270 allocates a string in here -- caller needs to free it 270 allocates a string in here -- caller needs to free it
271 */ 271 */
272 char **yahoo_list2array(char *buff) 272 char **yahoo_list2array(const char *buff)
273 { 273 {
274 char **tmp_array = NULL; 274 char **tmp_array = NULL;
275 char *array_elem = NULL; 275 char *array_elem = NULL;
276 char *tmp = NULL; 276 char *tmp = NULL;
277 277
478 FREE(ctx->identities); 478 FREE(ctx->identities);
479 yahoo_dbg_Print("libyahoo", "[libyahoo] yahoo_free_identities: done\n"); 479 yahoo_dbg_Print("libyahoo", "[libyahoo] yahoo_free_identities: done\n");
480 } 480 }
481 481
482 #if 0 /* not used at the moment */ 482 #if 0 /* not used at the moment */
483 static void yahoo_hexdump(char *label, unsigned char *data, int datalen) 483 static void yahoo_hexdump(const char *label, const unsigned char *data, int datalen)
484 { 484 {
485 int i, j; 485 int i, j;
486 int val, skipped_last; 486 int val, skipped_last;
487 char current[100]; 487 char current[100];
488 char last[100]; 488 char last[100];
580 } 580 }
581 printf("\n"); 581 printf("\n");
582 } 582 }
583 #endif 583 #endif
584 584
585 static int yahoo_socket_connect(struct yahoo_context *ctx, char *host, 585 static int yahoo_socket_connect(struct yahoo_context *ctx, const char *host,
586 int port) 586 int port)
587 { 587 {
588 struct sockaddr_in serv_addr; 588 struct sockaddr_in serv_addr;
589 struct hostent *server; 589 struct hostent *server;
590 int servfd; 590 int servfd;
672 * -- Hrishikesh Desai <hrishi@mediaibc.com> 672 * -- Hrishikesh Desai <hrishi@mediaibc.com>
673 * 673 *
674 */ 674 */
675 675
676 676
677 static char *yahoo_urlencode(char *instr) 677 static char *yahoo_urlencode(const char *instr)
678 { 678 {
679 register int ipos, bpos; //input str pos., buffer pos. 679 register int ipos, bpos; //input str pos., buffer pos.
680 static unsigned char *str=NULL; 680 static unsigned char *str=NULL;
681 int len=strlen(instr); 681 int len=strlen(instr);
682 int tmp; 682 int tmp;
726 726
727 return ( str); 727 return ( str);
728 } 728 }
729 729
730 730
731 static int yahoo_addtobuffer(struct yahoo_context *ctx, char *data, 731 static int yahoo_addtobuffer(struct yahoo_context *ctx, const char *data,
732 int datalen) 732 int datalen)
733 { 733 {
734 //yahoo_hexdump("yahoo_addtobuffer", data, datalen); 734 //yahoo_hexdump("yahoo_addtobuffer", data, datalen);
735 735
736 /* Check buffer, increase size if necessary */ 736 /* Check buffer, increase size if necessary */
805 * Published library interfaces 805 * Published library interfaces
806 */ 806 */
807 807
808 /* Initialize interface to yahoo library, sortof like a class object 808 /* Initialize interface to yahoo library, sortof like a class object
809 creation routine. */ 809 creation routine. */
810 struct yahoo_context *yahoo_init(char *user, char *password, 810 struct yahoo_context *yahoo_init(const char *user, const char *password,
811 struct yahoo_options *options) 811 struct yahoo_options *options)
812 { 812 {
813 struct yahoo_context *tmp; 813 struct yahoo_context *tmp;
814 814
815 if (!user || !password) 815 if (!user || !password)
1068 1068
1069 return 1; 1069 return 1;
1070 } 1070 }
1071 1071
1072 /* Add a buddy to your buddy list */ 1072 /* Add a buddy to your buddy list */
1073 int yahoo_add_buddy(struct yahoo_context *ctx, char *addid, 1073 int yahoo_add_buddy(struct yahoo_context *ctx, const char *addid,
1074 char *active_id, char *group, char *msg) 1074 const char *active_id, const char *group, const char *msg)
1075 { 1075 {
1076 char buffer[5000]; 1076 char buffer[5000];
1077 int servfd; 1077 int servfd;
1078 1078
1079 if (!ctx) 1079 if (!ctx)
1141 yahoo_dbg_Print("libyahoo", "[libyahoo] yahoo_add_buddy: finished\n"); 1141 yahoo_dbg_Print("libyahoo", "[libyahoo] yahoo_add_buddy: finished\n");
1142 return 1; 1142 return 1;
1143 } 1143 }
1144 1144
1145 /* Remove a buddy from your buddy list */ 1145 /* Remove a buddy from your buddy list */
1146 int yahoo_remove_buddy(struct yahoo_context *ctx, char *addid, 1146 int yahoo_remove_buddy(struct yahoo_context *ctx, const char *addid,
1147 char *active_id, char *group, char *msg) 1147 const char *active_id, const char *group, const char *msg)
1148 { 1148 {
1149 char buffer[5000]; 1149 char buffer[5000];
1150 int servfd; 1150 int servfd;
1151 1151
1152 if (!ctx) 1152 if (!ctx)
1619 return (1); 1619 return (1);
1620 } 1620 }
1621 1621
1622 /* Send a packet to the server, called by all routines that want to issue 1622 /* Send a packet to the server, called by all routines that want to issue
1623 a command. */ 1623 a command. */
1624 int yahoo_sendcmd(struct yahoo_context *ctx, int service, char *active_nick, 1624 int yahoo_sendcmd(struct yahoo_context *ctx, int service, const char *active_nick,
1625 char *content, unsigned int msgtype) 1625 const char *content, unsigned int msgtype)
1626 { 1626 {
1627 int size; 1627 int size;
1628 struct yahoo_rawpacket *pkt; 1628 struct yahoo_rawpacket *pkt;
1629 int maxcontentsize; 1629 int maxcontentsize;
1630 1630
1689 int yahoo_cmd_idle(struct yahoo_context *ctx) 1689 int yahoo_cmd_idle(struct yahoo_context *ctx)
1690 { 1690 {
1691 return yahoo_sendcmd(ctx, YAHOO_SERVICE_IDLE, ctx->user, "", 0); 1691 return yahoo_sendcmd(ctx, YAHOO_SERVICE_IDLE, ctx->user, "", 0);
1692 } 1692 }
1693 1693
1694 int yahoo_cmd_sendfile(struct yahoo_context *ctx, char *active_user, 1694 int yahoo_cmd_sendfile(struct yahoo_context *ctx, const char *active_user,
1695 char *touser, char *msg, char *filename) 1695 const char *touser, const char *msg, const char *filename)
1696 { 1696 {
1697 yahoo_dbg_Print("libyahoo", "yahoo_cmd_sendfile not implemented yet!"); 1697 yahoo_dbg_Print("libyahoo", "yahoo_cmd_sendfile not implemented yet!");
1698 return (0); 1698 return (0);
1699 } 1699 }
1700 1700
1701 int yahoo_cmd_msg(struct yahoo_context *ctx, char *active_user, 1701 int yahoo_cmd_msg(struct yahoo_context *ctx, const char *active_user,
1702 char *touser, char *msg) 1702 const char *touser, const char *msg)
1703 { 1703 {
1704 char *content; 1704 char *content;
1705 1705
1706 if (!(content = (char *) malloc(strlen(touser) + strlen(msg) + 5))) 1706 if (!(content = (char *) malloc(strlen(touser) + strlen(msg) + 5)))
1707 return 0; 1707 return 0;
1718 1718
1719 FREE(content); 1719 FREE(content);
1720 return (1); 1720 return (1);
1721 } 1721 }
1722 1722
1723 int yahoo_cmd_msg_offline(struct yahoo_context *ctx, char *active_user, 1723 int yahoo_cmd_msg_offline(struct yahoo_context *ctx, const char *active_user,
1724 char *touser, char *msg) 1724 const char *touser, const char *msg)
1725 { 1725 {
1726 char *content; 1726 char *content;
1727 1727
1728 if (!(content = (char *) malloc(strlen(touser) + strlen(msg) + 5))) 1728 if (!(content = (char *) malloc(strlen(touser) + strlen(msg) + 5)))
1729 return 0; 1729 return 0;
1742 FREE(content); 1742 FREE(content);
1743 return (1); 1743 return (1);
1744 } 1744 }
1745 1745
1746 /* appended the " " so that won't trigger yahoo bug - hack for the moment */ 1746 /* appended the " " so that won't trigger yahoo bug - hack for the moment */
1747 int yahoo_cmd_set_away_mode(struct yahoo_context *ctx, int status, char *msg) 1747 int yahoo_cmd_set_away_mode(struct yahoo_context *ctx, int status, const char *msg)
1748 { 1748 {
1749 char statusstring[500]; 1749 char statusstring[500];
1750 1750
1751 yahoo_dbg_Print("libyahoo", 1751 yahoo_dbg_Print("libyahoo",
1752 "[libyahoo] yahoo_cmd_set_away_mode: set status (%d), msg(%s)\n", 1752 "[libyahoo] yahoo_cmd_set_away_mode: set status (%d), msg(%s)\n",
1768 snprintf(statusstring, 500, "%d", status); 1768 snprintf(statusstring, 500, "%d", status);
1769 } 1769 }
1770 return yahoo_sendcmd(ctx, YAHOO_SERVICE_ISAWAY, ctx->user, statusstring, 0); 1770 return yahoo_sendcmd(ctx, YAHOO_SERVICE_ISAWAY, ctx->user, statusstring, 0);
1771 } 1771 }
1772 1772
1773 int yahoo_cmd_set_back_mode(struct yahoo_context *ctx, int status, char *msg) 1773 int yahoo_cmd_set_back_mode(struct yahoo_context *ctx, int status, const char *msg)
1774 { 1774 {
1775 char statusstring[500]; 1775 char statusstring[500];
1776 1776
1777 yahoo_dbg_Print("libyahoo", 1777 yahoo_dbg_Print("libyahoo",
1778 "[libyahoo] yahoo_cmd_set_back_mode: set status (%d), msg(%s)\n", 1778 "[libyahoo] yahoo_cmd_set_back_mode: set status (%d), msg(%s)\n",
1780 1780
1781 snprintf(statusstring, 500, "%d%c%s ", status, 1, msg ? msg : ""); 1781 snprintf(statusstring, 500, "%d%c%s ", status, 1, msg ? msg : "");
1782 return yahoo_sendcmd(ctx, YAHOO_SERVICE_ISBACK, ctx->user, statusstring, 0); 1782 return yahoo_sendcmd(ctx, YAHOO_SERVICE_ISBACK, ctx->user, statusstring, 0);
1783 } 1783 }
1784 1784
1785 int yahoo_cmd_activate_id(struct yahoo_context *ctx, char *newid) 1785 int yahoo_cmd_activate_id(struct yahoo_context *ctx, const char *newid)
1786 { 1786 {
1787 if (strlen(newid)) 1787 if (strlen(newid))
1788 return yahoo_sendcmd(ctx, YAHOO_SERVICE_IDACT, newid, newid, 0); 1788 return yahoo_sendcmd(ctx, YAHOO_SERVICE_IDACT, newid, newid, 0);
1789 return 0; 1789 return 0;
1790 } 1790 }
1815 int type == 0 - normal, 1 - voice (not supported yet) 1815 int type == 0 - normal, 1 - voice (not supported yet)
1816 1816
1817 Packet format: 1817 Packet format:
1818 id^invited-users^msg^0or1 1818 id^invited-users^msg^0or1
1819 */ 1819 */
1820 int yahoo_cmd_start_conf(struct yahoo_context *ctx, char *conf_id, 1820 int yahoo_cmd_start_conf(struct yahoo_context *ctx, const char *conf_id,
1821 char **userlist, char *msg, int type) 1821 char **userlist, const char *msg, int type)
1822 { 1822 {
1823 char ctrlb = 2; 1823 char ctrlb = 2;
1824 char *content; 1824 char *content;
1825 char *new_userlist = yahoo_array2list(userlist); 1825 char *new_userlist = yahoo_array2list(userlist);
1826 int cont_len = 0; 1826 int cont_len = 0;
1875 1875
1876 Packet format: 1876 Packet format:
1877 id^all-invited-users-and-host 1877 id^all-invited-users-and-host
1878 1878
1879 */ 1879 */
1880 int yahoo_cmd_conf_logon(struct yahoo_context *ctx, char *conf_id, 1880 int yahoo_cmd_conf_logon(struct yahoo_context *ctx, const char *conf_id,
1881 char *host, char **userlist) 1881 const char *host, char **userlist)
1882 { 1882 {
1883 char ctrlb = 2; 1883 char ctrlb = 2;
1884 char *content; 1884 char *content;
1885 char *new_userlist = yahoo_array2list(userlist); 1885 char *new_userlist = yahoo_array2list(userlist);
1886 int cont_len = 0; 1886 int cont_len = 0;
1936 1936
1937 Packet format: 1937 Packet format:
1938 id^all-invited-users-and-host^msg 1938 id^all-invited-users-and-host^msg
1939 1939
1940 */ 1940 */
1941 int yahoo_cmd_decline_conf(struct yahoo_context *ctx, char *conf_id, 1941 int yahoo_cmd_decline_conf(struct yahoo_context *ctx, const char *conf_id,
1942 char *host, char **userlist, char *msg) 1942 const char *host, char **userlist, const char *msg)
1943 { 1943 {
1944 char ctrlb = 2; 1944 char ctrlb = 2;
1945 char *content; 1945 char *content;
1946 char *new_userlist = yahoo_array2list(userlist); 1946 char *new_userlist = yahoo_array2list(userlist);
1947 1947
1986 Packet format: 1986 Packet format:
1987 id^all-invited-users 1987 id^all-invited-users
1988 1988
1989 */ 1989 */
1990 1990
1991 int yahoo_cmd_conf_logoff(struct yahoo_context *ctx, char *conf_id, 1991 int yahoo_cmd_conf_logoff(struct yahoo_context *ctx, const char *conf_id,
1992 char **userlist) 1992 char **userlist)
1993 { 1993 {
1994 char ctrlb = 2; 1994 char ctrlb = 2;
1995 char *content; 1995 char *content;
1996 int cont_len = 0; 1996 int cont_len = 0;
2046 Packet format: 2046 Packet format:
2047 id^invited-user^who-else-in-conf^who-else-in-conf^msg^0 2047 id^invited-user^who-else-in-conf^who-else-in-conf^msg^0
2048 2048
2049 */ 2049 */
2050 2050
2051 int yahoo_cmd_conf_invite(struct yahoo_context *ctx, char *conf_id, 2051 int yahoo_cmd_conf_invite(struct yahoo_context *ctx, const char *conf_id,
2052 char **userlist, char *invited_user, char *msg) 2052 char **userlist, const char *invited_user, const char *msg)
2053 { 2053 {
2054 char ctrlb = 2; 2054 char ctrlb = 2;
2055 char *content; 2055 char *content;
2056 char *new_userlist = yahoo_array2list(userlist); 2056 char *new_userlist = yahoo_array2list(userlist);
2057 2057
2095 2095
2096 Packet format: 2096 Packet format:
2097 id^all-invited-users^msg 2097 id^all-invited-users^msg
2098 2098
2099 */ 2099 */
2100 int yahoo_cmd_conf_msg(struct yahoo_context *ctx, char *conf_id, 2100 int yahoo_cmd_conf_msg(struct yahoo_context *ctx, const char *conf_id,
2101 char **userlist, char *msg) 2101 char **userlist, const char *msg)
2102 { 2102 {
2103 char ctrlb = 2; 2103 char ctrlb = 2;
2104 char *content; 2104 char *content;
2105 int cont_len = 0; 2105 int cont_len = 0;
2106 2106
2729 */ 2729 */
2730 int yahoo_parsepacket_conference_user(struct yahoo_context *ctx, 2730 int yahoo_parsepacket_conference_user(struct yahoo_context *ctx,
2731 struct yahoo_packet *pkt, struct yahoo_rawpacket *inpkt) 2731 struct yahoo_packet *pkt, struct yahoo_rawpacket *inpkt)
2732 { 2732 {
2733 char *content; 2733 char *content;
2734 char *tmp, delim[5]; 2734 char *tmp = NULL;
2735 size_t found = 0, len = yahoo_makeint(inpkt->len);
2735 2736
2736 /* Make working copy of content */ 2737 /* Make working copy of content */
2737 content = strdup(inpkt->content); 2738 content = memdup(inpkt->content, len);
2738 2739
2739 /* init elements to all null */ 2740 /* init elements to all null */
2740 pkt->conf_id = NULL; 2741 pkt->conf_id = NULL;
2741 pkt->conf_host = NULL; 2742 pkt->conf_host = NULL;
2742 pkt->conf_user = NULL; 2743 pkt->conf_user = NULL;
2743 pkt->conf_userlist = NULL; 2744 pkt->conf_userlist = NULL;
2744 pkt->conf_inviter = NULL; 2745 pkt->conf_inviter = NULL;
2745 pkt->conf_msg = NULL; 2746 pkt->conf_msg = NULL;
2746 2747
2747 tmp = NULL;
2748 delim[0] = 2; /* control-b */
2749 delim[1] = 0;
2750
2751 if (content) 2748 if (content)
2752 { 2749 {
2753 tmp = strtok(content, delim); 2750 tmp = memtok(content, len, "\002", 2, &found);
2754 } 2751 }
2755 2752
2756 if (tmp) /* got the conference id */ 2753 if (tmp) /* got the conference id */
2757 { 2754 {
2758 pkt->conf_id = strdup(tmp); 2755 pkt->conf_id = memdupasstr(tmp, found);
2759 tmp = strtok(NULL, delim); 2756 tmp = memtok(0, 0, "\002", 2, &found);
2760 } 2757 }
2761 2758
2762 if (tmp) /* conference user */ 2759 if (tmp)
2763 { 2760 {
2764 pkt->conf_user = strdup(tmp); 2761 if ( pkt->msgtype == 1 ) /* conference user */
2765 tmp = strtok(NULL, delim); 2762 {
2763 pkt->conf_user = memdupasstr(tmp, found);
2764 tmp = memtok(0, 0, "\002", 2, &found);
2765 }
2766 else if ( pkt->msgtype == 0 ) /* conference userlist? */
2767 {
2768 char *userlist = memdupasstr(tmp, found);
2769
2770 pkt->conf_userlist = yahoo_list2array(userlist);
2771 tmp = memtok(0, 0, "\002", 2, &found);
2772 FREE(userlist);
2773 }
2766 } 2774 }
2767 2775
2768 FREE(content); 2776 FREE(content);
2769 return 0; 2777 return 0;
2770 } 2778 }