comparison src/html.c @ 1250:b5783215b245

[gaim-migrate @ 1260] decklin's clean up of the account editor, much needed. indent -kr -i8 -l105 -ncs -cp7 -npcs -T GtkWidget -T gpointer -T AppletCallbackFunc -T GtkFunction -T gaim_plugin_remove -T name -T FILE -T gchar -T user_opts -T GdkEvent -T GtkObject ... did about.c, aim.c, away.c, browser.c, buddy_chat.c, gaimrc.c, html.c, idle.c, multi.c. Need to do buddy.c, conversation.c, dialogs.c, oscar.c, perl.c, plugins.c, prefs.c, proxy.c, prpl.c, rvous.c, server.c, sound.c, toc.c, util.c. not doing gtkhtml.c because it's a piece of crap anyway, or *ticker.c because they're syd's. got rid of debug_buff, just debug_printf now. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Wed, 13 Dec 2000 20:18:35 +0000
parents a930439f29b1
children 00aef397a1fe
comparison
equal deleted inserted replaced
1249:3e44de27622d 1250:b5783215b245
37 #include <netinet/in.h> 37 #include <netinet/in.h>
38 #include <fcntl.h> 38 #include <fcntl.h>
39 #include <errno.h> 39 #include <errno.h>
40 #include "proxy.h" 40 #include "proxy.h"
41 41
42 gchar * strip_html(gchar * text) 42 gchar *strip_html(gchar *text)
43 { 43 {
44 int i, j; 44 int i, j;
45 int visible = 1; 45 int visible = 1;
46 gchar *text2 = g_malloc(strlen(text) + 1); 46 gchar *text2 = g_malloc(strlen(text) + 1);
47 47
48 strcpy(text2, text); 48 strcpy(text2, text);
49 for (i = 0, j = 0;text2[i]; i++) 49 for (i = 0, j = 0; text2[i]; i++) {
50 { 50 if (text2[i] == '<') {
51 if(text2[i]=='<')
52 {
53 visible = 0; 51 visible = 0;
54 continue; 52 continue;
55 } 53 } else if (text2[i] == '>') {
56 else if(text2[i]=='>')
57 {
58 visible = 1; 54 visible = 1;
59 continue; 55 continue;
60 } 56 }
61 if(visible) 57 if (visible) {
62 {
63 text2[j++] = text2[i]; 58 text2[j++] = text2[i];
64 } 59 }
65 } 60 }
66 text2[j] = '\0'; 61 text2[j] = '\0';
67 return text2; 62 return text2;
73 char scan_info[255]; 68 char scan_info[255];
74 char port[5]; 69 char port[5];
75 int f; 70 int f;
76 71
77 if (strstr(url, "http://")) 72 if (strstr(url, "http://"))
78 g_snprintf(scan_info, sizeof(scan_info), "http://%%[A-Za-z0-9.]:%%[0-9]/%%[A-Za-z0-9.~_-/&%%?]"); 73 g_snprintf(scan_info, sizeof(scan_info),
74 "http://%%[A-Za-z0-9.]:%%[0-9]/%%[A-Za-z0-9.~_-/&%%?]");
79 else 75 else
80 g_snprintf(scan_info, sizeof(scan_info), "%%[A-Za-z0-9.]:%%[0-9]/%%[A-Za-z0-9.~_-/&%%?]"); 76 g_snprintf(scan_info, sizeof(scan_info),
77 "%%[A-Za-z0-9.]:%%[0-9]/%%[A-Za-z0-9.~_-/&%%?]");
81 f = sscanf(url, scan_info, test.address, port, test.page); 78 f = sscanf(url, scan_info, test.address, port, test.page);
82 if (f == 1) { 79 if (f == 1) {
83 if (strstr(url, "http://")) 80 if (strstr(url, "http://"))
84 g_snprintf(scan_info, sizeof(scan_info), "http://%%[A-Za-z0-9.]/%%[A-Za-z0-9.~_-/&%%?]"); 81 g_snprintf(scan_info, sizeof(scan_info),
82 "http://%%[A-Za-z0-9.]/%%[A-Za-z0-9.~_-/&%%?]");
85 else 83 else
86 g_snprintf(scan_info, sizeof(scan_info), "%%[A-Za-z0-9.]/%%[A-Za-z0-9.~_-/&%%?]"); 84 g_snprintf(scan_info, sizeof(scan_info),
87 f = sscanf(url, scan_info, test.address, test.page); 85 "%%[A-Za-z0-9.]/%%[A-Za-z0-9.~_-/&%%?]");
88 g_snprintf(port, sizeof(test.port), "80"); 86 f = sscanf(url, scan_info, test.address, test.page);
89 port[2] = 0; 87 g_snprintf(port, sizeof(test.port), "80");
88 port[2] = 0;
90 } 89 }
91 if (f == 1) { 90 if (f == 1) {
92 if (strstr(url, "http://")) 91 if (strstr(url, "http://"))
93 g_snprintf(scan_info, sizeof(scan_info), "http://%%[A-Za-z0-9.]"); 92 g_snprintf(scan_info, sizeof(scan_info), "http://%%[A-Za-z0-9.]");
94 else 93 else
95 g_snprintf(scan_info, sizeof(scan_info), "%%[A-Za-z0-9.]"); 94 g_snprintf(scan_info, sizeof(scan_info), "%%[A-Za-z0-9.]");
96 f = sscanf(url, scan_info, test.address); 95 f = sscanf(url, scan_info, test.address);
97 g_snprintf(test.page, sizeof(test.page), "%c", '\0'); 96 g_snprintf(test.page, sizeof(test.page), "%c", '\0');
98 } 97 }
99 98
100 sscanf(port, "%d", &test.port); 99 sscanf(port, "%d", &test.port);
103 102
104 char *grab_url(struct aim_user *user, char *url) 103 char *grab_url(struct aim_user *user, char *url)
105 { 104 {
106 struct g_url website; 105 struct g_url website;
107 char *webdata = NULL; 106 char *webdata = NULL;
108 int sock; 107 int sock;
109 int len; 108 int len;
110 int read_rv; 109 int read_rv;
111 int datalen = 0; 110 int datalen = 0;
112 char buf[256]; 111 char buf[256];
113 char data; 112 char data;
114 int startsaving = 0; 113 int startsaving = 0;
115 GtkWidget *pw = NULL, *pbar = NULL, *label; 114 GtkWidget *pw = NULL, *pbar = NULL, *label;
116 115
117 website = parse_url(url); 116 website = parse_url(url);
118 117
119 if (user) { 118 if (user) {
120 if ((sock = proxy_connect(website.address, website.port, user->proto_opt[2], 119 if ((sock = proxy_connect(website.address, website.port, user->proto_opt[2],
121 atoi(user->proto_opt[3]), atoi(user->proto_opt[4]))) < 0) 120 atoi(user->proto_opt[3]), atoi(user->proto_opt[4]))) < 0)
122 return g_strdup(_("g003: Error opening connection.\n")); 121 return g_strdup(_("g003: Error opening connection.\n"));
123 } else { 122 } else {
124 if ((sock = proxy_connect(website.address, website.port, NULL, 0, -1)) < 0) 123 if ((sock = proxy_connect(website.address, website.port, NULL, 0, -1)) < 0)
125 return g_strdup(_("g003: Error opening connection.\n")); 124 return g_strdup(_("g003: Error opening connection.\n"));
126 } 125 }
127 126
128 g_snprintf(buf, sizeof(buf), "GET /%s HTTP/1.0\r\n\r\n", website.page); 127 g_snprintf(buf, sizeof(buf), "GET /%s HTTP/1.0\r\n\r\n", website.page);
129 g_snprintf(debug_buff, sizeof(debug_buff), "Request: %s\n", buf); 128 debug_printf("Request: %s\n", buf);
130 debug_print(debug_buff);
131 write(sock, buf, strlen(buf)); 129 write(sock, buf, strlen(buf));
132 fcntl(sock, F_SETFL, O_NONBLOCK); 130 fcntl(sock, F_SETFL, O_NONBLOCK);
133 131
134 webdata = NULL; 132 webdata = NULL;
135 len = 0; 133 len = 0;
136 134
137 /* 135 /*
138 * avoid fgetc(), it causes problems on solaris 136 * avoid fgetc(), it causes problems on solaris
139 while ((data = fgetc(sockfile)) != EOF) { 137 while ((data = fgetc(sockfile)) != EOF) {
140 */ 138 */
141 /* read_rv will be 0 on EOF and < 0 on error, so this should be fine */ 139 /* read_rv will be 0 on EOF and < 0 on error, so this should be fine */
142 while ((read_rv = read(sock, &data, 1)) > 0 || errno == EWOULDBLOCK) { 140 while ((read_rv = read(sock, &data, 1)) > 0 || errno == EWOULDBLOCK) {
143 if (errno == EWOULDBLOCK) { 141 if (errno == EWOULDBLOCK) {
144 errno = 0; 142 errno = 0;
145 continue; 143 continue;
146 } 144 }
147 145
148 if (!data) 146 if (!data)
149 continue; 147 continue;
150 148
151 if (!startsaving && data == '<') { 149 if (!startsaving && data == '<') {
152 #ifdef HAVE_STRSTR 150 #ifdef HAVE_STRSTR
153 char *cs = strstr(webdata, "Content-Length"); 151 char *cs = strstr(webdata, "Content-Length");
154 if (cs) { 152 if (cs) {
155 char tmpbuf[1024]; 153 char tmpbuf[1024];
156 sscanf(cs, "Content-Length: %d", &datalen); 154 sscanf(cs, "Content-Length: %d", &datalen);
157 155
158 g_snprintf(tmpbuf, 1024, _("Getting %d bytes from %s"), datalen, url); 156 g_snprintf(tmpbuf, 1024, _("Getting %d bytes from %s"), datalen, url);
159 pw = gtk_dialog_new(); 157 pw = gtk_dialog_new();
160 158
161 label = gtk_label_new(tmpbuf); 159 label = gtk_label_new(tmpbuf);
162 gtk_widget_show(label); 160 gtk_widget_show(label);
163 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pw)->vbox), 161 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pw)->vbox),
164 label, FALSE, FALSE, 5); 162 label, FALSE, FALSE, 5);
165 163
166 pbar = gtk_progress_bar_new(); 164 pbar = gtk_progress_bar_new();
167 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pw)->action_area), 165 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pw)->action_area),
168 pbar, FALSE, FALSE, 5); 166 pbar, FALSE, FALSE, 5);
169 gtk_widget_show(pbar); 167 gtk_widget_show(pbar);
170 168
171 gtk_window_set_title(GTK_WINDOW(pw), _("Getting Data")); 169 gtk_window_set_title(GTK_WINDOW(pw), _("Getting Data"));
172 170
173 gtk_widget_realize(pw); 171 gtk_widget_realize(pw);
174 aol_icon(pw->window); 172 aol_icon(pw->window);
175 173
176 gtk_widget_show(pw); 174 gtk_widget_show(pw);
177 } else 175 } else
178 datalen = 0; 176 datalen = 0;
179 #else 177 #else
180 datalen = 0; 178 datalen = 0;
181 #endif 179 #endif
182 g_free(webdata); 180 g_free(webdata);
188 len++; 186 len++;
189 webdata = g_realloc(webdata, len); 187 webdata = g_realloc(webdata, len);
190 webdata[len - 1] = data; 188 webdata[len - 1] = data;
191 189
192 if (pbar) 190 if (pbar)
193 gtk_progress_bar_update(GTK_PROGRESS_BAR(pbar), 191 gtk_progress_bar_update(GTK_PROGRESS_BAR(pbar), ((100 * len) / datalen) / 100.0);
194 ((100 * len) / datalen) / 100.0); 192
195
196 while (gtk_events_pending()) 193 while (gtk_events_pending())
197 gtk_main_iteration(); 194 gtk_main_iteration();
198 } 195 }
199 196
200 webdata = g_realloc(webdata, len+1); 197 webdata = g_realloc(webdata, len + 1);
201 webdata[len] = 0; 198 webdata[len] = 0;
202 199
203 200
204 g_snprintf(debug_buff, sizeof(debug_buff), _("Receieved: '%s'\n"), webdata); 201 debug_printf(_("Receieved: '%s'\n"), webdata);
205 debug_print(debug_buff); 202
206 203 if (pw)
207 if (pw) 204 gtk_widget_destroy(pw);
208 gtk_widget_destroy(pw);
209 205
210 close(sock); 206 close(sock);
211 return webdata; 207 return webdata;
212 } 208 }