Example #1
0
string html_table_code(const string &in)
{
  if (in.size()==0)
    return " ";
  else {
    return encodeXML(in);
  }
}
const StringBuffer &CEspApplicationPort::getAppFrameHtml(time_t &modified, const char *inner, StringBuffer &html, IEspContext* ctx)
{
    if (!xslp)
       throw MakeStringException(0,"Error - CEspApplicationPort XSLT processor not initialized");

    bool embedded_url=(inner&&*inner);

    StringBuffer params;
    bool needRefresh = true;
    if (!getUrlParams(ctx->queryRequestParameters(), params))
    {
        if (params.length()==0)
            needRefresh = false;
        if (ctx->getClientVersion()>0)
        {
            params.appendf("%cver_=%g", params.length()?'&':'?', ctx->getClientVersion());
            needRefresh = true;
        }
    }

    if (needRefresh || embedded_url || !appFrameHtml.length())
    {
        int passwordDaysRemaining = scPasswordExpired;//-1 means dont display change password screen
#ifdef _USE_OPENLDAP
        ISecUser* user = ctx->queryUser();
        ISecManager* secmgr = ctx->querySecManager();
        if(user && secmgr)
        {
            passwordDaysRemaining = user->getPasswordDaysRemaining();//-1 if expired, -2 if never expires
            int passwordExpirationDays = (int)secmgr->getPasswordExpirationWarningDays();
            if (passwordDaysRemaining == scPasswordNeverExpires || passwordDaysRemaining > passwordExpirationDays)
                passwordDaysRemaining = scPasswordExpired;
        }
#endif
        StringBuffer xml;
        StringBuffer encoded_inner;
        if(inner && *inner)
            encodeXML(inner, encoded_inner);

        // replace & with &amps;
        params.replaceString("&","&");

        xml.appendf("<EspApplicationFrame title=\"%s\" navWidth=\"%d\" navResize=\"%d\" navScroll=\"%d\" inner=\"%s\" params=\"%s\" passwordDays=\"%d\"/>",
            getESPContainer()->getFrameTitle(), navWidth, navResize, navScroll, (inner&&*inner) ? encoded_inner.str() : "?main", params.str(), passwordDaysRemaining);

        Owned<IXslTransform> xform = xslp->createXslTransform();
        xform->loadXslFromFile(StringBuffer(getCFD()).append("./xslt/appframe.xsl").str());
        xform->setXmlSource(xml.str(), xml.length()+1);
        xform->transform( (needRefresh || embedded_url) ? html.clear() : appFrameHtml.clear());
    }

    if (!needRefresh && !embedded_url)
        html.clear().append(appFrameHtml.str());

    static time_t startup_time = time(NULL);
    modified = startup_time;
    return html;
}
Example #3
0
void JabberClient::startHandshake()
{
    m_socket->writeBuffer.packetStart();
    m_socket->writeBuffer
    << "<stream:stream to=\""
    << encodeXML(getServer())
    << "\" xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\">\n";
    sendPacket();
}
Example #4
0
void MessageGenerator::doType(StringStack& parent, int indent, const char* tag, IXmlType* type, IPTree* tmplat, StringBuffer& buf)
{
    const char* typeName = type->queryName();
    if (type->isComplexType())
    {
        if (typeName && std::find(parent.begin(),parent.end(),typeName) != parent.end())
        {
            //DBGLOG("Recursive type: %s, ignored", typeName);
        }
        else 
        {
            int flds = type->getFieldCount();
            for (int i=0; i<flds; i++)
            {
                const char* fldName = type->queryFieldName(i);
                buf.appendf("<%s>", fldName);
                IPTree* existing = tmplat->queryBranch(fldName);
                if (typeName)
                    parent.push_back(typeName);
                if (existing)
                    doType(parent,indent+1,fldName, type->queryFieldType(i), existing, buf);
                else
                    doType(parent,indent+1,fldName,type->queryFieldType(i),buf);
                buf.appendf("</%s>", fldName);
                if (typeName)
                    parent.pop_back();
            }
        }
    }
    else if (type->isArray())
    {
        if (typeName && std::find(parent.begin(),parent.end(),typeName) != parent.end())
        {
            //DBGLOG("Recursive type: %s, ignored", typeName);
        }
        else 
        {
            const char* itemName = type->queryFieldName(0);
            IXmlType* itemType = type->queryFieldType(0);
            int childCount = tmplat->numChildren();
            if (typeName)
                parent.push_back(typeName);
            if (childCount>0)
            {
                Owned<IPTreeIterator> items = tmplat->getElements(itemName);
                for (items->first(); items->isValid(); items->next())
                {
                    buf.appendf("<%s>", itemName);
                    doType(parent,indent+2,itemName,itemType,&items->query(),buf);
                    buf.appendf("</%s>", itemName);
                }
            }
            else
            {
                for (int i=0; i<m_items; i++)
                {
                    buf.appendf("<%s>", itemName);
                    doType(parent,indent+2,itemName, itemType, buf);
                    buf.appendf("</%s>", itemName);
                }
                if (m_ecl2esp)
                    buf.appendf("<%s/>", itemName);
            }
            if (typeName)
                parent.pop_back();
        }
    }
    else
    {
        const char* existing = tmplat->queryProp(".");
        if (existing && isNotBlank(existing))
            encodeXML(existing,buf);
        else if (m_gx)
            buf.append("*** MISSING ***");
        else
        {
            DefValMap::const_iterator it = m_cfgDefValues.find(tag);
            if (it != m_cfgDefValues.end())
                buf.append(it->second.c_str());
            else
                type->getSampleValue(buf,tag);
        }
    }
}
Example #5
0
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"));
}
Example #6
0
bool gdioutput::writeHTML(const wstring &file, const string &title, int refreshTimeOut) const
{
  ofstream fout(file.c_str());

  if (fout.bad())
    return false;


  fout << "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" <<
          "          \"http://www.w3.org/TR/html4/loose.dtd\">\n\n";

  fout << "<html>\n<head>\n";
  fout << "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n";
  if (refreshTimeOut > 0)
    fout << "<meta http-equiv=\"refresh\" content=\"" << refreshTimeOut << "\">\n";


  fout << "<title>" << toUTF8(title) << "</title>\n";

  map< pair<gdiFonts, string>, pair<string, string> > styles;
  generateStyles(fout, false, TL, styles);

/*
  fout << "<style type=\"text/css\">\n";
  fout << "body {background-color: rgb(250, 250,255)}\n";
  fout << "h1 {font-family:arial,sans-serif;font-size:24px;font-weight:normal;white-space:nowrap}\n";
  fout << "h2 {font-family:arial,sans-serif;font-size:20px;font-weight:normal;white-space:nowrap}\n";
  fout << "h3 {font-family:arial,sans-serif;font-size:16px;font-weight:normal;white-space:nowrap}\n";
  fout << "p {font-family:arial,sans-serif;font-size:12px;font-weight:normal;white-space:nowrap}\n";
  fout << "</style>\n";
  */
  fout << "</head>\n";

  fout << "<body>\n";

  list<TextInfo>::const_iterator it = TL.begin();

  double yscale = 1.2;
  double xscale = 1.1;
  while (it!=TL.end()) {
    string estyle;
    if (it->format!=1 && it->format!=boldSmall) {
      if (it->format & textRight)
        estyle = " style=\"position:absolute;left:" +
            itos(int(xscale *it->xp)) + "px;top:"  + itos(int(yscale*it->yp)) + "px\"";
      else
        estyle = " style=\"position:absolute;left:" +
            itos(int(xscale *it->xp)) + "px;top:" + itos(int(yscale*it->yp)) + "px\"";

    }
    else {
      if (it->format & textRight)
         estyle = " style=\"font-weight:bold;position:absolute;left:" +
              itos(int(xscale *it->xp)) + "px;top:" + itos(int(yscale*it->yp)) +  "px\"";
      else
         estyle = " style=\"font-weight:bold;position:absolute;left:" +
              itos(int(xscale *it->xp)) + "px;top:" + itos(int(yscale*it->yp)) + "px\"";
    }
    string starttag, endtag;
    getStyle(styles, it->getGdiFont(), it->font, estyle, starttag, endtag);

    if (!it->text.empty())
      fout << starttag << toUTF8(encodeXML(it->text)) << endtag << endl;
    //fout << "</" << element << ">\n";
    ++it;
  }

  fout << "<p style=\"position:absolute;left:10px;top:" <<  int(yscale*MaxY)+15 << "px\">";

  char bf1[256];
  char bf2[256];
  GetTimeFormat(LOCALE_USER_DEFAULT, 0, NULL, NULL, bf2, 256);
  GetDateFormat(LOCALE_USER_DEFAULT, 0, NULL, NULL, bf1, 256);
  //fout << "Skapad av <i>MeOS</i>: " << bf1 << " "<< bf2 << "\n";
  fout << toUTF8(lang.tl("Skapad av ")) + "<a href=\"http://www.melin.nu/meos\" target=\"_blank\"><i>MeOS</i></a>: " << bf1 << " "<< bf2 << "\n";
  fout << "</p>\n";

  fout << "</body>\n";
  fout << "</html>\n";

  return false;
}