From 14a96f6418fff80c2c751eda838fa50cb9e3030d Mon Sep 17 00:00:00 2001 From: "shrutiv%netscape.com" Date: Thu, 20 Sep 2001 17:43:23 +0000 Subject: [PATCH] Fix for bug 96914: Support customizing proxies Backend code for customizing proxies (r=tao) --- cck/ib/ib.cpp | 149 ++++++++++++++++++++++++++++++++++++++++++++++- cck/ib/script.ib | 14 +++++ 2 files changed, 161 insertions(+), 2 deletions(-) diff --git a/cck/ib/ib.cpp b/cck/ib/ib.cpp index 1098f14d3765..f56488b64611 100644 --- a/cck/ib/ib.cpp +++ b/cck/ib/ib.cpp @@ -436,6 +436,130 @@ int ModifyDTD(CString xpifile, CString entity, CString newvalue) return TRUE; } +void ModifyEntity1(char *buffer, CString entity, CString newvalue) +{ + CString buf(buffer); + entity = entity + "\""; + + int i = buf.Find(entity); + if (i == -1) return; + + i = buf.ReverseFind('"'); + if (i == -1) return; + + CString tempbuf = buf; + tempbuf.Left(i); + int j = tempbuf.ReverseFind('"'); + if (j == -1) return; + + buf.Delete(j, i-j); + buf.Insert(j, newvalue); + + strcpy(buffer, (char *)(LPCTSTR) buf); +} + +int ModifyJS1(CString xpifile, CString entity, CString newvalue) +{ + CString newfile = xpifile + ".new"; + int rv = TRUE; + char *fgetsrv; + + // Read in all.js file and make substitutions + FILE *srcf = fopen(xpifile, "r"); + FILE *dstf = fopen(newfile, "w"); + if (!srcf) + rv = FALSE; + else + { + int done = FALSE; + while (!done) + { + fgetsrv = fgets(buffer, sizeof(buffer), srcf); + done = feof(srcf); + if (!done) + { + if (!fgetsrv || ferror(srcf)) + { + rv = FALSE; + break; + } + ModifyEntity1(buffer, entity, newvalue); + fputs(buffer, dstf); + } + } + + fclose(srcf); + fclose(dstf); + } + + remove(xpifile); + rename(newfile, xpifile); + + return TRUE; +} + +void ModifyEntity2(char *buffer, CString entity, CString newvalue) +{ + CString buf(buffer); + newvalue = " " + newvalue; + + int i = buf.Find(entity); + if (i == -1) return; + + i = buf.ReverseFind(')'); + if (i == -1) return; + + CString tempbuf = buf; + tempbuf.Left(i); + int j = tempbuf.ReverseFind(','); + if (j == -1) return; + + buf.Delete(j+1, i-j-1); + buf.Insert(j+1, newvalue); + + strcpy(buffer, (char *)(LPCTSTR) buf); +} + +int ModifyJS2(CString xpifile, CString entity, CString newvalue) +{ + CString newfile = xpifile + ".new"; + int rv = TRUE; + char *fgetsrv; + + // Read in all.js file and make substitutions + FILE *srcf = fopen(xpifile, "r"); + FILE *dstf = fopen(newfile, "w"); + if (!srcf) + rv = FALSE; + else + { + int done = FALSE; + while (!done) + { + fgetsrv = fgets(buffer, sizeof(buffer), srcf); + done = feof(srcf); + if (!done) + { + if (!fgetsrv || ferror(srcf)) + { + rv = FALSE; + break; + } + ModifyEntity2(buffer, entity, newvalue); + fputs(buffer, dstf); + } + } + + fclose(srcf); + fclose(dstf); + } + + remove(xpifile); + rename(newfile, xpifile); + + return TRUE; +} + int interpret(char *cmd) { char *cmdname = strtok(cmd, "("); @@ -568,6 +692,8 @@ int interpret(char *cmd) else if ((strcmp(cmdname, "modifyDTD") == 0) || (strcmp(cmdname, "modifyJS") == 0) || + (strcmp(cmdname, "modifyJS1") == 0) || + (strcmp(cmdname, "modifyJS2") == 0) || (strcmp(cmdname, "modifyProperties") == 0)) { char *xpiname = strtok(NULL, ",)"); @@ -599,6 +725,10 @@ int interpret(char *cmd) ModifyJS(xpifile,entity,newvalue); else if (strcmp(cmdname, "modifyProperties") == 0) ModifyProperties(xpifile,entity,newvalue); + else if (strcmp(cmdname, "modifyJS1") == 0) + ModifyJS1(xpifile,entity,newvalue); + else if (strcmp(cmdname, "modifyJS2") == 0) + ModifyJS2(xpifile,entity,newvalue); else { // If the browser window's title bar text field is empty, @@ -675,7 +805,7 @@ void invisible() else if (!(Components[i].disabled) && !(Components[i].additional) && !(Components[i].invisible)) WritePrivateProfileString(Components[i].compname, "Attributes", "SELECTED|FORCE_UPGRADE", iniDstPath); else if (Components[i].additional && Components[i].launchapp && !(Components[i].invisible)) - WritePrivateProfileString(Components[i].compname, "Attributes", "SELECTED|LAUNCHAPP|ADDITIONAL", iniDstPath); + WritePrivateProfileString(Components[i].compname, "Attributes", "SELECTED|LAUNCHAPP|ADDITIONAL", iniDstPath); componentOrder++; } else @@ -1140,7 +1270,22 @@ int StartIB(CString parms, WIDGET *curWidget) CString setnewsRDF = tempPath +"\\newsaccount.rdf"; SetGlobal("NewsRDF",setnewsRDF); CreateNewsMenu(); - + + // Determine which proxy configuration is chosen + CString proxyConfigoption = GetGlobal("radioGroup2"); + if (proxyConfigoption == "3") + SetGlobal("ProxyConfig","2"); + else if (proxyConfigoption == "2") + SetGlobal("ProxyConfig","1"); + else + SetGlobal("ProxyConfig","0"); + // Determine which SOCKS version is chosen + CString socksVer = GetGlobal("socksv"); + if (socksVer == "SOCKS v4") + SetGlobal("SocksVersion","4"); + else + SetGlobal("SocksVersion","5"); + if (cdDir.Compare("1") ==0) { _mkdir((char *)(LPCTSTR) cdPath); diff --git a/cck/ib/script.ib b/cck/ib/script.ib index e92390a3af5a..3bf4fc344fcc 100644 --- a/cck/ib/script.ib +++ b/cck/ib/script.ib @@ -23,6 +23,20 @@ modifyProperties(regus.xpi,bin/chrome/US.jar,locale/US/aim-region/region.propert modifyProperties(regus.xpi,bin/chrome/US.jar,locale/US/messenger-region/region-ns.properties,messenger.throbber.url,%AnimatedLogoURL%) modifyProperties(regus.xpi,bin/chrome/US.jar,locale/US/messenger-region/region-ns.properties,addressbook.throbber.url,%AnimatedLogoURL%) modifyJS(browser.xpi,no.jar,bin/defaults/pref/all-ns.js,general.useragent.vendorComment,%OrganizationName%) +modifyJS1(browser.xpi,no.jar,bin/defaults/pref/all.js,network.proxy.ftp,%FTPproxyname%) +modifyJS1(browser.xpi,no.jar,bin/defaults/pref/all.js,network.proxy.gopher,%Gopherproxyname%) +modifyJS1(browser.xpi,no.jar,bin/defaults/pref/all.js,network.proxy.http,%HTTPproxyname%) +modifyJS1(browser.xpi,no.jar,bin/defaults/pref/all.js,network.proxy.ssl,%SSLproxyname%) +modifyJS1(browser.xpi,no.jar,bin/defaults/pref/all.js,network.proxy.socks,%SOCKShostname%) +modifyJS1(browser.xpi,no.jar,bin/defaults/pref/all.js,network.proxy.no_proxies_on,%NoProxyname%) +modifyJS1(browser.xpi,no.jar,bin/defaults/pref/all.js,network.proxy.autoconfig_url,%autoproxyurl%) +modifyJS2(browser.xpi,no.jar,bin/defaults/pref/all.js,network.proxy.type,%ProxyConfig%) +modifyJS2(browser.xpi,no.jar,bin/defaults/pref/all.js,network.proxy.ftp_port,%FTPportno%) +modifyJS2(browser.xpi,no.jar,bin/defaults/pref/all.js,network.proxy.gopher_port,%Gopherportno%) +modifyJS2(browser.xpi,no.jar,bin/defaults/pref/all.js,network.proxy.http_port,%HTTPportno%) +modifyJS2(browser.xpi,no.jar,bin/defaults/pref/all.js,network.proxy.ssl_port,%SSLportno%) +modifyJS2(browser.xpi,no.jar,bin/defaults/pref/all.js,network.proxy.socks_port,%SOCKSportno%) +modifyJS2(browser.xpi,no.jar,bin/defaults/pref/all.js,network.proxy.socks_version,%SocksVersion%) addrdfFile(deflenus.xpi,no.jar,bin/defaults/isp,mailaccount.rdf,%IspRDF%) addrdfFile(regus.xpi,no.jar,bin/defaults/isp/US,mailaccount.rdf,%IspRDF%) addrdfFile(deflenus.xpi,no.jar,bin/defaults/isp,newsaccount.rdf,%NewsRDF%)