QVariant CQJsonModel:: headerData(int section, Qt::Orientation orientation, int role) const { if (orientation != Qt::Horizontal) return CQBaseModel::headerData(section, orientation, role); if (role == Qt::DisplayRole) { QString str; if (headerString(section, str)) return QVariant(str); } else if (role == Qt::ToolTipRole) { QString str; if (headerString(section, str)) { CQBaseModelType type = columnType(section); str += ":" + typeName(type); return QVariant(str); } } else if (role == Qt::EditRole) { return QVariant(); } else { return CQBaseModel::headerData(section, orientation, role); } return QVariant(); }
void CurlDownload::addHeaders(const ResourceRequest& request) { if (request.httpHeaderFields().size() > 0) { struct curl_slist* headers = 0; HTTPHeaderMap customHeaders = request.httpHeaderFields(); HTTPHeaderMap::const_iterator end = customHeaders.end(); for (HTTPHeaderMap::const_iterator it = customHeaders.begin(); it != end; ++it) { const String& value = it->value; String headerString(it->key); if (value.isEmpty()) // Insert the ; to tell curl that this header has an empty value. headerString.append(";"); else { headerString.append(": "); headerString.append(value); } CString headerLatin1 = headerString.latin1(); headers = curl_slist_append(headers, headerLatin1.data()); } if (headers) { curl_easy_setopt(m_curlHandle, CURLOPT_HTTPHEADER, headers); m_customHeaders = headers; } } }
size_t HttpConnection::write_headers(void *ptr, size_t size, size_t nmemb, std::map<std::string, std::string> *headers) { char* headerLine = reinterpret_cast<char *>(ptr); // convert to string std::string headerString(headerLine, (size * nmemb)); std::string key; std::string val; // find colon size_t colon_loc = headerString.find(":"); if (colon_loc == std::string::npos) { key = headerString; val = ""; } else { key = headerString.substr(0, colon_loc); val = headerString.substr(colon_loc + 1, std::string::npos); } // Lowercase the key (for consistency) and remove spaces std::transform(key.begin(), key.end(), key.begin(), ::tolower); key.erase(std::remove_if(key.begin(), key.end(), ::isspace), key.end()); val.erase(std::remove_if(val.begin(), val.end(), ::isspace), val.end()); LOG_DEBUG("Received header %s with value %s", key.c_str(), val.c_str()); (*headers)[key] = val; return size * nmemb; }
void ArchiveReader::ReadAllHeaders() { std::string headerString(BlockSize, '\0'); m_ArchiveFile.read(&headerString[0], BlockSize); try { while (m_HeaderReader.ReadHeader(headerString) && m_ArchiveFile) { m_HeaderCollection.push_back(m_HeaderReader.GetHeader()); m_ArchiveFile.seekg(m_HeaderReader.GetNextHeaderPosition()); m_ArchiveFile.read(&headerString[0], BlockSize); } } catch(const HeaderReaderException& headerReaderException) { std::cout << "HeaderReaderException " << std::endl; std::cout << headerReaderException.what() << std::endl; } // for (auto fileHeader : m_HeaderCollection) // { // std::cout << std::endl; // std::cout << "File name: " << fileHeader.GetFileName() << std::endl; // std::cout << "File type: " << fileHeader.GetFileType() << std::endl; // std::cout << std::setbase(8); // std::cout << "File permissions: " << fileHeader.GetFilePermissions() << std::endl; // std::cout << std::setbase(10); // std::cout << "File size: " << fileHeader.GetFileSize() << std::endl; // std::cout << "File start pos: " << fileHeader.GetFileStartPosition() << std::endl; // std::cout << "File end pos: " << fileHeader.GetFileEndPosition() << std::endl; // } // std::cout << "######################################### All " << m_HeaderCollection.size() << " headers was read ###################################################" << std::endl; }
void Options::SaveOptions() { NativeString configurationPath(NativeString(mMaxInterface->GetDir(APP_PLUGCFG_DIR))); URI configurationPathUri(URI::nativePathToUri(configurationPath.toUtf8String())); URI optionsFileUri(configurationPathUri, CONFIGURATION_FILE_NAME); // NativeString filename = configurationPath + "\\" + CONFIGURATION_FILE_NAME; FILE* file; errno_t error = fopen_s(&file, optionsFileUri.toNativePath().c_str(), "wb"); if ( error ) return; // Write down a standard INI header to allow MaxScript edition. String headerString("[" + CONFIGURATION_HEADER_NAME + "]\r\n"); fwrite(headerString.data(), headerString.length(), 1, file); // Write down the options, one by one, in the form: 'option=X\n' writeOption(file, OPTION_NORMALS_NAME, mNormals ); writeOption(file, OPTION_TRIANGULAT_NAME, mTriangulate ); writeOption(file, OPTION_XREFS_NAME, mIncludeXrefs ); writeOption(file, OPTION_TANGENTS_NAME, mTangents ); writeOption(file, OPTION_ANIMATIONS_NAME, mAnimations ); writeOption(file, OPTION_SAMPLEANIMATIONS_NAME, mSampleAnimation ); writeOption(file, OPTION_CREATECLIP_NAME, mCreateClip ); writeOption(file, OPTION_BAKEMATRICES_NAME, mBakeMatrices ); writeOption(file, OPTION_RELATIVEPATHS_NAME, mRelativePaths ); writeOption(file, OPTION_CHECKIFANIMATIONISANIMATED_NAME, mCheckIfAnimationIsAnimated ); writeOption(file, OPTION_ANIMATIONSTART_NAME, mAnimationStart ); writeOption(file, OPTION_ANIMATIONEND_NAME, mAnimationEnd ); writeOption(file, OPTION_COPY_IMAGES_NAME, mCopyImages ); writeOption(file, OPTION_EXPORT_USERDEFINED_PROPERTIES_NAME, mExportUserDefinedProperties ); fclose(file); }
void ResourceHandleManager::initializeHandle(ResourceHandle* job) { KURL kurl = job->request().url(); // Remove any fragment part, otherwise curl will send it as part of the request. kurl.setRef(""); ResourceHandleInternal* d = job->getInternal(); String url = kurl.string(); if (kurl.isLocalFile()) { String query = kurl.query(); // Remove any query part sent to a local file. if (!query.isEmpty()) url = url.left(url.find(query)); // Determine the MIME type based on the path. d->m_response.setMimeType(MIMETypeRegistry::getMIMETypeForPath(url)); } d->m_handle = curl_easy_init(); #ifndef NDEBUG if (getenv("DEBUG_CURL")) curl_easy_setopt(d->m_handle, CURLOPT_VERBOSE, 1); #endif curl_easy_setopt(d->m_handle, CURLOPT_PRIVATE, job); curl_easy_setopt(d->m_handle, CURLOPT_ERRORBUFFER, m_curlErrorBuffer); curl_easy_setopt(d->m_handle, CURLOPT_WRITEFUNCTION, writeCallback); curl_easy_setopt(d->m_handle, CURLOPT_WRITEDATA, job); curl_easy_setopt(d->m_handle, CURLOPT_HEADERFUNCTION, headerCallback); curl_easy_setopt(d->m_handle, CURLOPT_WRITEHEADER, job); curl_easy_setopt(d->m_handle, CURLOPT_AUTOREFERER, 1); curl_easy_setopt(d->m_handle, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(d->m_handle, CURLOPT_MAXREDIRS, 10); curl_easy_setopt(d->m_handle, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_easy_setopt(d->m_handle, CURLOPT_SHARE, m_curlShareHandle); curl_easy_setopt(d->m_handle, CURLOPT_DNS_CACHE_TIMEOUT, 60 * 5); // 5 minutes // FIXME: Enable SSL verification when we have a way of shipping certs // and/or reporting SSL errors to the user. if (ignoreSSLErrors) curl_easy_setopt(d->m_handle, CURLOPT_SSL_VERIFYPEER, false); // enable gzip and deflate through Accept-Encoding: curl_easy_setopt(d->m_handle, CURLOPT_ENCODING, ""); // url must remain valid through the request ASSERT(!d->m_url); // url is in ASCII so latin1() will only convert it to char* without character translation. d->m_url = strdup(url.latin1().data()); curl_easy_setopt(d->m_handle, CURLOPT_URL, d->m_url); if (m_cookieJarFileName) { curl_easy_setopt(d->m_handle, CURLOPT_COOKIEFILE, m_cookieJarFileName); curl_easy_setopt(d->m_handle, CURLOPT_COOKIEJAR, m_cookieJarFileName); } struct curl_slist* headers = 0; if (job->request().httpHeaderFields().size() > 0) { HTTPHeaderMap customHeaders = job->request().httpHeaderFields(); HTTPHeaderMap::const_iterator end = customHeaders.end(); for (HTTPHeaderMap::const_iterator it = customHeaders.begin(); it != end; ++it) { String key = it->first; String value = it->second; String headerString(key); headerString.append(": "); headerString.append(value); CString headerLatin1 = headerString.latin1(); headers = curl_slist_append(headers, headerLatin1.data()); } } if ("GET" == job->request().httpMethod()) curl_easy_setopt(d->m_handle, CURLOPT_HTTPGET, TRUE); else if ("POST" == job->request().httpMethod()) setupPOST(job, &headers); else if ("PUT" == job->request().httpMethod()) setupPUT(job, &headers); else if ("HEAD" == job->request().httpMethod()) curl_easy_setopt(d->m_handle, CURLOPT_NOBODY, TRUE); if (headers) { curl_easy_setopt(d->m_handle, CURLOPT_HTTPHEADER, headers); d->m_customHeaders = headers; } }
void ResourceHandleManager::startJob(ResourceHandle* job) { ResourceHandleInternal* d = job->getInternal(); DeprecatedString url = job->request().url().url(); d->m_handle = curl_easy_init(); #ifndef NDEBUG if (getenv("DEBUG_CURL")) curl_easy_setopt(d->m_handle, CURLOPT_VERBOSE, 1); #endif curl_easy_setopt(d->m_handle, CURLOPT_PRIVATE, job); curl_easy_setopt(d->m_handle, CURLOPT_ERRORBUFFER, m_curlErrorBuffer); curl_easy_setopt(d->m_handle, CURLOPT_WRITEFUNCTION, writeCallback); curl_easy_setopt(d->m_handle, CURLOPT_WRITEDATA, job); curl_easy_setopt(d->m_handle, CURLOPT_HEADERFUNCTION, headerCallback); curl_easy_setopt(d->m_handle, CURLOPT_WRITEHEADER, job); curl_easy_setopt(d->m_handle, CURLOPT_AUTOREFERER, 1); curl_easy_setopt(d->m_handle, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(d->m_handle, CURLOPT_MAXREDIRS, 10); curl_easy_setopt(d->m_handle, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_easy_setopt(d->m_handle, CURLOPT_SHARE, m_curlShareHandle); curl_easy_setopt(d->m_handle, CURLOPT_DNS_CACHE_TIMEOUT, 60 * 5); // 5 minutes // enable gzip and deflate through Accept-Encoding: curl_easy_setopt(d->m_handle, CURLOPT_ENCODING, ""); // url must remain valid through the request ASSERT(!d->m_url); d->m_url = strdup(url.ascii()); curl_easy_setopt(d->m_handle, CURLOPT_URL, d->m_url); if (m_cookieJarFileName) { curl_easy_setopt(d->m_handle, CURLOPT_COOKIEFILE, m_cookieJarFileName); curl_easy_setopt(d->m_handle, CURLOPT_COOKIEJAR, m_cookieJarFileName); } if (job->request().httpHeaderFields().size() > 0) { struct curl_slist* headers = 0; HTTPHeaderMap customHeaders = job->request().httpHeaderFields(); HTTPHeaderMap::const_iterator end = customHeaders.end(); for (HTTPHeaderMap::const_iterator it = customHeaders.begin(); it != end; ++it) { String key = it->first; String value = it->second; String headerString(key); headerString.append(": "); headerString.append(value); CString headerLatin1 = headerString.latin1(); headers = curl_slist_append(headers, headerLatin1.data()); } curl_easy_setopt(d->m_handle, CURLOPT_HTTPHEADER, headers); d->m_customHeaders = headers; } if ("GET" == job->request().httpMethod()) curl_easy_setopt(d->m_handle, CURLOPT_HTTPGET, TRUE); else if ("POST" == job->request().httpMethod()) setupPOST(job); else if ("PUT" == job->request().httpMethod()) setupPUT(job); else if ("HEAD" == job->request().httpMethod()) curl_easy_setopt(d->m_handle, CURLOPT_NOBODY, TRUE); CURLMcode ret = curl_multi_add_handle(m_curlMultiHandle, d->m_handle); // don't call perform, because events must be async // timeout will occur and do curl_multi_perform if (ret && ret != CURLM_CALL_MULTI_PERFORM) { #ifndef NDEBUG printf("Error %d starting job %s\n", ret, job->request().url().url().ascii()); #endif job->cancel(); return; } }