/* Let's jump right into it - parse a cookie, as received from a website. */ bool receiveCookie(const char *url, const char *str) { struct cookie *c; const char *p, *q, *server; char *date, *s; debugPrint(3, "cookie %s", str); server = getHostURL(url); if (server == 0 || !*server) return false; /* Cookie starts with name=value. If we can't get that, go home. */ for (p = str; *p != ';' && *p; p++) ; for (q = str; *q != '='; q++) if (!*q || q >= p) return false; if (str == q) return false; c = allocZeroMem(sizeof(struct cookie)); c->tail = false; c->name = pullString1(str, q); ++q; if (p - q > 0) c->value = pullString1(q, p); else c->value = emptyString; c->server = cloneString(server); if (date = extractHeaderParam(str, "expires")) { c->expires = parseHeaderDate(date); nzFree(date); } else if (date = extractHeaderParam(str, "max-age")) { int n = stringIsNum(date); if (n >= 0) { time_t now = time(0); c->expires = now + n; } nzFree(date); } c->path = extractHeaderParam(str, "path"); if (!c->path) { /* The url indicates the path for this cookie, if a path is not explicitly given */ const char *dir, *dirend; getDirURL(url, &dir, &dirend); c->path = pullString1(dir, dirend); } else { if (!c->path[0] || c->path[strlen(c->path) - 1] != '/') c->path = appendString(c->path, "/"); if (c->path[0] != '/') c->path = prependString(c->path, "/"); } if (!(c->domain = extractHeaderParam(str, "domain"))) { c->domain = cloneString(server); } else { /* Is this safe for tail-matching? */ const char *domtemp = c->domain; if (domtemp[0] == '.') domtemp++; if (!domainSecurityCheck(server, domtemp)) { nzFree(c->domain); c->domain = cloneString(server); } else { /* It's safe to do tail-matching with this domain. */ c->tail = true; /* Guarantee that it does in fact start with dot, prepending if necessary.. */ if (c->domain[0] != '.') c->domain = prependString(c->domain, "."); } } if (s = extractHeaderParam(str, "secure")) { c->secure = true; nzFree(s); } cookieForLibcurl(c); freeCookie(c); nzFree(c); return true; } /* receiveCookie */
/* After createJavaContext, set up the document object and other variables * and methods that are base for client side DOM. */ void setupJavaDom(void) { jsobjtype w = cw->winobj; // window object jsobjtype d = cw->docobj; // document object jsobjtype nav; // navigator object jsobjtype navpi; // navigator plugins jsobjtype navmt; // navigator mime types jsobjtype hist; // history object struct MIMETYPE *mt; struct utsname ubuf; int i; char save_c; static const char *languages[] = { 0, "english", "french", "portuguese", "polish", "german", "russian", }; extern const char *startWindowJS; /* self reference through several names */ set_property_object(w, "window", w); set_property_object(w, "self", w); set_property_object(w, "parent", w); set_property_object(w, "top", w); nav = instantiate(w, "navigator", 0); if (!nav) return; /* some of the navigator is in startwindow.js; the runtime properties are here. */ set_property_string(nav, "userLanguage", languages[eb_lang]); set_property_string(nav, "language", languages[eb_lang]); set_property_string(nav, "appVersion", version); set_property_string(nav, "vendorSub", version); set_property_string(nav, "userAgent", currentAgent); uname(&ubuf); set_property_string(nav, "oscpu", ubuf.sysname); set_property_string(nav, "platform", ubuf.machine); /* Build the array of mime types and plugins, * according to the entries in the config file. */ navpi = instantiate_array(nav, "plugins"); if (navpi == NULL) return; navmt = instantiate_array(nav, "mimeTypes"); if (navmt == NULL) return; mt = mimetypes; for (i = 0; i < maxMime; ++i, ++mt) { int len; /* po is the plugin object and mo is the mime object */ jsobjtype po = instantiate_array_element(navpi, i, 0); jsobjtype mo = instantiate_array_element(navmt, i, 0); if (po == NULL || mo == NULL) return; set_property_object(mo, "enabledPlugin", po); set_property_string(mo, "type", mt->type); set_property_object(navmt, mt->type, mo); set_property_string(mo, "description", mt->desc); set_property_string(mo, "suffixes", mt->suffix); /* I don't really have enough information from the config file to fill * in the attributes of the plugin object. * I'm just going to fake it. * Description will be the same as that of the mime type, * and the filename will be the program to run. * No idea if this is right or not. */ set_property_string(po, "description", mt->desc); set_property_string(po, "filename", mt->program); /* For the name, how about the program without its options? */ len = strcspn(mt->program, " \t"); save_c = mt->program[len]; mt->program[len] = 0; set_property_string(po, "name", mt->program); mt->program[len] = save_c; } hist = instantiate(w, "history", 0); if (hist == NULL) return; set_property_string(hist, "current", cw->fileName); /* Since there is no history in edbrowse, the rest is left to startwindow.js */ /* the js window/document setup script. * These are all the things that do not depend on the platform, * OS, configurations, etc. */ jsRunScript(w, startWindowJS, "StartWindow", 1); // Document properties that must be set after startwindow.js. // Most of these use the setters in the URL class. set_property_string(d, "referrer", cw->referrer); instantiate_url(d, "URL", cw->fileName); instantiate_url(d, "location", cw->fileName); instantiate_url(w, "location", cw->fileName); set_property_string(d, "domain", getHostURL(cw->fileName)); docCookie(d); } /* setupJavaDom */