Mercurial > pidgin
comparison libpurple/protocols/oscar/family_icbm.c @ 30600:6f8a8685eef1
Simplify the way that string length and memory allocation is done.
I noticed this while investigating #12587 (which I don't think this will fix).
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Tue, 12 Oct 2010 21:50:56 +0000 |
parents | 1cdae196aac8 |
children | 1558900f47e5 |
comparison
equal
deleted
inserted
replaced
30599:0950887d7860 | 30600:6f8a8685eef1 |
---|---|
1934 return -EINVAL; | 1934 return -EINVAL; |
1935 | 1935 |
1936 fmt = "<N><QUERY><Q><PluginID>srvMng</PluginID></Q></QUERY><NOTIFY><srv><id>cAwaySrv</id><req><id>AwayStat</id><trans>2</trans><senderId>%s</senderId></req></srv></NOTIFY></N>\r\n"; | 1936 fmt = "<N><QUERY><Q><PluginID>srvMng</PluginID></Q></QUERY><NOTIFY><srv><id>cAwaySrv</id><req><id>AwayStat</id><trans>2</trans><senderId>%s</senderId></req></srv></NOTIFY></N>\r\n"; |
1937 | 1937 |
1938 account = purple_connection_get_account(od->gc); | 1938 account = purple_connection_get_account(od->gc); |
1939 xmllen = strlen(fmt) - 2 + strlen(account->username); | 1939 |
1940 | 1940 statxml = g_strdup_printf(fmt, account->username); |
1941 statxml = g_malloc(xmllen); | 1941 xmllen = strlen(statxml); |
1942 snprintf(statxml, xmllen, fmt, account->username); | |
1943 | 1942 |
1944 aim_icbm_makecookie(cookie); | 1943 aim_icbm_makecookie(cookie); |
1945 | 1944 |
1946 byte_stream_new(&bs, 10 + 8 + 2 + 1 + strlen(sn) + 2 | 1945 byte_stream_new(&bs, 10 + 8 + 2 + 1 + strlen(sn) + 2 |
1947 + 2 + 2 + 8 + 16 + 2 + 2 + 2 + 2 + 2 | 1946 + 2 + 2 + 8 + 16 + 2 + 2 + 2 + 2 + 2 |
1960 aim_tlvlist_add_noval(&inner_tlvlist, 0x000f); | 1959 aim_tlvlist_add_noval(&inner_tlvlist, 0x000f); |
1961 | 1960 |
1962 /* Add Plugin Specific Data */ | 1961 /* Add Plugin Specific Data */ |
1963 byte_stream_new(&plugindata, (sizeof(c_plugindata) + xmllen)); | 1962 byte_stream_new(&plugindata, (sizeof(c_plugindata) + xmllen)); |
1964 byte_stream_putraw(&plugindata, c_plugindata, sizeof(c_plugindata)); /* Content of TLV 0x2711 */ | 1963 byte_stream_putraw(&plugindata, c_plugindata, sizeof(c_plugindata)); /* Content of TLV 0x2711 */ |
1965 byte_stream_putstr(&plugindata, statxml); | 1964 byte_stream_putraw(&plugindata, (const guint8*)statxml, xmllen); |
1966 | 1965 |
1967 aim_tlvlist_add_raw(&inner_tlvlist, 0x2711, (sizeof(c_plugindata) + xmllen), plugindata.data); | 1966 aim_tlvlist_add_raw(&inner_tlvlist, 0x2711, (sizeof(c_plugindata) + xmllen), plugindata.data); |
1968 | 1967 |
1969 aim_tlvlist_write(&header, &inner_tlvlist); | 1968 aim_tlvlist_write(&header, &inner_tlvlist); |
1970 aim_tlvlist_free(inner_tlvlist); | 1969 aim_tlvlist_free(inner_tlvlist); |
2046 | 2045 |
2047 msg = purple_markup_strip_html(formatted_msg); | 2046 msg = purple_markup_strip_html(formatted_msg); |
2048 if (!msg) | 2047 if (!msg) |
2049 return -EINVAL; | 2048 return -EINVAL; |
2050 | 2049 |
2051 len = strlen(fmt) - 6 + strlen(account->username) + strlen(title) + strlen(msg); | 2050 statxml = g_strdup_printf(fmt, account->username, title, msg); |
2052 statxml = g_malloc(len); | 2051 len = strlen(statxml); |
2053 | |
2054 snprintf(statxml, len, fmt, account->username, title, msg); | |
2055 | 2052 |
2056 purple_debug_misc("oscar", "X-Status AutoReply: %s, %s\n", formatted_msg, msg); | 2053 purple_debug_misc("oscar", "X-Status AutoReply: %s, %s\n", formatted_msg, msg); |
2057 | 2054 |
2058 byte_stream_new(&bs, 10 + 8 + 2 + 1 + strlen(sn) + 2 + sizeof(plugindata) + strlen(statxml)); /* 16 extra */ | 2055 byte_stream_new(&bs, 10 + 8 + 2 + 1 + strlen(sn) + 2 + sizeof(plugindata) + len); /* 16 extra */ |
2059 | 2056 |
2060 snacid = aim_cachesnac(od, 0x0004, 0x000b, 0x0000, NULL, 0); | 2057 snacid = aim_cachesnac(od, 0x0004, 0x000b, 0x0000, NULL, 0); |
2061 aim_im_puticbm(&bs, cookie, 0x0002, sn); | 2058 aim_im_puticbm(&bs, cookie, 0x0002, sn); |
2062 byte_stream_put16(&bs, 0x0003); | 2059 byte_stream_put16(&bs, 0x0003); |
2063 byte_stream_putraw(&bs, plugindata, sizeof(plugindata)); | 2060 byte_stream_putraw(&bs, plugindata, sizeof(plugindata)); |
2064 byte_stream_putraw(&bs, (const guint8*)statxml, strlen(statxml)); | 2061 byte_stream_putraw(&bs, (const guint8*)statxml, len); |
2065 | 2062 |
2066 flap_connection_send_snac_with_priority(od, conn, 0x0004, 0x000b, snacid, &bs, TRUE); | 2063 flap_connection_send_snac_with_priority(od, conn, 0x0004, 0x000b, snacid, &bs, TRUE); |
2067 | 2064 |
2068 g_free(statxml); | 2065 g_free(statxml); |
2069 g_free(msg); | 2066 g_free(msg); |