String cookies(const KURL& url) { DeprecatedString str = url.url(); char domainBuffer[SIZE_OF_LATIN1_BUFFERS]; char pathBuffer[SIZE_OF_LATIN1_BUFFERS]; int tl_domainLocationInUrlBegins = str.find("://") + SIZE_OF_COLONSLASHSLASH; int tl_domainLocationInUrlEnds = str.find("/",tl_domainLocationInUrlBegins) - 1; int tl_pathLocationInUrlEnds = str.findRev("/"); strncpy(domainBuffer, str.ascii() + tl_domainLocationInUrlBegins, tl_domainLocationInUrlEnds - tl_domainLocationInUrlBegins + 1); domainBuffer[tl_domainLocationInUrlEnds - tl_domainLocationInUrlBegins + 1] = '\0'; strncpy(pathBuffer, str.ascii() + tl_domainLocationInUrlEnds + 1, tl_pathLocationInUrlEnds - tl_domainLocationInUrlEnds); pathBuffer[tl_pathLocationInUrlEnds - tl_domainLocationInUrlEnds] = '\0'; char* cookStr = WebKitApollo::g_HostFunctions->getJavaScriptCookies(domainBuffer,pathBuffer); if(!cookStr) { return String(); } String cookieString(cookStr); ::free(cookStr); return cookieString; }
void setCookies(const KURL& url, const KURL& policyURL, const String& value) { DeprecatedString str = url.url(); DeprecatedString result("Set-Cookie:"); DeprecatedString val = value.deprecatedString(); //add everything in the cookie result.append(val); //Check if it had appended domain, path bool noDomainSet = !val.contains(DeprecatedString("domain=")); bool noPathSet = !val.contains(DeprecatedString("path=")); if(noDomainSet || noPathSet) { char pathBuffer[SIZE_OF_LATIN1_BUFFERS]; char domainBuffer[SIZE_OF_LATIN1_BUFFERS]; int tl_domainLocationInUrlBegins = str.find("://") + SIZE_OF_COLONSLASHSLASH; int tl_domainLocationInUrlEnds = str.find("/",tl_domainLocationInUrlBegins) - 1; result.append(';'); if(noDomainSet) { str.copyLatin1(domainBuffer, tl_domainLocationInUrlBegins, tl_domainLocationInUrlEnds - tl_domainLocationInUrlBegins + 1); domainBuffer[tl_domainLocationInUrlEnds - tl_domainLocationInUrlBegins + 1] = '\0'; result.append(DeprecatedString(" domain=")); result.append(DeprecatedString::fromLatin1(domainBuffer)); result.append(';'); } if(noPathSet) { int tl_pathLocationInUrlEnds = str.findRev("/"); str.copyLatin1(pathBuffer, tl_domainLocationInUrlEnds + 1, // 1 because it'll include '/' tl_pathLocationInUrlEnds - tl_domainLocationInUrlEnds ); pathBuffer[tl_pathLocationInUrlEnds = tl_domainLocationInUrlEnds] = '\0'; result.append(DeprecatedString(" path=")); result.append(DeprecatedString::fromLatin1(pathBuffer)); result.append(';'); } } if(val.startsWith(DeprecatedString("https://"))) { result.append(DeprecatedString(" secure")); } //Connect with Runtime. // WebKitApollo::g_HostFunctions->setJavaScriptCookie(result.latin1()); }
bool HTMLFormElement::formData(FormData &form_data) const { DeprecatedCString enc_string = ""; // used for non-multipart data DeprecatedString str = m_acceptcharset.deprecatedString(); str.replace(',', ' '); DeprecatedStringList charsets = DeprecatedStringList::split(' ', str); TextEncoding encoding(InvalidEncoding); Frame *frame = document()->frame(); for (DeprecatedStringList::Iterator it = charsets.begin(); it != charsets.end(); ++it) { if ((encoding = TextEncoding((*it).latin1())).isValid()) break; } if (!encoding.isValid()) { if (frame) encoding = TextEncoding(frame->encoding().latin1()); else encoding = TextEncoding(Latin1Encoding); } for (unsigned i = 0; i < formElements.size(); ++i) { HTMLGenericFormElement* current = formElements[i]; FormDataList lst(encoding); if (!current->disabled() && current->appendFormData(lst, m_multipart)) { for (DeprecatedValueListConstIterator<FormDataListItem> it = lst.begin(); it != lst.end(); ++it) { if (!m_multipart) { // handle ISINDEX / <input name=isindex> special // but only if its the first entry if ( enc_string.isEmpty() && (*it).m_data == "isindex" ) { ++it; enc_string += encodeCString( (*it).m_data ); } else { if(!enc_string.isEmpty()) enc_string += '&'; enc_string += encodeCString((*it).m_data); enc_string += "="; ++it; enc_string += encodeCString((*it).m_data); } } else { DeprecatedCString hstr("--"); hstr += m_boundary.deprecatedString().latin1(); hstr += "\r\n"; hstr += "Content-Disposition: form-data; name=\""; hstr += (*it).m_data.data(); hstr += "\""; // if the current type is FILE, then we also need to // include the filename if (current->hasLocalName(inputTag) && static_cast<HTMLInputElement*>(current)->inputType() == HTMLInputElement::FILE) { DeprecatedString path = static_cast<HTMLInputElement*>(current)->value().deprecatedString(); // FIXME: This won't work if the filename includes a " mark, // or control characters like CR or LF. This also does strange // things if the filename includes characters you can't encode // in the website's character set. hstr += "; filename=\""; hstr += encoding.fromUnicode(path.mid(path.findRev('/') + 1), true); hstr += "\""; if (!static_cast<HTMLInputElement*>(current)->value().isEmpty()) { DeprecatedString mimeType = frame ? frame->mimeTypeForFileName(path).deprecatedString() : DeprecatedString(); if (!mimeType.isEmpty()) { hstr += "\r\nContent-Type: "; hstr += mimeType.ascii(); } } } hstr += "\r\n\r\n"; ++it; // append body form_data.appendData(hstr.data(), hstr.length()); const FormDataListItem &item = *it; size_t dataSize = item.m_data.size(); if (dataSize != 0) form_data.appendData(item.m_data, dataSize - 1); else if (!item.m_path.isEmpty()) form_data.appendFile(item.m_path); form_data.appendData("\r\n", 2); } } } } if (m_multipart) enc_string = ("--" + m_boundary.deprecatedString() + "--\r\n").ascii(); form_data.appendData(enc_string.data(), enc_string.length()); return true; }