| 3944 |
3944 |
| 3945 /* TODO: Move this into odc.c! */ |
3945 /* TODO: Move this into odc.c! */ |
| 3946 static void |
3946 static void |
| 3947 gaim_odc_send_im(PeerConnection *conn, const char *message, GaimMessageFlags imflags) |
3947 gaim_odc_send_im(PeerConnection *conn, const char *message, GaimMessageFlags imflags) |
| 3948 { |
3948 { |
| 3949 GString *msg = g_string_new("<HTML><BODY>"); |
3949 GString *msg; |
| 3950 GString *data = g_string_new("</BODY></HTML><BINARY>"); |
3950 GString *data; |
| |
3951 gchar *tmp; |
| |
3952 int tmplen; |
| |
3953 guint16 charset, charsubset; |
| 3951 GData *attribs; |
3954 GData *attribs; |
| 3952 const char *start, *end, *last; |
3955 const char *start, *end, *last; |
| 3953 int oscar_id = 0; |
3956 int oscar_id = 0; |
| 3954 |
3957 |
| |
3958 msg = g_string_new("<HTML><BODY>"); |
| |
3959 data = g_string_new("<BINARY>"); |
| 3955 last = message; |
3960 last = message; |
| 3956 |
3961 |
| 3957 /* for each valid IMG tag... */ |
3962 /* for each valid IMG tag... */ |
| 3958 while (last && *last && gaim_markup_find_tag("img", last, &start, &end, &attribs)) |
3963 while (last && *last && gaim_markup_find_tag("img", last, &start, &end, &attribs)) |
| 3959 { |
3964 { |
| 3986 oscar_id, size); |
3991 oscar_id, size); |
| 3987 |
3992 |
| 3988 /* ... and append the data to the binary section ... */ |
3993 /* ... and append the data to the binary section ... */ |
| 3989 g_string_append_printf(data, "<DATA ID=\"%d\" SIZE=\"%lu\">", |
3994 g_string_append_printf(data, "<DATA ID=\"%d\" SIZE=\"%lu\">", |
| 3990 oscar_id, size); |
3995 oscar_id, size); |
| 3991 data = g_string_append_len(data, imgdata, size); |
3996 g_string_append_len(data, imgdata, size); |
| 3992 data = g_string_append(data, "</DATA>"); |
3997 g_string_append(data, "</DATA>"); |
| 3993 } |
3998 } |
| 3994 /* If the tag is invalid, skip it, thus no else here */ |
3999 /* If the tag is invalid, skip it, thus no else here */ |
| 3995 |
4000 |
| 3996 g_datalist_clear(&attribs); |
4001 g_datalist_clear(&attribs); |
| 3997 |
4002 |
| 3998 /* continue from the end of the tag */ |
4003 /* continue from the end of the tag */ |
| 3999 last = end + 1; |
4004 last = end + 1; |
| 4000 } |
4005 } |
| 4001 |
4006 |
| 4002 /* append any remaining message data (without the > :-) ) */ |
4007 /* append any remaining message data */ |
| 4003 if (last && *last) |
4008 if (last && *last) |
| 4004 msg = g_string_append(msg, last); |
4009 g_string_append(msg, last); |
| 4005 |
4010 |
| 4006 /* if we inserted any images in the binary section, append it */ |
4011 g_string_append(msg, "</BODY></HTML>"); |
| |
4012 |
| |
4013 /* Convert the message to a good encoding */ |
| |
4014 gaim_plugin_oscar_convert_to_best_encoding(conn->od->gc, |
| |
4015 conn->sn, msg->str, &tmp, &tmplen, &charset, &charsubset); |
| |
4016 g_string_free(msg, TRUE); |
| |
4017 msg = g_string_new_len(tmp, tmplen); |
| |
4018 |
| |
4019 /* Append any binary data that we may have */ |
| 4007 if (oscar_id) { |
4020 if (oscar_id) { |
| 4008 msg = g_string_append_len(msg, data->str, data->len); |
4021 msg = g_string_append_len(msg, data->str, data->len); |
| 4009 msg = g_string_append(msg, "</BINARY>"); |
4022 msg = g_string_append(msg, "</BINARY>"); |
| 4010 } |
4023 } |
| 4011 |
|
| 4012 g_string_free(data, TRUE); |
4024 g_string_free(data, TRUE); |
| 4013 |
4025 |
| 4014 /* TODO: Deal with the encoding. */ |
4026 peer_odc_send_im(conn, msg->str, msg->len, charset, |
| 4015 peer_odc_send_im(conn, msg->str, msg->len, 0, imflags & GAIM_MESSAGE_AUTO_RESP); |
4027 imflags & GAIM_MESSAGE_AUTO_RESP); |
| 4016 g_string_free(msg, TRUE); |
4028 g_string_free(msg, TRUE); |
| 4017 } |
4029 } |
| 4018 |
4030 |
| 4019 static int |
4031 static int |
| 4020 oscar_send_im(GaimConnection *gc, const char *name, const char *message, GaimMessageFlags imflags) |
4032 oscar_send_im(GaimConnection *gc, const char *name, const char *message, GaimMessageFlags imflags) |