1 const char killpopup_rcs[] = "$Id: killpopup.c,v 1.14 2002/03/07 03:46:53 oes Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/killpopup.c,v $
6 * Purpose : Handles the filtering of popups.
8 * Copyright : Written by and Copyright (C) 2001 the SourceForge
9 * Privoxy team. http://ijbswa.sourceforge.net
11 * Based on the Internet Junkbuster originally written
12 * by and Copyright (C) 1997 Anonymous Coders and
13 * Junkbusters Corporation. http://www.junkbusters.com
15 * This program is free software; you can redistribute it
16 * and/or modify it under the terms of the GNU General
17 * Public License as published by the Free Software
18 * Foundation; either version 2 of the License, or (at
19 * your option) any later version.
21 * This program is distributed in the hope that it will
22 * be useful, but WITHOUT ANY WARRANTY; without even the
23 * implied warranty of MERCHANTABILITY or FITNESS FOR A
24 * PARTICULAR PURPOSE. See the GNU General Public
25 * License for more details.
27 * The GNU General Public License should be included with
28 * this file. If not, you can view it at
29 * http://www.gnu.org/copyleft/gpl.html
30 * or write to the Free Software Foundation, Inc., 59
31 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 * $Log: killpopup.c,v $
35 * Revision 1.14 2002/03/07 03:46:53 oes
36 * Fixed compiler warnings etc
38 * Revision 1.13 2001/11/13 00:16:40 jongfoster
39 * Replacing references to malloc.h with the standard stdlib.h
40 * (See ANSI or K&R 2nd Ed)
42 * Revision 1.12 2001/10/25 03:40:48 david__schmidt
43 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
44 * threads to call select() simultaneously. So, it's time to do a real, live,
45 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
46 * (native). Both versions will work, but using __OS2__ offers multi-threading.
48 * Revision 1.11 2001/10/07 15:42:41 oes
49 * filter_popups now gets a csp pointer so it can raise the new
50 * CSP_FLAG_MODIFIED flag.
52 * Revision 1.10 2001/09/22 16:34:44 jongfoster
53 * Removing unneeded #includes
55 * Revision 1.9 2001/07/31 14:44:22 oes
56 * Deleted unused size parameter from filter_popups()
58 * Revision 1.8 2001/07/30 22:08:36 jongfoster
59 * Tidying up #defines:
60 * - All feature #defines are now of the form FEATURE_xxx
61 * - Permanently turned off WIN_GUI_EDIT
62 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
64 * Revision 1.7 2001/07/20 19:29:25 haroon
65 * - In v1.5 forgot to add that I implemented LOG_LEVEL_POPUPS in errlog.c,
66 * errlog.h and killpopup.c. In that case, it is superfluous to have define for
67 * POPUP_VERBOSE, so I removed the defines and logging is now done
68 * via log_error(LOG_LEVEL_POPUPS, ....)
70 * Revision 1.6 2001/07/19 19:11:35 haroon
71 * - Implemented Guy's idea of replacing window.open( with 1;''.concat(
72 * - Implemented Guy's idea of replacing .resizeTo( with .scrollTo(
74 * Revision 1.5 2001/07/18 15:02:52 haroon
75 * improved nuking of window.open
77 * Revision 1.4 2001/06/29 13:29:55 oes
78 * Added FIXMEs (and didn't repair, hehe)
80 * Revision 1.3 2001/05/22 18:56:28 oes
83 * Revision 1.2 2001/05/20 01:21:20 jongfoster
84 * Version 2.9.4 checkin.
85 * - Merged popupfile and cookiefile, and added control over PCRS
86 * filtering, in new "permissionsfile".
87 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
88 * file error you now get a message box (in the Win32 GUI) rather
89 * than the program exiting with no explanation.
90 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
92 * - Removed tabs from "config"
93 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
94 * - Bumped up version number.
96 * Revision 1.1.1.1 2001/05/15 13:58:58 oes
97 * Initial import of version 2.9.3 source tree
100 *********************************************************************/
107 #include <sys/types.h>
110 #include <sys/stat.h>
113 #if !defined(_WIN32) && !defined(__OS2__)
118 #include "killpopup.h"
121 const char killpopup_h_rcs[] = KILLPOPUP_H_VERSION;
123 #ifdef FEATURE_KILL_POPUPS
125 /*********************************************************************
127 * Function : filter_popups
129 * Description : Filter the block of data that's been read from the server
130 * for javascript popup code and replace by syntactically
131 * neutral code of the same size.
132 * Raise the CSP_FLAG_MODIFIED flag on success.
135 * 1 : buff = Buffer to scan and modify. Null terminated.
136 * 2 : csp = Client state pointer
140 *********************************************************************/
141 void filter_popups(char *buff, struct client_state *csp)
143 char *start_p = NULL;
144 char *close_p = NULL;
148 * replace the window.open( with a harmless JavaScript replacement
149 * (notice the two single quotes)
151 while ((start_p = strstr(buff, "window.open(")) != NULL)
155 strncpy(start_p, "1;''.concat(", 12);
156 log_error(LOG_LEVEL_POPUPS, "Blocked popup window open");
157 csp->flags |= CSP_FLAG_MODIFIED;
162 * replace the .resizeTo( with a harmless JavaScript replacement
164 while ((start_p = strstr(buff, ".resizeTo(")) != NULL)
168 strncpy(start_p, ".scrollTo(", 10);
169 log_error(LOG_LEVEL_POPUPS, "Blocked popup window resize");
170 csp->flags |= CSP_FLAG_MODIFIED;
175 * Filter onUnload and onExit
177 start_p = strstr(buff, "<body");
178 if (!start_p) start_p = strstr(buff, "<BODY");
179 if (!start_p) start_p = strstr(buff, "<Body");
180 if (!start_p) start_p = strstr(buff, "<BOdy");
183 close_p = strchr(start_p, '>');
186 /* we are now between <body and the ending > */
187 p = strstr(start_p, "onUnload");
190 strncpy(p, "_nU_", 4);
191 csp->flags |= CSP_FLAG_MODIFIED;
193 p = strstr(start_p, "onExit");
196 strncpy(p, "_nE_", 4);
197 csp->flags |= CSP_FLAG_MODIFIED;
204 #endif /* def FEATURE_KILL_POPUPS */