Mercurial > pidgin.yaz
annotate src/html.c @ 253:5b28ef2b550e
[gaim-migrate @ 263]
A few things happened in this update:
- Commented out the libfaim deny/permit list stuff because it's seriously buggy
- Added Socks v4 support
- improved proxy support for things like getting users' info
- i think that's it
committer: Tailor Script <tailor@pidgin.im>
| author | Eric Warmenhoven <eric@warmenhoven.org> |
|---|---|
| date | Tue, 23 May 2000 05:26:30 +0000 |
| parents | c8854c4b66cc |
| children | f8a29745247c |
| rev | line source |
|---|---|
| 1 | 1 /* |
| 2 * gaim | |
| 3 * | |
| 4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
| 5 * | |
| 6 * This program is free software; you can redistribute it and/or modify | |
| 7 * it under the terms of the GNU General Public License as published by | |
| 8 * the Free Software Foundation; either version 2 of the License, or | |
| 9 * (at your option) any later version. | |
| 10 * | |
| 11 * This program is distributed in the hope that it will be useful, | |
| 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 * GNU General Public License for more details. | |
| 15 * | |
| 16 * You should have received a copy of the GNU General Public License | |
| 17 * along with this program; if not, write to the Free Software | |
| 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 19 * | |
| 20 */ | |
| 21 | |
| 22 #include <string.h> | |
| 23 #include <stdio.h> | |
| 24 #include <stdlib.h> | |
| 25 #include <sys/time.h> | |
| 26 #include <unistd.h> | |
| 27 #include <gtk/gtk.h> | |
| 28 #include <gdk/gdkprivate.h> | |
| 29 #include <gdk/gdkx.h> | |
| 30 #include "gaim.h" | |
| 31 #include <sys/types.h> | |
| 32 #include <sys/socket.h> | |
| 33 #include <netdb.h> | |
| 34 #include <netinet/in.h> | |
| 35 | |
| 36 gchar * strip_html(gchar * text) | |
| 37 { | |
| 38 int i, j; | |
| 39 int visible = 1; | |
| 40 gchar *text2 = g_malloc(strlen(text) + 1); | |
| 41 | |
| 42 strcpy(text2, text); | |
| 43 for (i = 0, j = 0;text2[i]; i++) | |
| 44 { | |
| 45 if(text2[i]=='<') | |
| 46 { | |
| 47 visible = 0; | |
| 48 continue; | |
| 49 } | |
| 50 else if(text2[i]=='>') | |
| 51 { | |
| 52 visible = 1; | |
| 53 continue; | |
| 54 } | |
| 55 if(visible) | |
| 56 { | |
| 57 text2[j++] = text2[i]; | |
| 58 } | |
| 59 } | |
| 60 text2[j] = '\0'; | |
| 61 return text2; | |
| 62 } | |
| 63 | |
| 64 struct g_url parse_url(char *url) | |
| 65 { | |
| 66 struct g_url test; | |
| 67 char scan_info[255]; | |
| 68 char port[5]; | |
| 69 int f; | |
| 70 | |
| 71 if (strstr(url, "http://")) | |
| 72 g_snprintf(scan_info, sizeof(scan_info), "http://%%[A-Za-z0-9.]:%%[0-9]/%%[A-Za-z0-9.~_-/&%%?]"); | |
| 73 else | |
| 74 g_snprintf(scan_info, sizeof(scan_info), "%%[A-Za-z0-9.]:%%[0-9]/%%[A-Za-z0-9.~_-/&%%?]"); | |
| 75 f = sscanf(url, scan_info, test.address, port, test.page); | |
| 76 if (f == 1) { | |
| 77 if (strstr(url, "http://")) | |
| 78 g_snprintf(scan_info, sizeof(scan_info), "http://%%[A-Za-z0-9.]/%%[A-Za-z0-9.~_-/&%%?]"); | |
| 79 else | |
| 80 g_snprintf(scan_info, sizeof(scan_info), "%%[A-Za-z0-9.]/%%[A-Za-z0-9.~_-/&%%?]"); | |
| 81 f = sscanf(url, scan_info, test.address, test.page); | |
| 82 g_snprintf(port, sizeof(test.port), "80"); | |
| 83 port[2] = 0; | |
| 84 } | |
| 85 if (f == 1) { | |
| 86 if (strstr(url, "http://")) | |
| 87 g_snprintf(scan_info, sizeof(scan_info), "http://%%[A-Za-z0-9.]"); | |
| 88 else | |
| 89 g_snprintf(scan_info, sizeof(scan_info), "%%[A-Za-z0-9.]"); | |
| 90 f = sscanf(url, scan_info, test.address); | |
| 91 g_snprintf(test.page, sizeof(test.page), "%c", '\0'); | |
| 92 } | |
| 93 | |
| 94 sscanf(port, "%d", &test.port); | |
| 95 return test; | |
| 96 } | |
| 97 | |
| 98 char *grab_url(char *url) | |
| 99 { | |
| 100 struct g_url website; | |
| 101 char *webdata = NULL; | |
| 102 int sock; | |
| 103 int len; | |
| 104 int datalen = 0; | |
|
253
5b28ef2b550e
[gaim-migrate @ 263]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
35
diff
changeset
|
105 struct in_addr *host; |
| 1 | 106 char buf[256]; |
| 107 char data; | |
| 108 FILE *sockfile; | |
| 109 int startsaving = 0; | |
| 110 GtkWidget *pw = NULL, *pbar = NULL, *label; | |
| 111 | |
| 112 website = parse_url(url); | |
| 113 | |
|
253
5b28ef2b550e
[gaim-migrate @ 263]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
35
diff
changeset
|
114 /* |
| 1 | 115 host = gethostbyname(website.address); |
| 116 if (!host) { return g_strdup("g001: Error resolving host\n"); } | |
| 117 | |
|
253
5b28ef2b550e
[gaim-migrate @ 263]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
35
diff
changeset
|
118 if ((sock = connect_address(inet_addr(host->h_addr), website.port)) <= -1) |
|
5b28ef2b550e
[gaim-migrate @ 263]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
35
diff
changeset
|
119 return g_strdup("g003: Error opening connection.\n"); |
|
5b28ef2b550e
[gaim-migrate @ 263]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
35
diff
changeset
|
120 */ |
|
5b28ef2b550e
[gaim-migrate @ 263]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
35
diff
changeset
|
121 host = (struct in_addr *)get_address(website.address); |
|
5b28ef2b550e
[gaim-migrate @ 263]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
35
diff
changeset
|
122 if (!host) { return g_strdup("g001: Error resolving host\n"); } |
|
5b28ef2b550e
[gaim-migrate @ 263]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
35
diff
changeset
|
123 if ((sock = connect_address(host->s_addr, website.port)) < 0) |
| 1 | 124 return g_strdup("g003: Error opening connection.\n"); |
| 125 | |
| 126 sockfile = fdopen(sock, "r+"); | |
| 127 | |
| 128 g_snprintf(buf, sizeof(buf), "GET /%s HTTP/1.0\n\n", website.page); | |
| 129 g_snprintf(debug_buff, sizeof(debug_buff), "Request: %s\n", buf); | |
| 130 debug_print(debug_buff); | |
| 131 fputs(buf, sockfile); | |
| 132 | |
| 133 webdata = NULL; | |
| 134 len = 0; | |
| 135 | |
| 35 | 136 while ((data = fgetc(sockfile)) != EOF) { |
| 1 | 137 if (!data) |
| 138 continue; | |
| 139 | |
| 140 if (!startsaving && data == '<') { | |
| 141 #ifdef HAVE_STRSTR | |
| 142 char *cs = strstr(webdata, "Content-Length"); | |
| 143 if (cs) { | |
| 144 char tmpbuf[1024]; | |
| 145 sscanf(cs, "Content-Length: %d", &datalen); | |
| 146 | |
| 147 g_snprintf(tmpbuf, 1024, "Getting %d bytes from %s", datalen, url); | |
| 148 pw = gtk_dialog_new(); | |
| 149 | |
| 150 label = gtk_label_new(tmpbuf); | |
| 151 gtk_widget_show(label); | |
| 152 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pw)->vbox), | |
| 153 label, FALSE, FALSE, 5); | |
| 154 | |
| 155 pbar = gtk_progress_bar_new(); | |
| 156 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pw)->action_area), | |
| 157 pbar, FALSE, FALSE, 5); | |
| 158 gtk_widget_show(pbar); | |
| 159 | |
| 160 gtk_window_set_title(GTK_WINDOW(pw), "Getting Data"); | |
| 161 | |
| 162 gtk_widget_realize(pw); | |
| 163 aol_icon(pw->window); | |
| 164 | |
| 165 gtk_widget_show(pw); | |
| 166 } else | |
| 167 datalen = 0; | |
| 168 #else | |
| 169 datalen = 0; | |
| 170 #endif | |
| 171 g_free(webdata); | |
| 172 webdata = NULL; | |
| 173 len = 0; | |
| 174 startsaving = 1; | |
| 175 } | |
| 176 | |
| 177 len++; | |
| 178 webdata = g_realloc(webdata, len); | |
| 179 webdata[len - 1] = data; | |
| 180 | |
| 181 if (pbar) | |
| 182 gtk_progress_bar_update(GTK_PROGRESS_BAR(pbar), | |
| 183 ((100 * len) / datalen) / 100.0); | |
| 184 | |
| 185 while (gtk_events_pending()) | |
| 186 gtk_main_iteration(); | |
| 187 } | |
| 188 | |
| 189 webdata = g_realloc(webdata, len+1); | |
| 190 webdata[len] = 0; | |
| 191 | |
| 192 | |
| 193 g_snprintf(debug_buff, sizeof(debug_buff), "Receieved: '%s'\n", webdata); | |
| 194 debug_print(debug_buff); | |
| 195 | |
| 196 if (pw) | |
| 197 gtk_widget_destroy(pw); | |
| 198 | |
| 199 close(sock); | |
| 200 return webdata; | |
| 201 } | |
| 202 | |
| 203 char *fix_url(gchar *buf) | |
| 204 { | |
| 205 char *new,*tmp; | |
| 206 int size; | |
| 207 | |
| 208 size=8; | |
| 209 size+=strlen(quad_addr); | |
| 210 tmp=strchr(strchr(buf,':')+1,':'); | |
| 211 size+=strlen(tmp); | |
| 212 new=g_malloc(size); | |
| 213 strcpy(new,"http://"); | |
| 214 strcat(new,quad_addr); | |
| 215 strcat(new,tmp); | |
| 216 return(new); | |
| 217 } | |
| 218 | |
| 219 |
