comparison src/conversation.c @ 3048:e729c064bc1b

[gaim-migrate @ 3061] Some Image send fixes, and elimination of some compile warnings. There are still far too many (read: more than zero) committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Fri, 15 Mar 2002 00:56:15 +0000
parents e68e2ba82310
children 200b8133616a
comparison
equal deleted inserted replaced
3047:388230971b20 3048:e729c064bc1b
1090 return; 1090 return;
1091 } 1091 }
1092 g_snprintf(buf, limit, "%s", buffy); 1092 g_snprintf(buf, limit, "%s", buffy);
1093 g_free(buffy); 1093 g_free(buffy);
1094 } 1094 }
1095 1095
1096 if (!c->is_chat) { 1096 if (!c->is_chat) {
1097 char *buffy; 1097 char *buffy;
1098 gboolean binary = FALSE;
1098 1099
1099 buffy = g_strdup(buf); 1100 buffy = g_strdup(buf);
1100 plugin_event(event_im_displayed_sent, c->gc, c->name, &buffy, 0); 1101 plugin_event(event_im_displayed_sent, c->gc, c->name, &buffy, 0);
1101 if (buffy) { 1102 if (buffy) {
1102 int imflags = 0; 1103 int imflags = 0;
1103 if (c->check && gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(c->check))) 1104 if (c->check && gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(c->check)))
1104 imflags = IM_FLAG_CHECKBOX; 1105 imflags = IM_FLAG_CHECKBOX;
1106
1105 if (c->images) { 1107 if (c->images) {
1106 int id, offset; 1108 int id, offset;
1107 char *bigbuf; 1109 char *bigbuf;
1108 GSList *tmplist = c->images; 1110 GSList *tmplist = c->images;
1109 id = 1; 1111 id = 1;
1110 length = strlen(buffy) + strlen("<BINARY></BINARY>"); 1112
1111 bigbuf = g_malloc(length);
1112 g_snprintf(bigbuf, strlen(buffy)+strlen("<BINARY> ") + 1, "%s<BINARY>", buffy);
1113 offset = strlen(buffy) + strlen("<BINARY>");
1114 while (tmplist) { 1113 while (tmplist) {
1115 FILE *imgfile; 1114 FILE *imgfile;
1116 char *filename; 1115 char *filename;
1117 struct stat st; 1116 struct stat st;
1118 char imgtag[1024]; 1117 char imgtag[1024];
1118
1119 if (stat(tmplist->data, &st) != 0) { 1119 if (stat(tmplist->data, &st) != 0) {
1120 debug_printf("Could not stat %s\n", tmplist->data); 1120 debug_printf("Could not stat %s\n", tmplist->data);
1121 break; 1121 tmplist = tmplist->next;
1122 continue;
1122 } 1123 }
1123 1124
1124 /* Here we check to make sure the user still wants to send the 1125 /* Here we check to make sure the user still wants to send the
1125 * image. He may have deleted the <img> tag in which case we 1126 * image. He may have deleted the <img> tag in which case we
1126 * don't want to send the binary data. */ 1127 * don't want to send the binary data. */
1128 while (strchr(filename, '/')) 1129 while (strchr(filename, '/'))
1129 filename = strchr(filename, '/') + 1; 1130 filename = strchr(filename, '/') + 1;
1130 g_snprintf(imgtag, sizeof(imgtag), 1131 g_snprintf(imgtag, sizeof(imgtag),
1131 "<IMG SRC=\"file://%s\" ID=\"%d\" DATASIZE=\"%d\">", 1132 "<IMG SRC=\"file://%s\" ID=\"%d\" DATASIZE=\"%d\">",
1132 filename, id, (int)st.st_size); 1133 filename, id, (int)st.st_size);
1133 if (!strstr(buffy, imgtag)) { 1134
1135 if (strstr(buffy, imgtag) == 0) {
1136 debug_printf("Not sending image: %s\n", tmplist->data);
1134 tmplist = tmplist->next; 1137 tmplist = tmplist->next;
1135 continue; 1138 continue;
1139 }
1140 if (!binary) {
1141 length = strlen(buffy) + strlen("<BINARY></BINARY>");
1142 bigbuf = g_malloc(length + 1);
1143 g_snprintf(bigbuf, strlen(buffy) + strlen("<BINARY> ") + 1,
1144 "%s<BINARY>", buffy);
1145 offset = strlen(buffy) + strlen("<BINARY>");
1146 binary = TRUE;
1136 } 1147 }
1137 g_snprintf(imgtag, sizeof(imgtag), 1148 g_snprintf(imgtag, sizeof(imgtag),
1138 "<DATA ID=\"%d\" SIZE=\"%d\">", 1149 "<DATA ID=\"%d\" SIZE=\"%d\">",
1139 id, (int)st.st_size); 1150 id, (int)st.st_size);
1140 1151
1141 length = length + strlen(imgtag) + st.st_size + strlen("</DATA>");; 1152 length = length + strlen(imgtag) + st.st_size + strlen("</DATA>");;
1142 bigbuf = g_realloc(bigbuf, length); 1153 bigbuf = g_realloc(bigbuf, length + 1);
1143 if (!(imgfile = fopen(tmplist->data, "r"))) { 1154 if (!(imgfile = fopen(tmplist->data, "r"))) {
1144 debug_printf("Could not open %s\n", tmplist->data); 1155 debug_printf("Could not open %s\n", tmplist->data);
1156 tmplist = tmplist->next;
1145 continue; 1157 continue;
1146 } 1158 }
1147 g_snprintf(bigbuf + offset, strlen(imgtag) + 1, "%s", imgtag); 1159 g_snprintf(bigbuf + offset, strlen(imgtag) + 1, "%s", imgtag);
1148 offset = offset + strlen(imgtag); 1160 offset = offset + strlen(imgtag);
1149 offset = offset + fread(bigbuf + offset, 1, st.st_size, imgfile); 1161 offset = offset + fread(bigbuf + offset, 1, st.st_size, imgfile);
1151 g_snprintf(bigbuf + offset, strlen("</DATA>") + 1, "</DATA>"); 1163 g_snprintf(bigbuf + offset, strlen("</DATA>") + 1, "</DATA>");
1152 offset= offset + strlen("</DATA>"); 1164 offset= offset + strlen("</DATA>");
1153 id++; 1165 id++;
1154 tmplist = tmplist->next; 1166 tmplist = tmplist->next;
1155 } 1167 }
1156 1168 if (binary) {
1157 g_snprintf(bigbuf + offset, strlen("</BINARY>") + 1, "</BINARY>"); 1169 g_snprintf(bigbuf + offset, strlen("</BINARY>") + 1, "</BINARY>");
1158 err =serv_send_im(c->gc, c->name, bigbuf, length, imflags); 1170 err =serv_send_im(c->gc, c->name, bigbuf, length, imflags);
1171 } else {
1172 err = serv_send_im(c->gc, c->name, buffy, -1, imflags);
1173 }
1159 if (err > 0) { 1174 if (err > 0) {
1160 GSList *tempy = c->images; 1175 GSList *tempy = c->images;
1161 while (tempy) { 1176 while (tempy) {
1162 g_free(tempy->data); 1177 g_free(tempy->data);
1163 tempy = tempy->next; 1178 tempy = tempy->next;
1164 } 1179 }
1165 g_slist_free(tempy); 1180 g_slist_free(tempy);
1166 c->images = NULL; 1181 c->images = NULL;
1167 write_to_conv(c, bigbuf, WFLAG_SEND, NULL, time(NULL), length); 1182 if (binary)
1183 write_to_conv(c, bigbuf, WFLAG_SEND, NULL, time(NULL), length);
1184 else
1185 write_to_conv(c, buffy, WFLAG_SEND, NULL, time(NULL), -1);
1168 if (c->makesound && (sound_options & OPT_SOUND_SEND)) 1186 if (c->makesound && (sound_options & OPT_SOUND_SEND))
1169 play_sound(SEND); 1187 play_sound(SEND);
1170 if (im_options & OPT_IM_POPDOWN) 1188 if (im_options & OPT_IM_POPDOWN)
1171 gtk_widget_hide(c->window); 1189 gtk_widget_hide(c->window);
1172 1190
1173 1191
1174 } 1192 }
1175 g_free(bigbuf); 1193 if (binary)
1194 g_free(bigbuf);
1176 } else { 1195 } else {
1177 err =serv_send_im(c->gc, c->name, buffy, -1, imflags); 1196 err =serv_send_im(c->gc, c->name, buffy, -1, imflags);
1178 if (err > 0) { 1197 if (err > 0) {
1179 write_to_conv(c, buf, WFLAG_SEND, NULL, time(NULL), -1); 1198 write_to_conv(c, buf, WFLAG_SEND, NULL, time(NULL), -1);
1180 if (c->makesound && (sound_options & OPT_SOUND_SEND)) 1199 if (c->makesound && (sound_options & OPT_SOUND_SEND))