/* ============================================================================ * Douglas Thrift's Search Engine License * * Copyright (C) 2002, Douglas Thrift. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * 3. The end-user documentation included with the redistribution, if any, must * include the following acknowledgment: * * "This product includes software developed by Douglas Thrift * (http://computers.douglasthrift.net/searchengine/)." * * Alternately, this acknowledgment may appear in the software itself, if * and wherever such third-party acknowledgments normally appear. * * 4. The names "Douglas Thrift" and "Douglas Thrift's Search Engine" must not * be used to endorse or promote products derived from this software without * specific prior written permission. For written permission, please visit * http://www.douglasthrift.net/contact.cgi for contact information. * * 5. Products derived from this software may not be called "Douglas Thrift's * Search Engine", nor may "Douglas Thrift's Search Engine" appear in their * name, without prior written permission. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ============================================================================ */ // Douglas Thrift's Search Engine HTTP Handler // // Douglas Thrift // // HttpHandler.cpp #include "HttpHandler.h" #ifdef _WIN32 #define PATH_SEPARATOR "\\" #define ENV_SEPARATOR ';' #else #define PATH_SEPARATOR "/" #define ENV_SEPARATOR ':' #endif HttpHandler::HttpHandler() { string arguments = "(Ljava/lang/String;ILjava/lang/String;Ljava/lang/Strin" + string("g;Ljava/lang/String;)Ljava/lang/String;"); begin = 0; // setJarPath(); // options[0].optionString = jarPath; // memset(&vm_args, 0, sizeof (vm_args)); // vm_args.version = JNI_VERSION_1_4; // vm_args.nOptions = 1; // vm_args.options = options; // status = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args); // if (status != JNI_ERR) // { // cls = env->FindClass("HttpConnector"); // if (cls != 0) // { // mid = env->GetStaticMethodID(cls, "connect", arguments.c_str()); // } // } } HttpHandler::~HttpHandler() { // if (status != JNI_ERR) // { // jvm->DestroyJavaVM(); // } // delete [] jarPath; } bool HttpHandler::connect(URL &url, bool head) { bool answer = false; // if (status != JNI_ERR) // { // if (cls != 0) // { // if (mid != 0) // { // jstring addressJ = env->NewStringUTF(url.getAddress().c_str()); // jint portJ = url.getPort(); // jstring pathJ = env->NewStringUTF(url.getPath().c_str()); // jstring programNameJ = env->NewStringUTF(programName.c_str()); // jstring programVersionJ = // env->NewStringUTF(programVersion.c_str()); // jstring pageJ = (jstring)env->CallStaticObjectMethod(cls, mid, // addressJ, portJ, pathJ, programNameJ, programVersionJ); // const char* pageC = env->GetStringUTFChars(pageJ, 0); // page = pageC; // env->ReleaseStringUTFChars(pageJ, pageC); // if (page != "unknown host\n" && page != "io exception\n" && // page != "bad headers\n") answer = true; // } // } // } return answer; } HttpHandler& HttpHandler::getline(string& line, char endline) { int end = page.find(endline, begin); int newline = page.find('\n', begin); if (newline < end || end == string::npos) { end = newline; } line = page.substr(begin, end - begin); if (end == string::npos) { begin = end; } else { begin = end + 1; } return *this; } bool HttpHandler::good() { bool answer = true; if (begin >= page.length()) { answer = false; } else if (begin == string::npos) { answer = false; } return answer; } void HttpHandler::clear() { begin = 0; page = ""; } /*void HttpHandler::setJarPath() { const string jarFile = "HttpConnector.jar"; string jarFilePath = jarFile; ifstream fin(jarFilePath.c_str()); if (!fin.is_open()) { unsigned end = program.rfind(PATH_SEPARATOR); if (end != string::npos) { string path = program.substr(0, end); jarFilePath = path + PATH_SEPARATOR + jarFile; fin.open(jarFilePath.c_str()); if (!fin.is_open()) { cerr << program << ": Could not find required file: " << jarFile << "\n"; exit(1); } else { fin.close(); } } else { string envPath = getenv("PATH"); if (debug) cerr << "envPath = " << envPath << "\n"; unsigned begin = 0; do { unsigned end = envPath.find(ENV_SEPARATOR, begin); string path = envPath.substr(begin, end); if (debug) cerr << "path = " << path << "\n"; jarFilePath = path + PATH_SEPARATOR + jarFile; fin.open(jarFilePath.c_str()); if (fin.is_open()) { fin.close(); break; } begin = end != string::npos ? end + 1 : string::npos; } while (begin < envPath.length()); if (begin == string::npos) { cerr << program << ": Could not find required file: " << jarFile << "\n"; exit(1); } } } else { fin.close(); } string jarPath = "-Djava.class.path=" + jarFilePath; // this->jarPath = new char[jarPath.length()]; // strcpy(this->jarPath, jarPath.c_str()); }*/