Beispiel #1
0
// add suffix and prefix when necessary
void fixPlugin(StringBuffer& plugin)
{
    if (stricmp(plugin.str()+plugin.length()-sizeof(SharedObjectExtension)+1,SharedObjectExtension)==0)
        return;
    plugin.insert(0,SharedObjectPrefix);
    plugin.append(SharedObjectExtension);
}
bool CWsLoggingServiceEx::onGetTransactionSeed(IEspContext& context, IEspGetTransactionSeedRequest& req, IEspGetTransactionSeedResponse& resp)
{
    bool bRet = false;
    try
    {
        if (!context.validateFeatureAccess(WSLOGGING_ACCESS, SecAccess_Write, false))
            throw MakeStringException(EspLoggingErrors::WSLoggingAccessDenied, "Failed to get transaction  seed. Permission denied.");

        LOGServiceType serviceType = LGSTGetTransactionSeed;
        for (unsigned int x = 0; x < loggingAgentThreads.size(); x++)
        {
            IUpdateLogThread* loggingThread = loggingAgentThreads[x];
            if (!loggingThread->hasService(serviceType))
                continue;

            IEspLogAgent* loggingAgent = loggingThread->getLogAgent();
            bRet = loggingAgent->getTransactionSeed(req, resp);
            break;
        }
    }
    catch (IException* e)
    {
        StringBuffer errorStr;
        e->errorMessage(errorStr);
        errorStr.insert(0, "Failed to get Transaction Seed: ");
        ERRLOG("%s", errorStr.str());
        resp.setStatusCode(-1);
        resp.setStatusMessage(errorStr.str());
        e->Release();
    }
    return bRet;
}
Beispiel #3
0
 void GermanStemmer::resubstitute(StringBuffer& buffer) {
   for ( size_t c = 0; c < buffer.length(); c++ ) {
     if ( buffer.charAt( c ) == _T('*') ) {
       TCHAR x = buffer.charAt( c - 1 );
       buffer.setCharAt( c, x );
     }
     else if ( buffer.charAt( c ) == _T('$') ) {
       buffer.setCharAt( c, 's' );
       TCHAR ch[] = { _T('c'), _T('h')};
       buffer.insert( c + 1, ch );
     }
     else if ( buffer.charAt( c ) == _T('§') ) {
       buffer.setCharAt( c, _T('c') );
       buffer.insert( c + 1, _T('h') );
     }
     else if ( buffer.charAt( c ) == _T('%') ) {
       buffer.setCharAt( c, _T('e') );
       buffer.insert( c + 1, _T('i') );
     }
     else if ( buffer.charAt( c ) == _T('&') ) {
       buffer.setCharAt( c, _T('i') );
       buffer.insert( c + 1, _T('e') );
     }
     else if ( buffer.charAt( c ) == _T('#') ) {
       buffer.setCharAt( c, _T('i') );
       buffer.insert( c + 1, _T('g') );
     }
     else if ( buffer.charAt( c ) == _T('!') ) {
       buffer.setCharAt( c, _T('s') );
       buffer.insert( c + 1, _T('t') );
     }
   }
 }
