Subj : Re: Still unsolved problem To : netscape.public.mozilla.jseng From : "Stu" Date : Wed Jun 04 2003 11:11 am "Brendan Eich" wrote in message news:3EDCE2B6.2050508@meer.net... > > I'm really stuck with this, I don't want to have to release my project with > > the debug JS32.dll!!, > > You have to show your code for people to help. Also any makefile you're > using. I tried mailing you the other day saying exactly this, but your > mail address isn't valid. > > /be > Yep I'm on a corporate LAN so no email address permitted on external Newsgroups. My code is now very large but I'll snip out the basics of what I'm trying to do this probably wont compile as a project once I've done this it just to show you what I'm doing. Here goes, JavaScript: function FindProxyForURL(url,host) { if (isInNet(host, "10.0.0.0", "255.0.0.0")) { return "DIRECT" } return "PROXY xap1.intra.xan.com:8080; PROXY xap2.intra.xan.com:8080; DIRECT" } C++ Code Gleb header containing C implementations of Functions called from the Javascript #ifndef GLEB_H #define GLEB_H #include "jsapi.h" #include "jscompat.h" #include "jspubtd.h" #include #include "xp_reg.h" //#include //#include #include extern int Interpret(int,char**); /* The javascript methods */ JSBool proxy_weekdayRange(JSContext *mc, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval); JSBool proxy_dateRange(JSContext *mc, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval); JSBool proxy_timeRange(JSContext *mc, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval); JSBool proxy_isPlainHostName(JSContext *mc, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval); JSBool proxy_dnsDomainLevels(JSContext *mc, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval); JSBool proxy_dnsDomainIs(JSContext *mc, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval); JSBool proxy_localHostOrDomainIs(JSContext *mc, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval); JSBool proxy_isResolvable(JSContext *mc, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval); JSBool proxy_dnsResolve(JSContext *mc, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval); JSBool proxy_isInNet(JSContext *mc, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval); JSBool proxy_myIpAddress(JSContext *mc, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval); JSBool proxy_regExpMatch(JSContext *mc, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval); static JSFunctionSpec pc_methods[] = { { "weekdayRange", proxy_weekdayRange, 3}, { "dateRange", proxy_dateRange, 7}, { "timeRange", proxy_timeRange, 7}, { "isPlainHostName", proxy_isPlainHostName, 1}, { "dnsDomainLevels", proxy_dnsDomainLevels, 1}, { "dnsDomainIs", proxy_dnsDomainIs, 2}, { "localHostOrDomainIs", proxy_localHostOrDomainIs, 2}, { "isResolvable", proxy_isResolvable, 1}, { "dnsResolve", proxy_dnsResolve, 1}, { "isInNet", proxy_isInNet, 3}, { "myIpAddress", proxy_myIpAddress, 0}, { "regExpMatch", proxy_regExpMatch, 2}, { "shExpMatch", proxy_regExpMatch, 2}, { NULL, NULL, 0} }; #endif One example from Gelb.c JSBool proxy_isInNet(JSContext *mc, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval) { if (argc >= 3 && JSVAL_IS_STRING(argv[0]) && JSVAL_IS_STRING(argv[1]) && JSVAL_IS_STRING(argv[2])) { const char *ipstr = JS_GetStringBytes(JSVAL_TO_STRING(argv[0])); char *ip = proxy_dns_resolve(ipstr); const char *patstr = JS_GetStringBytes(JSVAL_TO_STRING(argv[1])); const char *maskstr = JS_GetStringBytes(JSVAL_TO_STRING(argv[2])); if (ip) { unsigned long host = convert_addr(ip); unsigned long pat = convert_addr(patstr); unsigned long mask = convert_addr(maskstr); free(ip); if ((mask & host) == (mask & pat)) { /*TRACEMSG(("~~~~~~~~~~~~ isInNet(%s(%s), %s, %s) returns TRUE\n", ipstr, ip, patstr, maskstr)); */ *rval = JSVAL_TRUE; return JS_TRUE; } } } /* TRACEMSG(("~~~~~~~~~~~~ isInNet() returns FALSE\n")); */ *rval = JSVAL_FALSE; return JS_TRUE; } jsproxy.cpp #define XP_PC #include "jsapi.h" #include "jsprf.h" #include "gleb.h" #include "jsproxy.h" #include "btogurl.h" #ifndef JSFILE #define JSFILE #endif bool CProxyAutoConf::load_auto_conf_file(const char* pAclUrlIn) { jsval rval; if(pAclUrlIn == NULL) return FALSE; strcpy (m_AutoConfFileUrl, pAclUrlIn); bool bFinished = FALSE; bool bSuccessfulFetch =FALSE; char SavedAclPath[128]; strcpy(SavedAclPath, ""); do { bFinished = fetch_acl_poll(&bSuccessfulFetch, &SavedAclPath[0]); Sleep(100); } while (bFinished == FALSE); if (!bSuccessfulFetch) { //Failed to Download a new ACL if(m_SavedAclFilePath == "") return FALSE; // There has never been a successful ACL stored } m_SavedAclFilePath = SavedAclPath; rt = JS_NewRuntime (10000000L); cx = JS_NewContext(rt, 8192); //if cx doesnot have a value, end the program here if (cx == NULL) { printf ("cx does not have a value\n"); return FALSE; } JS_SetErrorReporter(cx, my_ErrorReporter); glob = JS_NewObject(cx, &global_class, 0, 0); if (!JS_InitStandardClasses(cx, glob)) return FALSE; localobj = JS_DefineObject(cx, glob, "localObject", &its_class, 0, JSPROP_ENUMERATE); if (!localobj) return FALSE; if (!JS_DefineProperties(cx, localobj, its_props)) return FALSE; if (!JS_DefineFunctions(cx, glob, pc_methods)) { return FALSE; } proxyscript = JS_CompileFile(cx, glob, m_SavedAclFilePath); if (proxyscript == NULL) { printf ("Compilation failed\n"); return FALSE; } JSBool success = JS_ExecuteScript(cx, glob, proxyscript, &rval); if (success == JS_FALSE) { printf ("Execution failed\n"); return FALSE; } return TRUE; } char* CProxyAutoConf::find_proxies_for_url(const char* pURL) { char strHost[256]; char strURL[256]; JSString *host, *url; jsval jsargv[2]; jsval rval; JSString *str; const char* functionname = "FindProxyForURL"; if(m_AutoConfFileUrl == NULL) { printf("Error Empty Auto Config File URL String\n"); return NULL; } strcpy (strURL, pURL); //strcpy (strHost, "www.e-peopleserve.com"); char* protocolstr = strstr(strURL, "http://"); if (protocolstr == NULL) { const char* host = strtok(strURL, "/"); strcpy (strHost, host); } else { //strtok(protocolstr, "http://"); protocolstr = protocolstr + 7; const char* host = strtok(protocolstr, "/"); strcpy (strHost, host); } if (m_iProxyRequestCounter >= DEFAULT_MAX_REQUESTS_PER_ACL_LOAD_) { m_bAclLoaded = load_auto_conf_file(m_AutoConfFileUrl); if (m_bAclLoaded) { m_iProxyRequestCounter =0; } } if (!m_bAclLoaded) { printf("Error unable to load an ACL file\n"); return NULL; //Fail situation error out } url = JS_NewStringCopyZ(cx, strURL); host = JS_NewStringCopyZ(cx, strHost); jsargv[0] = STRING_TO_JSVAL (url); jsargv[1] = STRING_TO_JSVAL (host); /* Assume the script is compiled and executing at this point */ m_iProxyRequestCounter++; JSBool executed = JS_CallFunctionName(cx, glob, functionname, 2, jsargv, &rval); if (executed != JS_TRUE) { printf ("Execution failed\n"); str = JS_ValueToString(cx, rval); return NULL; } str = JS_ValueToString(cx, rval); printf("Call function script result: %s\n", JS_GetStringBytes(str)); return JS_GetStringBytes(str); } main.c #include "jsproxy.h" /////////////////////////////////////////////////////////////// int main(int argc, char* argv[]) { char* AclURL = "file://d:\\jsproxy\\working\\bin\\default.pac"; char* URL = "www.e-peopleserve.com/help.htm"; CProxyAutoConf m_ProxyAutoConf; m_ProxyAutoConf.set_acl_url(AclURL); char* Proxy = m_ProxyAutoConf.find_proxies_for_url(URL); if (Proxy == NULL) { printf("An error occurred Exiting"); return -1; } printf("End of Main Function\n"); return 0; } What am I doing thats causing the CallFunctionName() to Error with "ReferenceError: host is not defined" but only with the release Dll. Another thing, I move the C function call from the Javascript an just leave and return "DIRECT" as the FindProxyForURL function body I get a successful CallFunctionName with both the Release and Debug Js32dll. Is the Release Dll somehow tied to the release compilation of the C++ project? I've always been compiling my C++ project as debug? Thanks all, Stu. .