bool CLoggingManager::getTransactionSeed(StringBuffer& transactionSeed, StringBuffer& status)
{
    if (!initialized)
        throw MakeStringException(-1,"LoggingManager not initialized");

    bool bRet = false;
    try
    {
        Owned<IEspGetTransactionSeedRequest> req =  createGetTransactionSeedRequest();
        Owned<IEspGetTransactionSeedResponse> resp =  createGetTransactionSeedResponse();
        transactionSeed.set("Seed");

        bRet = getTransactionSeed(*req, *resp);
        if (bRet && !resp->getStatusCode())
        {
            const char* seed = resp->getSeedId();
            if (!seed || !*seed)
                status.set("Failed to get Transaction Seed");
            else
            {
                transactionSeed.set(seed);
                status.set("Transaction Seed returned.");
                bRet = true;
            }
        }
        else
        {
            const char* statusMsg = resp->getStatusMessage();
            if (statusMsg && *statusMsg)
                status.setf("Failed to get Transaction Seed: %s", statusMsg);
            else
                status.set("Failed to get Transaction Seed");
        }
    }
    catch (IException* e)
    {
        e->errorMessage(status);
        status.insert(0, "Failed to get Transaction Seed: ");
        ERRLOG("%s",status.str());
        e->Release();
    }

    return bRet;
}
void GermanStemmer::resubstitute(StringBuffer& buffer) {
    for ( size_t i = 0; i < buffer.length(); i++ ) {
#ifdef _UCS2
        TCHAR c = buffer.charAt(i);
#else
        unsigned char c = buffer.charAt(i);
#endif
        if ( c == _T('*') ) {
            buffer.setCharAt( i, buffer.charAt( i - 1 ) );
        }
        else if ( c == _T('$') ) {
            buffer.setCharAt( i, 's' );
            buffer.insert( i + 1, _T("ch"), 2 );
        }
        else if ( c == 0xa7 ) { // section sign in UTF-16
            buffer.setCharAt( i, _T('c') );
            buffer.insert( i + 1, _T('h') );
        }
        else if ( c == _T('%') ) {
            buffer.setCharAt( i, _T('e') );
            buffer.insert( i + 1, _T('i') );
        }
        else if ( c == _T('&') ) {
            buffer.setCharAt( i, _T('i') );
            buffer.insert( i + 1, _T('e') );
        }
        else if ( c == _T('#') ) {
            buffer.setCharAt( i, _T('i') );
            buffer.insert( i + 1, _T('g') );
        }
        else if ( c == _T('!') ) {
            buffer.setCharAt( i, _T('s') );
            buffer.insert( i + 1, _T('t') );
        }
    }
}
StringBuffer& MessageGenerator::generateMessage(const char* method, const char* templatemsg, StringBuffer& message)
{
    if(!method || !*method)
        return message;

    if(http_tracelevel >= 1)
        fprintf(m_logfile, "Automatically generating message from schema for method \"%s\"%s", method, LT);
    
    initCfgDefValues(method);

    if (m_isRoxie)
        genRoxieMessage(templatemsg, message);
    else 
        genNonRoxieMessage(method, templatemsg, message);

    if (m_gfile.get())
    {
        Owned<IFile> tf = createIFile(m_gfile.get());
        {
            Owned<IFileIO> tio = tf->open(IFOcreaterw);
            tio->write(0, message.length(), message.str());
        }
    }

    else if(http_tracelevel > 0)
    {
        fprintf(stderr, "Request for method %s has been generated:\n", method);
        if(http_tracelevel >= 5)
            fprintf(stderr, "%s\n", message.str());

        char c = 'n';
        if(!(m_globals && m_globals->getPropBool("useDefault")))
        {
            fprintf(stderr, "Do you want to modify it?[n/y]");
            c = getchar();
        }

        if(c == 'y' || c == 'Y' || m_keepfile)
        {
            StringBuffer tmpfname;
            tmpfname.append(method);
            addFileTimestamp(tmpfname, false);
#ifdef _WIN32
            tmpfname.insert(0, "c:\\Temp\\");
#else
            tmpfname.insert(0, "/tmp/");
#endif
            Owned<IFile> tf = createIFile(tmpfname.str());
            {
                Owned<IFileIO> tio = tf->open(IFOcreaterw);
                tio->write(0, message.length(), message.str());
            }
            
            if(c == 'y' || c == 'Y')
            {
                StringBuffer cmdline;
#ifdef _WIN32
                cmdline.appendf("notepad.exe %s", tmpfname.str());
                STARTUPINFO sinfo;
                PROCESS_INFORMATION pinfo;
                GetStartupInfo(&sinfo);
                CreateProcess(0, (char*)cmdline.str(), 0, 0, false, 0, 0, 0, &sinfo, &pinfo);
                WaitForSingleObject(pinfo.hProcess, INFINITE);
#else
                cmdline.appendf("vi %s", tmpfname.str());
                if (system(cmdline.str()) == -1)
                    throw MakeStringException(-1, "MessageGenerator::generateMessage: could not execute command %s", cmdline.str());
#endif
                message.clear().loadFile(tmpfname.str(), true);
            }

            if(!m_keepfile)
                tf->remove();
            else
                printf("A copy is saved at %s (unless you specified another location)\n", tmpfname.str());
        }
    }

    return message;
}
Beispiel #7
0
int HttpClient::sendSoapRequest(const char* url, const char* soapaction, const char* infile)
{
    if(!url || !*url || !infile || !*infile)
        return 0;

    StringBuffer protocol, user, passwd, port, path;
    m_host.clear();
    SplitURL(url, protocol, user, passwd, m_host, port, path);

    if(port.length() > 0)
        m_port = atoi(port.str());
    else
    {
        if(protocol.length() > 0 && stricmp(protocol.str(), "https") == 0)
            m_port = 443;
        else
            m_port = 80;
    }

    if(stricmp(protocol.str(), "HTTPS") == 0)
        m_use_ssl = true;

    if(m_use_ssl)
    {
#ifdef USE_OPENSSL
        if(m_ssctx.get() == NULL)
            m_ssctx.setown(createSecureSocketContext(ClientSocket));
#else
        throw MakeStringException(-1, "HttpClient: failure to create SSL socket - OpenSSL not enabled in build");
#endif
    }

    StringBuffer request;

    try
    {
        request.loadFile(infile, true);
    }
    catch(IException* e)
    {
        StringBuffer errmsg;
        printf("\nerror loading file %s - %s", infile, e->errorMessage(errmsg).str());
        return -1;
    }
    catch(...)
    {
        printf("\nerror loading file %s", infile);
        return -1;
    }

    if(request.length() == 0)
    {
        printf("input is empty\n");
        return -1;
    }


    const char* ptr = request.str();
    while(*ptr == ' ')
        ptr++;
    if(*ptr != '<')
    {
        printf("the input should be xml\n");
        return -1;
    }

    if(strncmp(ptr, "<?xml", 5) != 0 && strncmp(ptr, "<soap:Envelope", 14) != 0)
    {
        request.insert(0, "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:wsse=\"http://schemas.xmlsoap.org/ws/2002/04/secext\"><soap:Body>");
        request.append("</soap:Body></soap:Envelope>");
    }

    StringBuffer headers;

    headers.appendf("POST %s HTTP/1.1\r\n", path.str());
    headers.append("Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*\r\n");
    headers.append("Accept-Language: en-us\r\n");
    headers.append("Content-Type: text/xml\r\n");
    if(soapaction && *soapaction)
        headers.appendf("SOAPAction: \"%s\"\r\n", soapaction);
    //headers.append("Accept-Encoding: gzip, deflate\r\n");
    headers.append("User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n");
    headers.appendf("Content-Length: %d\r\n", request.length());
    headers.append("Host: ").append(m_host.str());
    if(m_port != 80)
        headers.appendf(":%d", m_port);
    headers.append("\r\n");

    if(user.length() > 0)
    {
        StringBuffer auth, abuf;
        abuf.appendf("%s:%s", user.str(), passwd.str());
        JBASE64_Encode(abuf.str(), abuf.length(), auth);
        headers.appendf("Authorization: Basic %s\r\n", auth.str());
    }

    headers.append("\r\n");


    request.insert(0, headers.str());

    return sendRequest(request);
}
bool QueryHelper::doit(FILE * fp)
{
    Owned<IClientWUCreateRequest> creq = wuclient->createWUCreateRequest();
    Owned<IClientWUCreateResponse> cresp = wuclient->WUCreate(creq);
    const IMultiException* excep = &cresp->getExceptions();
    if(excep != NULL && excep->ordinality() > 0)
    {
        StringBuffer msg;
        excep->errorMessage(msg);
        printf("%s\n", msg.str());
        return false;
    }

    IConstECLWorkunit* wu = &cresp->getWorkunit();
    if(!wu)
    {
        printf("can't create workunit\n");
        return false;
    }

    Owned<IClientWUUpdateRequest> ureq = wuclient->createWUUpdateRequest();
    ureq->setWuid(wu->getWuid());

    // Make a workUnit
    StringBuffer jobname;
    if(globals->hasProp("jobname"))
        jobname.append(globals->queryProp("jobname"));

    StringBuffer ecl;
    if (globals->getProp("ecl", ecl))
    {
        if (ecl.length() && ecl.charAt(0)=='@')
        {
            StringBuffer filename(ecl.str()+1);
            ecl.clear().loadFile(filename);
            if (jobname.length() == 0)
                splitFilename(filename, NULL, NULL, &jobname, NULL);
        }
        ureq->setQueryText(ecl.str());
    }
    else if (globals->hasProp("main"))
        ureq->setQueryMainDefinition(globals->queryProp("main"));
    else if (globals->hasProp("attr"))
        ureq->setQueryText(globals->queryProp("attr"));

    if (globals->getPropInt("compileOnly", 0)!=0)
        ureq->setAction(WUActionCompile);
    if (jobname.length())
        ureq->setJobname(jobname);

    IArrayOf<IEspDebugValue> dvals;
    IArrayOf<IEspApplicationValue> avals;
    StringBuffer xmlParams;

    Owned<IPropertyIterator> it = globals->getIterator();
    bool xmlSeen = false;
    ForEach(*it)
    {
        const char * key = it->getPropKey();
        if (key && strlen(key)>1)
        {
            if(key[0] == '-')
            {
                if (key[1] == 'f')
                {
                    Owned<IEspDebugValue> dval = createDebugValue();
                    dval->setName(&key[2]);
                    dval->setValue(globals->queryProp(key));
                    dvals.append(*dval.getLink());
                }
                //All other options are ignored.
            }
            else if(key[0] == '_')
            {
                Owned<IEspApplicationValue> aval = createApplicationValue();
                aval->setApplication("eclplus");
                aval->setName(&key[1]);
                aval->setValue(globals->queryProp(key));
                avals.append(*aval.getLink());
            }
            else if(key[0] == '/')
            {
                if (xmlSeen)
                    throw MakeStringException(0, "query option must not be used with stored or /, and cannot appear more than once");
                // The / form is expected to be used for scalars, so xmlEncode is appropriate.
                // To pass sets or datasets, use the xml= version
                xmlParams.appendf("<%s>", &key[1]);
                encodeXML(globals->queryProp(key), xmlParams);
                xmlParams.appendf("</%s>", &key[1]);
            }
            else if(stricmp(key, "stored")==0)
            {
                if (xmlSeen)
                    throw MakeStringException(0, "query option must not be used with stored or /, and cannot appear more than once");
                const char *xml = globals->queryProp(key);
                try
                {
                    Owned<IPropertyTree> checkValid = createPTreeFromXMLString(xml);
                }
                catch (IException *E)
                {
                    StringBuffer msg;
                    E->errorMessage(msg);
                    E->Release();
                    throw MakeStringException(0, "Invalid xml: %s", msg.str());
                }
                xmlParams.append(xml);
            }
            else if(stricmp(key, "query")==0)
            {
                if (xmlSeen || xmlParams.length())
                    throw MakeStringException(0, "query option must not be used with stored or /, and cannot appear more than once");
                xmlSeen = true;
                StringBuffer xml;
                if (!globals->getProp(key, xml))
                    throw MakeStringException(0, "Invalid value for query= parameter");
                if (xml.length() && xml.charAt(0)=='@')
                {
                    StringBuffer filename(xml.str()+1);
                    xml.clear().loadFile(filename);
                }
                try
                {
                    Owned<IPropertyTree> checkValid = createPTreeFromXMLString(xml);
                }
                catch (IException *E)
                {
                    StringBuffer msg;
                    E->errorMessage(msg);
                    E->Release();
                    throw MakeStringException(0, "Invalid xml: %s", msg.str());
                }
                xmlParams.append(xml);
            }
        }
    }
    if(dvals.length() > 0)
        ureq->setDebugValues(dvals);
    if(avals.length() > 0)
        ureq->setApplicationValues(avals);
    if (xmlParams.length())
    {
        if (!xmlSeen)
        {
            xmlParams.insert(0, "<Query>");
            xmlParams.append("</Query>");
        }
        ureq->setXmlParams(xmlParams);
    }

    Owned<IClientWUUpdateResponse> uresp = wuclient->WUUpdate(ureq);
    const IMultiException* uexcep = &uresp->getExceptions();
    if(uexcep != NULL && uexcep->ordinality() > 0)
    {
        StringBuffer msg;
        uexcep->errorMessage(msg);
        printf("%s\n", msg.str());
        return false;
    }

    // Execute it
    return doSubmitWorkUnit(fp, wu->getWuid(), globals->queryProp("cluster"));
}
void GermanStemmer::substitute(StringBuffer& buffer) {
    substCount = 0;

    for ( size_t i = 0; i < buffer.length(); i++ ) {
#ifdef _UCS2
        TCHAR c = buffer.charAt(i);
#else
        unsigned char c = buffer.charAt(i);
#endif
        // Replace the second char of a pair of the equal characters with an asterisk
        if ( i > 0 && c == buffer.charAt ( i - 1 )  ) {
            buffer.setCharAt( i, _T('*') );
        }
        // Substitute Umlauts.
        else if ( c  == 0xe4 ) {
            buffer.setCharAt( i, _T('a') );
        }
        else if ( c == 0xf6 ) {
            buffer.setCharAt( i, _T('o') );
        }
        else if ( c == 0xfc ) {
            buffer.setCharAt( i, _T('u') );
        }
        // Fix bug so that 'ß' at the end of a word is replaced.
        else if ( c == 0xdf ) {
            buffer.setCharAt( i, _T('s') );
            buffer.insert( i + 1, _T('s') );
            substCount++;
        }
        // Take care that at least one character is left left side from the current one
        if ( i < buffer.length() - 1 ) {
            // Masking several common character combinations with an token
            if ( ( i < buffer.length() - 2 ) && c == _T('s') &&
                    buffer.charAt( i + 1 ) == _T('c') && buffer.charAt( i + 2 ) == _T('h') )
            {
                buffer.setCharAt( i, _T('$') );
                buffer.deleteChars( i + 1, i + 3 );
                substCount =+ 2;
            }
            else if ( c == _T('c') && buffer.charAt( i + 1 ) == _T('h') ) {
                buffer.setCharAt( i, 0xa7 ); // section sign in UTF-16
                buffer.deleteCharAt( i + 1 );
                substCount++;
            }
            else if ( c == _T('e') && buffer.charAt( i + 1 ) == _T('i') ) {
                buffer.setCharAt( i, _T('%') );
                buffer.deleteCharAt( i + 1 );
                substCount++;
            }
            else if ( c == _T('i') && buffer.charAt( i + 1 ) == _T('e') ) {
                buffer.setCharAt( i, _T('&') );
                buffer.deleteCharAt( i + 1 );
                substCount++;
            }
            else if ( c == _T('i') && buffer.charAt( i + 1 ) == _T('g') ) {
                buffer.setCharAt( i, _T('#') );
                buffer.deleteCharAt( i + 1 );
                substCount++;
            }
            else if ( c == _T('s') && buffer.charAt( i + 1 ) == _T('t') ) {
                buffer.setCharAt( i, _T('!') );
                buffer.deleteCharAt( i + 1 );
                substCount++;
            }
        }
    }
}
Beispiel #10
0
    void GermanStemmer::substitute(StringBuffer& buffer) {
      substCount = 0;

      for ( size_t c = 0; c < buffer.length(); c++ ) {
        // Replace the second char of a pair of the equal characters with an asterisk
        if ( c > 0 && buffer.charAt( c ) == buffer.charAt ( c - 1 )  ) {
          buffer.setCharAt( c, _T('*') );
        }
        // Substitute Umlauts.
        else if ( buffer.charAt( c ) == _T('ä') ) {
          buffer.setCharAt( c, _T('a') );
        }
        else if ( buffer.charAt( c ) == _T('ö') ) {
          buffer.setCharAt( c, _T('o') );
        }
        else if ( buffer.charAt( c ) == _T('ü') ) {
          buffer.setCharAt( c, _T('u') );
        }
        // Fix bug so that 'ß' at the end of a word is replaced.
        else if ( buffer.charAt( c ) == _T('ß') ) {
            buffer.setCharAt( c, _T('s') );
            buffer.insert( c + 1, _T('s') );
            substCount++;
        }
        // Take care that at least one character is left left side from the current one
        if ( c < buffer.length() - 1 ) {
          // Masking several common character combinations with an token
          if ( ( c < buffer.length() - 2 ) && buffer.charAt( c ) == _T('s') &&
            buffer.charAt( c + 1 ) == _T('c') && buffer.charAt( c + 2 ) == _T('h') )
          {
            buffer.setCharAt( c, _T('$') );
            buffer.deleteChars( c + 1, c + 3 );
            substCount =+ 2;
          }
          else if ( buffer.charAt( c ) == _T('c') && buffer.charAt( c + 1 ) == _T('h') ) {
            buffer.setCharAt( c, _T('§') );
            buffer.deleteCharAt( c + 1 );
            substCount++;
          }
          else if ( buffer.charAt( c ) == _T('e') && buffer.charAt( c + 1 ) == _T('i') ) {
            buffer.setCharAt( c, _T('%') );
            buffer.deleteCharAt( c + 1 );
            substCount++;
          }
          else if ( buffer.charAt( c ) == _T('i') && buffer.charAt( c + 1 ) == _T('e') ) {
            buffer.setCharAt( c, _T('&') );
            buffer.deleteCharAt( c + 1 );
            substCount++;
          }
          else if ( buffer.charAt( c ) == _T('i') && buffer.charAt( c + 1 ) == _T('g') ) {
            buffer.setCharAt( c, _T('#') );
            buffer.deleteCharAt( c + 1 );
            substCount++;
          }
          else if ( buffer.charAt( c ) == _T('s') && buffer.charAt( c + 1 ) == _T('t') ) {
            buffer.setCharAt( c, _T('!') );
            buffer.deleteCharAt( c + 1 );
            substCount++;
          }
        }
      }
    }