int parseParameters( boost::program_options::variables_map _vm, int ruleGen, execMyRuleInp_t *execMyRuleInp, char *inBuf ) { strArray_t strArray; int status, i, j; char *value; char line[MAX_NAME_LEN]; int promptF = 0; int labelF = 0; if ( inBuf == NULL || strcmp( inBuf, "null" ) == 0 ) { execMyRuleInp->inpParamArray = NULL; return 0; } memset( &strArray, 0, sizeof( strArray ) ); status = splitMultiStr( inBuf, &strArray ); if ( status < 0 ) { rodsLog( LOG_ERROR, "parseMsInputParam: parseMultiStr error, status = %d", status ); execMyRuleInp->inpParamArray = NULL; return status; } status = 0; resizeStrArray( &strArray, MAX_NAME_LEN ); value = strArray.value; if ( _vm.count( "file" ) ) { if ( _vm.count( "parameters" ) ) { std::vector< std::string > parameters; try { parameters = _vm["parameters"].as< std::vector< std::string > >(); } catch ( boost::bad_any_cast& e ) { std::cerr << "Bad parameter list provided to parseParameters\n"; std::cerr << "Use -h or --help for help\n"; return -1; } for ( size_t inx = 0; inx < parameters.size(); ++inx ) { std::string param = parameters.at(inx); /* using the values from the input line following -F <filename> */ /* each string is supposed to have to format label=value */ if ( param == "prompt" ) { promptF = 1; break; } if ( param == "default" || param.length() == 0 ) { continue; } else if ( param.at(0) == '*' ) { size_t eqInx; std::string tmpStr; if ( inx > 0 && labelF == 0 ) { return CAT_INVALID_ARGUMENT; } labelF = 1; if ( ( eqInx = param.find( "=" ) ) == std::string::npos ) { return CAT_INVALID_ARGUMENT; } tmpStr = param.substr( 0, eqInx ); for ( j = 0; j < strArray.len; j++ ) { if ( strstr( &value[j * strArray.size], tmpStr.c_str() ) == &value[j * strArray.size] ) { char *val = quoteString( param.c_str(), _vm.count( "string" ), 1 ); rstrcpy( &value[j * strArray.size], val, strArray.size ); free( val ); break; } } if ( j == strArray.len ) { printf( "Ignoring Argument \"%s\"\n", param.c_str() ); } } else { char *valPtr = &value[inx * strArray.size]; char *tmpPtr; if ( labelF == 1 ) { return CAT_INVALID_ARGUMENT; } if ( ( tmpPtr = strstr( valPtr, "=" ) ) != NULL ) { tmpPtr++; char *val = quoteString( param.c_str(), _vm.count( "string" ), 0 ); rstrcpy( tmpPtr, val, strArray.size - ( tmpPtr - valPtr + 1 ) ); free( val ); } } } } } for ( i = 0; i < strArray.len; i++ ) { char *valPtr = &value[i * strArray.size]; char *tmpPtr; if ( ( tmpPtr = strstr( valPtr, "=" ) ) != NULL ) { *tmpPtr = '\0'; tmpPtr++; if ( *tmpPtr == '$' ) { /* If $ is used as a value in the input file for label=value then the remaining command line arguments are taken as values. If no command line arguments are given then the user is prompted for the input value */ printf( "Default %s=%s\n New %s=", valPtr, tmpPtr + 1, valPtr ); if ( fgets( line, MAX_NAME_LEN, stdin ) == NULL ) { return CAT_INVALID_ARGUMENT; } size_t line_len = strlen( line ); if ( line_len > 0 && '\n' == line[line_len - 1] ) { line[line_len - 1] = '\0'; line_len--; } char *val = line_len > 0 ? quoteString( line, _vm.count( "string" ) && ruleGen, 0 ) : strdup( tmpPtr + 1 ); addMsParam( execMyRuleInp->inpParamArray, valPtr, STR_MS_T, val, NULL ); } else if ( promptF == 1 ) { /* the user has asked for prompting */ printf( "Current %s=%s\n New %s=", valPtr, tmpPtr, valPtr ); if ( fgets( line, MAX_NAME_LEN, stdin ) == NULL ) { return CAT_INVALID_ARGUMENT; } size_t line_len = strlen( line ); if ( line_len > 0 && '\n' == line[line_len - 1] ) { line[line_len - 1] = '\0'; line_len--; } char *val = line_len > 0 ? quoteString( line, _vm.count( "string" ) && ruleGen, 0 ) : strdup( tmpPtr ); addMsParam( execMyRuleInp->inpParamArray, valPtr, STR_MS_T, val, NULL ); } else if ( *tmpPtr == '\\' ) { /* first '\' is skipped. If you need to use '\' in the first letter add an additional '\' if you have to use '$' in the first letter add a '\' before that */ tmpPtr++; char *param = quoteString( tmpPtr, _vm.count( "string" ) && ruleGen, 0 ); if ( !ruleGen ) { trimQuotes( param ); } addMsParam( execMyRuleInp->inpParamArray, valPtr, STR_MS_T, param, NULL ); } else { char *param = quoteString( tmpPtr, _vm.count( "string" ) && ruleGen, 0 ); if ( !ruleGen ) { trimQuotes( param ); } addMsParam( execMyRuleInp->inpParamArray, valPtr, STR_MS_T, param, NULL ); } } else { rodsLog( LOG_ERROR, "parseMsInputParam: inpParam %s format error", valPtr ); status = CAT_INVALID_ARGUMENT; } } return status; }
QString MsgViewBase::messageText(Message *msg, bool bUnread) { QString options; QString info; QString status; const char *icon = "message"; const CommandDef *def = CorePlugin::m_plugin->messageTypes.find(msg->type()); if (def) icon = def->icon; bool bDirection = false; if (msg->type() == MessageStatus){ icon = "empty"; StatusMessage *sm = static_cast<StatusMessage*>(msg); Client *client = NULL; string clientStr; if (msg->client()) clientStr = msg->client(); int n = clientStr.find_last_of('.'); if (n >= 0){ clientStr = clientStr.substr(0, n); }else{ clientStr = ""; } if (!clientStr.empty()){ for (unsigned i = 0; i < getContacts()->nClients(); i++){ string n = getContacts()->getClient(i)->name(); if (n.length() < clientStr.length()) continue; n = n.substr(0, clientStr.length()); if (clientStr == n){ client = getContacts()->getClient(i); break; } } } if ((client == NULL) && getContacts()->nClients()) client = getContacts()->getClient(0); if (client){ for (def = client->protocol()->statusList(); def->text; def++){ if (def->id == sm->getStatus()){ icon = def->icon; status = i18n(def->text); break; } } } options += " direction=\"2\""; bDirection = true; }else{ MessageDef *m_def = (MessageDef*)(def->param); if (m_def->flags & MESSAGE_INFO){ options += " direction=\"2\""; bDirection = true; } } info = QString("<icon>%1</icon>") .arg(icon); QString contactName; if (msg->getFlags() & MESSAGE_RECEIVED){ if (!bDirection) options += " direction=\"1\""; Contact *contact = getContacts()->contact(msg->contact()); if (contact){ contactName = contact->getName(); if (contactName.isEmpty()){ Client *client = NULL; ClientDataIterator it(contact->clientData); void *data; while ((data = ++it) != NULL){ if (it.client()->dataName(data) == msg->client()){ client = it.client(); break; } } } } if (!bUnread){ for (list<msg_id>::iterator it = CorePlugin::m_plugin->unread.begin(); it != CorePlugin::m_plugin->unread.end(); ++it){ msg_id &m = (*it); if ((m.id == msg->id()) && (m.contact == msg->contact()) && (m.client == msg->client())){ bUnread = true; break; } } } if (bUnread) options += " unread=\"1\""; }else{ if (!bDirection) options += " direction=\"0\""; contactName = getContacts()->owner()->getName(); } if (contactName.isEmpty()) contactName = "???"; info += QString("<from>%1</from>") .arg(quoteString(contactName)); QString id = QString::number(msg->id()); id += ","; // <hack> // Terrible hack to set message bgcolor. We prefer to insert the entire history // in one chunk (since it's more efficient and causes less redraws), and there's // no way to set block's background color directly in Qt's HTML), so we make a note // of it in the HTML and set it retroactively in setBackground. if (!CorePlugin::m_plugin->getOwnColors() && (msg->getBackground() != 0xFFFFFFFF) && (msg->getForeground() != msg->getBackground())) id += QString::number(msg->getBackground()); // </hack> string client_str; if (msg->client()) client_str = msg->client(); if (!client_str.empty()){ id += ","; id += quoteString(client_str.c_str()); } if (m_cut.size()){ id += ","; id += QString::number(m_cut.size()); } info += "<id>"; info += id; info += "</id>"; QString icons; if (msg->getFlags() & MESSAGE_SECURE) options += " encrypted=\"1\""; if (msg->getFlags() & MESSAGE_URGENT) options += " urgent=\"1\""; if (msg->getFlags() & MESSAGE_LIST) options += " list=\"1\""; QString s; QDateTime t; t.setTime_t(msg->getTime()); info += s.sprintf("<time><date>%%1</date><hour>%02u</hour><minute>%02u</minute><second>%02u</second></time>", t.time().hour(), t.time().minute(), t.time().second()) .arg(formatDate(msg->getTime())); s = "<?xml version=\"1.0\"?><message"; s += options; s += ">"; s += info; QString msgText; if (msg->type() != MessageStatus){ msgText = msg->presentation(); if (msgText.isEmpty()){ unsigned type = msg->baseType(); CommandDef *cmd = CorePlugin::m_plugin->messageTypes.find(type); if (cmd){ MessageDef *def = (MessageDef*)(cmd->param); msgText = i18n(def->singular, def->plural, 1); int n = msgText.find("1 "); if (n == 0){ msgText = msgText.mid(2); }else if (n > 0){ msgText = msgText.left(n); } msgText = QString("<p>") + msgText + "</p>"; } QString text = msg->getRichText(); msgText += text; } }else{ msgText = status; } Event e(EventEncodeText, &msgText); e.process(); ViewParser parser(CorePlugin::m_plugin->getOwnColors(), CorePlugin::m_plugin->getUseSmiles()); msgText = parser.parse(msgText); s += "<body"; if (!CorePlugin::m_plugin->getOwnColors() && (msg->getForeground() != 0xFFFFFFFF) && (msg->getForeground() != msg->getBackground())) { s += " fgcolor=\"#"; s += QString::number(msg->getForeground(), 16).rightJustify(6, '0'); s += "\""; } // Some bright day might come when one could specify background color from inside Qt's richtext. // Meanwhile, this is useless: if ((msg->getBackground() != 0xFFFFFFFF) && (msg->getForeground() != msg->getBackground())) { s += " bgcolor=\"#"; s += QString::number(msg->getBackground(), 16).rightJustify(6, '0'); s += "\""; } s += ">"; // We pass the rich text quoted, since we're not sure of its' XML validity. // The XSL engine should copy it as-is (using xsl:value-of with disable-output-escaping="yes"). s += quoteString(QString(MSG_BEGIN) + msgText); s += "</body>"; s += "</message>"; XSL *p = xsl; if (p == NULL) p = CorePlugin::m_plugin->historyXSL; QString res = p->process(s); XslOutputParser outParser; res = outParser.parse(res); QString anchor = MSG_ANCHOR; anchor += id; anchor += "\">"; res = anchor + res; return res; }
void *ICQSearch::processEvent(Event *e) { if (e->type() == EventRandomChat){ m_randomUin = (unsigned)(e->param()); if (m_randomUin == 0){ edtStatus->setText(i18n("Search fail")); }else{ edtStatus->setText(i18n("Request user info")); btnMsg->setEnabled(true); btnAdd->setEnabled(true); edtInfo->setText(i18n("<p>UIN: <b><a href=\"icq://%1\"><u>%2</u></a></b></p>") .arg(QString::number(m_randomUin)) .arg(QString::number(m_randomUin))); edtInfo->sync(); m_client->randomChatInfo(m_randomUin); } return this; } if (e->type() == EventRandomChatInfo){ ICQUserData *data = (ICQUserData*)(e->param()); if (data->Uin.value != m_randomUin) return NULL; edtStatus->setText(""); m_name = QString::fromUtf8(data->Alias.ptr); QString name = quoteString(m_name); QString topic = quoteString(QString::fromUtf8(data->About.ptr)); QString page = QString::fromUtf8(data->Homepage.ptr); QString pageLink = page; if (pageLink.left(5) != "http:"){ pageLink = "http://"; pageLink += page; } page = quoteString(page); const ext_info *e; QString text = i18n("<p><b>%1</b></p>") .arg(name); if (!topic.isEmpty()) text += i18n("%1<br>") .arg(topic); text += i18n("<p>Age: <b>%1</b></p>") .arg(data->Age.value); QString gender; for (e = p_genders; e->nCode; e++){ if (e->nCode == data->Gender.value){ gender = i18n(e->szName); break; } } if (!gender.isEmpty()) text += i18n("<p>Gender: <b>%1</b></p>") .arg(gender); QString country; for (e = getCountries(); e->nCode; e++){ if (e->nCode == data->Country.value){ country = i18n(e->szName); break; } } if (!country.isEmpty()) text += i18n("<p>Country: <b>%1</b></p>") .arg(country); QString lang; for (e = p_languages; e->nCode; e++){ if (e->nCode == data->Language.value){ lang = i18n(e->szName); break; } } if (!lang.isEmpty()) text += i18n("<p>Language: <b>%1</b></p>") .arg(lang); if (!page.isEmpty()) text += i18n("<p>Homepage: <a href=\"%1\"><u>%2</u></a></p>") .arg(pageLink) .arg(page); edtInfo->append(text); edtInfo->sync(); } switch (e->type()){ case EventGroupCreated: case EventGroupDeleted: case EventGroupChanged: fillGroup(); } return NULL; }
void *JabberClient::processEvent(Event *e) { if (e->type() == EventTemplateExpanded){ TemplateExpand *t = (TemplateExpand*)(e->param()); setStatus((unsigned)(t->param), quoteString(t->tmpl, false).utf8()); } if (e->type() == EventContactChanged){ Contact *contact = (Contact*)(e->param()); string grpName; string name; name = contact->getName().utf8(); Group *grp = NULL; if (contact->getGroup()) grp = getContacts()->group(contact->getGroup()); if (grp) grpName = grp->getName().utf8(); ClientDataIterator it(contact->clientData, this); JabberUserData *data; while ((data = (JabberUserData*)(++it)) != NULL){ if (!cmp(grpName, data->Group)){ listRequest(data, name.c_str(), grpName.c_str(), false); continue; } if (data->Name && *data->Name){ if (!cmp(name, data->Name)) listRequest(data, name.c_str(), grpName.c_str(), false); continue; } if (!cmp(name, data->ID)) listRequest(data, name.c_str(), grpName.c_str(), false); } return NULL; } if (e->type() == EventContactDeleted){ Contact *contact = (Contact*)(e->param()); ClientDataIterator it(contact->clientData, this); JabberUserData *data; while ((data = (JabberUserData*)(++it)) != NULL){ listRequest(data, NULL, NULL, true); } return NULL; } if (e->type() == EventGroupChanged){ Group *grp = (Group*)(e->param()); string grpName; grpName = grp->getName().utf8(); ContactList::ContactIterator itc; Contact *contact; while ((contact = ++itc) != NULL){ if (contact->getGroup() != grp->id()) continue; ClientDataIterator it(contact->clientData, this); JabberUserData *data; while ((data = (JabberUserData*)(++it)) != NULL){ if (!cmp(grpName, data->Group)) listRequest(data, contact->getName().utf8(), grpName.c_str(), false); } } } return NULL; }
QCString JabberClient::encodeXML(const QString &str) { return quoteString(str, false).utf8(); }
QString MsgViewBase::messageText(Message *msg, bool bUnread) { QString options; QString info; QString status; const char *icon = "message"; const CommandDef *def = CorePlugin::m_plugin->messageTypes.find(msg->type()); if (def) icon = def->icon; bool bDirection = false; if (msg->type() == MessageStatus){ icon = "empty"; StatusMessage *sm = static_cast<StatusMessage*>(msg); Client *client = NULL; string clientStr; if (msg->client()) clientStr = msg->client(); int n = clientStr.find_last_of('.'); if (n >= 0){ clientStr = clientStr.substr(0, n); }else{ clientStr = ""; } if (!clientStr.empty()){ for (unsigned i = 0; i < getContacts()->nClients(); i++){ string n = getContacts()->getClient(i)->name(); if (n.length() < clientStr.length()) continue; n = n.substr(0, clientStr.length()); if (clientStr == n){ client = getContacts()->getClient(i); break; } } } if ((client == NULL) && getContacts()->nClients()) client = getContacts()->getClient(0); if (client){ for (def = client->protocol()->statusList(); def->text; def++){ if (def->id == sm->getStatus()){ icon = def->icon; status = i18n(def->text); break; } } } options += " direction=\"2\""; bDirection = true; }else{ MessageDef *m_def = (MessageDef*)(def->param); if (m_def->flags & MESSAGE_INFO){ options += " direction=\"2\""; bDirection = true; } } info = QString("<icon>%1</icon>") .arg(icon); QString contactName; if (msg->getFlags() & MESSAGE_RECEIVED){ if (!bDirection) options += " direction=\"1\""; Contact *contact = getContacts()->contact(msg->contact()); if (contact){ contactName = contact->getName(); if (contactName.isEmpty()){ Client *client = NULL; ClientDataIterator it(contact->clientData); void *data; while ((data = ++it) != NULL){ if (it.client()->dataName(data) == msg->client()){ client = it.client(); break; } } } } if (!bUnread){ for (list<msg_id>::iterator it = CorePlugin::m_plugin->unread.begin(); it != CorePlugin::m_plugin->unread.end(); ++it){ msg_id &m = (*it); if ((m.id == msg->id()) && (m.contact == msg->contact()) && (m.client == msg->client())){ bUnread = true; break; } } } if (bUnread) options += " unread=\"1\""; }else{ if (!bDirection) options += " direction=\"0\""; contactName = getContacts()->owner()->getName(); } if (contactName.isEmpty()) contactName = "???"; info += QString("<from>%1</from>") .arg(quoteString(contactName)); QString id = QString::number(msg->id()); id += ","; if (msg->getBackground() != msg->getForeground()) id += QString::number(msg->getBackground() & 0xFFFFFF); string client_str; if (msg->client()) client_str = msg->client(); if (!client_str.empty()){ id += ","; id += quoteString(client_str.c_str()); } info += "<id>"; info += id; info += "</id>"; QString icons; if (msg->getFlags() & MESSAGE_SECURE) options += " encrypted=\"1\""; if (msg->getFlags() & MESSAGE_URGENT) options += " urgent=\"1\""; if (msg->getFlags() & MESSAGE_LIST) options += " list=\"1\""; QString s; QDateTime t; t.setTime_t(msg->getTime()); info += s.sprintf("<time><date>%%1</date><hour>%02u</hour><minute>%02u</minute><second>%02u</second></time>", t.time().hour(), t.time().minute(), t.time().second()) .arg(formatDate(msg->getTime())); s = "<?xml version=\"1.0\"?><message"; s += options; s += ">"; s += info; QString msgText; if (msg->type() != MessageStatus){ msgText = msg->presentation(); if (msgText.isEmpty()){ unsigned type = msg->baseType(); CommandDef *cmd = CorePlugin::m_plugin->messageTypes.find(type); if (cmd){ MessageDef *def = (MessageDef*)(cmd->param); msgText = i18n(def->singular, def->plural, 1); int n = msgText.find("1 "); if (n == 0){ msgText = msgText.mid(2); }else if (n > 0){ msgText = msgText.left(n); } msgText = QString("<p>") + msgText + "</p>"; } QString text = msg->getRichText(); msgText += text; } }else{ msgText = status; } Event e(EventEncodeText, &msgText); e.process(); msgText = parseText(msgText, CorePlugin::m_plugin->getOwnColors(), CorePlugin::m_plugin->getUseSmiles()); msgText = QString(MSG_BEGIN) + msgText; s += "<body>"; s += quoteString(msgText); s += "</body>"; s += "</message>"; XSL *p = xsl; if (p == NULL) p = CorePlugin::m_plugin->historyXSL; QString anchor = MSG_ANCHOR; anchor += id; anchor += "\">"; QString res = p->process(s); if (res.left(3) == "<p>"){ res = QString("<p>") + anchor + res.mid(3); }else{ res = anchor + res; } return res; }
static void testQuoteString(void) { test(quoteString("abcde"), "\"abcde\""); test(quoteString("ab\t\"\5cd"), "\"ab\\t\\\"\\005cd\""); }
bool JabberClient::send(Message *msg, void *_data) { if (getState() != Connected) return false; JabberUserData *data = (JabberUserData*)_data; switch (msg->type()){ case MessageAuthRefused:{ string grp; Group *group = NULL; Contact *contact = getContacts()->contact(msg->contact()); if (contact && contact->getGroup()) group = getContacts()->group(contact->getGroup()); if (group) grp = group->getName().utf8(); listRequest(data, data->Name, grp.c_str(), false); if (data->Subscribe & SUBSCRIBE_FROM){ m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<presence to=\"" << data->ID; m_socket->writeBuffer << "\" type=\"unsubscribed\"><status>" << (const char*)(quoteString(msg->getPlainText(), false).utf8()) << "</status></presence>"; sendPacket(); if ((msg->getFlags() & MESSAGE_NOHISTORY) == 0){ msg->setClient(dataName(data).c_str()); Event e(EventSent, msg); e.process(); } Event e(EventMessageSent, msg); e.process(); delete msg; return true; } } case MessageGeneric:{ Contact *contact = getContacts()->contact(msg->contact()); if ((contact == NULL) || (data == NULL)) return false; m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<message to=\"" << data->ID; m_socket->writeBuffer << "\"><body>" << (const char*)msg->getPlainText().utf8() << "</body></message>"; sendPacket(); if ((msg->getFlags() & MESSAGE_NOHISTORY) == 0){ msg->setClient(dataName(data).c_str()); Event e(EventSent, msg); e.process(); } Event e(EventMessageSent, msg); e.process(); delete msg; return true; } case MessageAuthRequest:{ m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<presence to=\"" << data->ID; m_socket->writeBuffer << "\" type=\"subscribe\"><status>" << (const char*)(quoteString(msg->getPlainText(), false).utf8()) << "</status></presence>"; sendPacket(); if ((msg->getFlags() & MESSAGE_NOHISTORY) == 0){ msg->setClient(dataName(data).c_str()); Event e(EventSent, msg); e.process(); } Event e(EventMessageSent, msg); e.process(); delete msg; return true; } case MessageAuthGranted:{ m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<presence to=\"" << data->ID; m_socket->writeBuffer << "\" type=\"subscribed\"></presence>"; sendPacket(); if ((msg->getFlags() & MESSAGE_NOHISTORY) == 0){ msg->setClient(dataName(data).c_str()); Event e(EventSent, msg); e.process(); } Event e(EventMessageSent, msg); e.process(); delete msg; return true; } case MessageJabberOnline: if (isAgent(data->ID) && (data->Status == STATUS_OFFLINE)){ m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<presence to=\"" << data->ID << "\"></presence>"; sendPacket(); delete msg; return true; } break; case MessageJabberOffline: if (isAgent(data->ID) && (data->Status != STATUS_OFFLINE)){ m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<presence to=\"" << data->ID << "\" type=\"unavailable\"></presence>"; sendPacket(); delete msg; return true; } break; } return false; }
void configParserStruct::pythonParser::setVariableValue( const std::string &VarName, const std::string &Value ) { ExternalVariables[ VarName ] = quoteString( Value, pythonQuotes() ); }
int parseMsInputParam( int argc, char **argv, int optInd, int ruleGen, int string, execMyRuleInp_t *execMyRuleInp, char *inBuf ) { strArray_t strArray; int status, i, j; char *value; int nInput; char line[MAX_NAME_LEN]; int promptF = 0; int labelF = 0; if ( inBuf == NULL || strcmp( inBuf, "null" ) == 0 ) { execMyRuleInp->inpParamArray = NULL; return ( 0 ); } nInput = argc - optInd; memset( &strArray, 0, sizeof( strArray ) ); status = splitMultiStr( inBuf, &strArray ); if ( status < 0 ) { rodsLog( LOG_ERROR, "parseMsInputParam: parseMultiStr error, status = %d", status ); execMyRuleInp->inpParamArray = NULL; return ( status ); } resizeStrArray( &strArray, MAX_NAME_LEN ); value = strArray.value; /* each string is supposed to have to format label=value */ for ( i = 0; i < nInput; i++ ) { /* using the values from the input line following -F <filename> */ if ( !strcmp( argv[optInd + i], "prompt" ) ) { promptF = 1; break; } if ( !strcmp( argv[optInd + i], "default" ) || strlen( argv[optInd + i] ) == 0 ) { continue; } else if ( *argv[optInd + i] == '*' ) { char *tmpPtr; if ( i > 0 && labelF == 0 ) { return( CAT_INVALID_ARGUMENT ); } labelF = 1; if ( ( tmpPtr = strstr( argv[optInd + i], "=" ) ) == NULL ) { return( CAT_INVALID_ARGUMENT ); } *tmpPtr = '\0'; for ( j = 0; j < strArray.len; j++ ) { if ( strstr( &value[j * strArray.size], argv[optInd + i] ) == &value[j * strArray.size] ) { *tmpPtr = '='; char *val = quoteString( argv[optInd + i], string, 1 ); rstrcpy( &value[j * strArray.size], val, strArray.size ); free( val ); break; } } if ( j == strArray.len ) { printf( "Ignoring Argument \"%s\"", argv[optInd + i] ); } } else { char *valPtr = &value[i * strArray.size]; char *tmpPtr; if ( labelF == 1 ) { return( CAT_INVALID_ARGUMENT ); } if ( ( tmpPtr = strstr( valPtr, "=" ) ) != NULL ) { tmpPtr++; char *val = quoteString( argv[optInd + i], string, 0 ); rstrcpy( tmpPtr, val, strArray.size - ( tmpPtr - valPtr + 1 ) ); free( val ); } } } for ( i = 0; i < strArray.len; i++ ) { char *valPtr = &value[i * strArray.size]; char *tmpPtr; if ( ( tmpPtr = strstr( valPtr, "=" ) ) != NULL ) { *tmpPtr = '\0'; tmpPtr++; /** RAJA Jul 12 2007 changed it so that it can take input values from terminal addMsParam (execMyRuleInp->inpParamArray, valPtr, STR_MS_T, strdup (tmpPtr), NULL); ** RAJA Jul 12 2007 changed it so that it can take input values from terminal **/ if ( *tmpPtr == '$' ) { /* If $ is used as a value in the input file for label=value then the remaining command line arguments are taken as values. If no command line arguments are given then the user is prompted for the input value */ printf( "Default %s=%s\n New %s=", valPtr, tmpPtr + 1, valPtr ); if ( fgets( line, MAX_NAME_LEN, stdin ) == NULL ) { return( CAT_INVALID_ARGUMENT ); } if ( ( line[strlen( line ) - 1] = '\n' ) ) { line[strlen( line ) - 1] = '\0'; } char *val; if ( strlen( line ) == 0 ) { val = strdup( tmpPtr + 1 ); } else { val = quoteString( line, string && ruleGen, 0 ); } addMsParam( execMyRuleInp->inpParamArray, valPtr, STR_MS_T, val, NULL ); } else if ( promptF == 1 ) { /* the user has asked for prompting */ printf( "Current %s=%s\n New %s=", valPtr, tmpPtr, valPtr ); if ( fgets( line, MAX_NAME_LEN, stdin ) == NULL ) { return( CAT_INVALID_ARGUMENT ); } if ( ( line[strlen( line ) - 1] = '\n' ) ) { line[strlen( line ) - 1] = '\0'; } char *val; if ( strlen( line ) == 0 ) { val = strdup( tmpPtr ); } else { val = quoteString( line, string && ruleGen, 0 ); } addMsParam( execMyRuleInp->inpParamArray, valPtr, STR_MS_T, val, NULL ); } else if ( *tmpPtr == '\\' ) { /* first '\' is skipped. If you need to use '\' in the first letter add an additional '\' if you have to use '$' in the first letter add a '\' before that */ tmpPtr++; char *param = quoteString( tmpPtr, string && ruleGen, 0 ); if ( !ruleGen ) { trimQuotes( param ); } addMsParam( execMyRuleInp->inpParamArray, valPtr, STR_MS_T, param, NULL ); } else { char *param = quoteString( tmpPtr, string && ruleGen, 0 ); if ( !ruleGen ) { trimQuotes( param ); } addMsParam( execMyRuleInp->inpParamArray, valPtr, STR_MS_T, param, NULL ); } } else { rodsLog( LOG_ERROR, "parseMsInputParam: inpParam %s format error", valPtr ); } } return ( 0 ); }
QString MsgViewBase::messageText(Message *msg) { QString color; unsigned long c_sender = (CorePlugin::m_plugin->getColorSender()) & 0xFFFFFF; unsigned long c_receiver = (CorePlugin::m_plugin->getColorReceiver())& 0xFFFFFF; unsigned long c_send = 0x000000; unsigned long c_receive = 0x000000; if (CorePlugin::m_plugin->getOwnColors()) { c_send = (CorePlugin::m_plugin->getColorSend()) & 0xFFFFFF; c_receive = (CorePlugin::m_plugin->getColorReceive()) & 0xFFFFFF; } color.sprintf(COLOR_FORMAT, ((msg->getFlags() & MESSAGE_RECEIVED) ? c_receiver : c_sender)); const char *icon = "message"; const CommandDef *def = CorePlugin::m_plugin->messageTypes.find(msg->type()); if (def) icon = def->icon; QString contactName; Client *client = NULL; Contact *contact = getContacts()->contact(msg->contact()); if (contact){ ClientDataIterator it(contact->clientData); void *data; while ((data = ++it) != NULL){ if (it.client()->dataName(data) == msg->client()){ client = it.client(); break; } } } if (msg->type() == MessageStatus){ icon = "empty"; StatusMessage *sm = static_cast<StatusMessage*>(msg); if (client == NULL) client = getContacts()->getClient(0); if (client){ for (def = client->protocol()->statusList(); def->text; def++){ if (def->id == sm->getStatus()){ icon = def->icon; break; } } } } bool bUnread = false; if (msg->getFlags() & MESSAGE_RECEIVED){ if (contact) contactName = contact->getName(); for (list<msg_id>::iterator it = CorePlugin::m_plugin->unread.begin(); it != CorePlugin::m_plugin->unread.end(); ++it){ msg_id &m = (*it); if ((m.id == msg->id()) && (m.contact == msg->contact()) && (m.client == msg->client())){ bUnread = true; break; } } }else{ if (client) contactName = client->ownerName(); if (contactName.isEmpty()) contactName = getContacts()->owner()->getName(); } if (contactName.isEmpty()) contactName = "???"; QString id = QString::number(msg->id()); id += ","; if (msg->getBackground() != msg->getForeground()) id += QString::number(msg->getBackground() & 0xFFFFFF); string client_str; if (msg->client()) client_str = msg->client(); if (!client_str.empty()){ id += ","; id += quoteText(client_str.c_str()); } QString icons; if (msg->getFlags() & MESSAGE_SECURE) icons += "<img src=\"icon:encrypted\">"; if (msg->getFlags() & MESSAGE_URGENT) icons += "<img src=\"icon:urgentmsg\">"; if (msg->getFlags() & MESSAGE_LIST) icons += "<img src=\"icon:listmsg\">"; QString s = QString("<p><nobr>" "<a href=\"msg://%1\"><img src=\"icon:%2\"></a>%3" " %4<span style=\"color:#%5\">%6</span> " "<font size=\"-1\">%7</font>%8" "</nobr></p>") .arg(id) .arg(icon) .arg(icons) .arg(bUnread ? "<b>" : "") .arg(color) .arg(quoteString(contactName)) .arg(formatTime(msg->getTime())) .arg(bUnread ? "</b>" : ""); if (msg->type() != MessageStatus){ QString msgText = msg->presentation(); if (msgText.isEmpty()){ unsigned type = msg->baseType(); CommandDef *cmd = CorePlugin::m_plugin->messageTypes.find(type); if (cmd){ MessageDef *def = (MessageDef*)(cmd->param); msgText += "<p>"; msgText += i18n(def->singular, def->plural, 1); msgText += "</p>"; } QString text = msg->getRichText(); msgText += text; } Event e(EventEncodeText, &msgText); e.process(); msgText = parseText(msgText, CorePlugin::m_plugin->getOwnColors(), CorePlugin::m_plugin->getUseSmiles()); if (CorePlugin::m_plugin->getOwnColors()){ color.sprintf(COLOR_FORMAT, ((msg->getFlags() & MESSAGE_RECEIVED) ? c_receive : c_send)); s += "<span style=\"color:#"; s += color; s += "\">"; } s += msgText; if (CorePlugin::m_plugin->getOwnColors()) s += "</span>"; } return s; }
void save(void *_obj, const cfgParam *params, ostream &out) { const cfgParam *saveParam = params; char *obj = (char*)_obj; string *s; string v; list<unsigned long> *l; list<unsigned long>::iterator it; for (;;){ const cfgParam *p; for (p = params; *p->name; p++){ const cfgParam *pp = saveParam; for (;;){ for (; *pp->name; pp++) if (strcmp(pp->name, p->name) == 0) break; if (*pp->name) break; if (pp->defValue == 0) break; pp = (const cfgParam*)(pp->defValue); } if (pp != p) continue; bool writeEmpty = false; string value; switch (p->type){ case PARAM_ULONG: if (*((unsigned long*)(obj + p->offs)) != p->defValue){ char buf[32]; snprintf(buf, sizeof(buf), "%lu", *((unsigned long*)(obj + p->offs))); value = buf; } break; case PARAM_USHORT: if (*((unsigned short*)(obj + p->offs)) != (unsigned short)(p->defValue)){ char buf[32]; snprintf(buf, sizeof(buf), "%u", *((unsigned short*)(obj + p->offs))); value = buf; } break; case PARAM_SHORT: if (*((short*)(obj + p->offs)) != (short)(p->defValue)){ char buf[32]; snprintf(buf, sizeof(buf), "%u", *((short*)(obj + p->offs))); value = buf; } break; case PARAM_STRING: s = (string*)(obj + p->offs); v = ""; if (p->defValue) v = (const char*)(p->defValue); if (*s != v){ value = *s; writeEmpty = true; } break; case PARAM_BOOL: if (*((bool*)(obj + p->offs)) != (bool)(p->defValue)) value = *((bool*)(obj + p->offs)) ? "true" : "false"; break; case PARAM_I18N: s = (string*)(obj + p->offs); v = ""; if (p->defValue) v = i18n((const char*)(p->defValue)).local8Bit(); if (*s != v) value = v; break; case PARAM_ULONGS: l = (list<unsigned long>*)(obj + p->offs); if (l->size()){ for (it = l->begin(); it != l->end(); ++it){ char b[15]; snprintf(b, sizeof(b), "%lu", *it); if (value.length()) value += ","; value += b; } } break; case PARAM_CHAR: if (obj[p->offs] != (char)(p->defValue)){ char buf[32]; snprintf(buf, sizeof(buf), "%u", *((char*)(obj + p->offs))); value = buf; } break; default: l = (list<unsigned long>*)(obj + p->offs); for (it = l->begin(); it != l->end(); ++it){ out << "[" << p->name << "]\n"; save((void*)(*it), (const cfgParam*)(p->defValue), out); } if (l->size()) out << "[]\n"; } if ((value.size() == 0) && !writeEmpty) continue; value = quoteString(value); out << p->name << "=" << value << "\n"; } if (p->defValue == 0) break; params = (const cfgParam*)(p->defValue); if (p->offs) obj = *((char**)(obj + p->offs)); } }
static String quoteURLIfNeeded(const String& string) { return isCSSTokenizerURL(string) ? string : quoteString(string); }
static String quoteStringIfNeeded(const String& string) { return isCSSTokenizerIdentifier(string) ? string : quoteString(string); }
QString MsgViewBase::messageText(Message *msg) { QString color; unsigned long c_sender = 0x800000; unsigned long c_receiver = 0x000080; unsigned long c_send = 0x000000; unsigned long c_receive = 0x000000; if (CorePlugin::m_plugin->getOwnColors()) { c_send = (CorePlugin::m_plugin->getColorSend()) & 0xFFFFFF; c_receive = (CorePlugin::m_plugin->getColorReceive()) & 0xFFFFFF; c_sender = (CorePlugin::m_plugin->getColorSender()) & 0xFFFFFF; c_receiver = (CorePlugin::m_plugin->getColorReceiver())& 0xFFFFFF; } color.sprintf(FONT_FORMAT, ((msg->getFlags() & MESSAGE_RECEIVED) ? c_receiver : c_sender)); const char *icon = "message"; const CommandDef *def = CorePlugin::m_plugin->messageTypes.find(msg->type()); if (def) icon = def->icon; QString contactName; Client *client = NULL; Contact *contact = getContacts()->contact(msg->contact()); if (contact){ ClientDataIterator it(contact->clientData); void *data; while ((data = ++it) != NULL){ if (it.client()->dataName(data) == msg->client()){ client = it.client(); break; } } } if (msg->type() == MessageStatus){ icon = "empty"; StatusMessage *sm = static_cast<StatusMessage*>(msg); if (client == NULL) client = getContacts()->getClient(0); if (client){ for (def = client->protocol()->statusList(); def->text; def++){ if (def->id == sm->getStatus()){ icon = def->icon; break; } } } } bool bUnread = false; if (msg->getFlags() & MESSAGE_RECEIVED){ if (contact) contactName = contact->getName(); for (list<msg_id>::iterator it = CorePlugin::m_plugin->unread.begin(); it != CorePlugin::m_plugin->unread.end(); ++it){ msg_id &m = (*it); if ((m.id == msg->id()) && (m.contact == msg->contact()) && (m.client == msg->client())){ bUnread = true; break; } } }else{ if (client) contactName = client->ownerName(); if (contactName.isEmpty()) contactName = getContacts()->owner()->getName(); } if (contactName.isEmpty()) contactName = "???"; QString id = QString::number(msg->id()); id += ","; if (msg->getBackground() != msg->getForeground()) id += QString::number(msg->getBackground() & 0xFFFFFF); string client_str; if (msg->client()) client_str = msg->client(); if (!client_str.empty()){ id += ","; id += quoteText(client_str.c_str()); } QString icons; if (msg->getFlags() & MESSAGE_SECURE) icons += "<img src=\"icon:encrypted\">"; if (msg->getFlags() & MESSAGE_URGENT) icons += "<img src=\"icon:urgentmsg\">"; if (msg->getFlags() & MESSAGE_LIST) icons += "<img src=\"icon:listmsg\">"; QString s = QString("<p><nobr>" "<a href=\"msg://%1\"><img src=\"icon:%2\"></a>%3" " %4<font color=\"#%5\">%6</font> " "<font size=-1>%7</font>%8" "</nobr></p>") .arg(id) .arg(icon) .arg(icons) .arg(bUnread ? "<b>" : "") .arg(color) .arg(quoteString(contactName)) .arg(formatTime(msg->getTime())) .arg(bUnread ? "</b>" : ""); if (msg->type() != MessageStatus){ QString msgText = msg->presentation(); // replace font color if we use own colors // some of the incoming messages are saved as html with an extra <font> - tag // so we need to replace until no more <font> - tag is found // this behaviour should be checked! if (CorePlugin::m_plugin->getOwnColors()) { int pos = msgText.find("font color=\"#",0); while (pos != -1) { pos += 13; QString color; color.sprintf(FONT_FORMAT, (msg->getFlags() & MESSAGE_RECEIVED) ? c_receive : c_send); msgText.replace(pos,6,color); pos = msgText.find("font color=\"#",pos); } } if (msgText.isEmpty()){ unsigned type = msg->type(); for (;;){ CommandDef *cmd = CorePlugin::m_plugin->messageTypes.find(type); if (cmd == NULL) break; MessageDef *def = (MessageDef*)(cmd->param); if (def->base_type){ type = def->base_type; continue; } msgText += "<p>"; msgText += i18n(def->singular, def->plural, 1); msgText += "</p>"; break; } QString text = msg->getRichText(); if (!text.isEmpty()){ msgText += "<p>"; msgText += text; msgText += "</p>"; } } Event e(EventEncodeText, &msgText); e.process(); s += parseText(msgText, false, CorePlugin::m_plugin->getUseSmiles()); } return s; }
void JabberImageParser::text(const QString &text) { res += quoteString(text); }
void FileTransferDlgNotify::createFile(const QString &name, unsigned size, bool bCanResume) { m_name = name; m_size = size; m_name = m_name.replace(QRegExp("\\\\"), "/"); FileTransfer *ft = m_dlg->m_msg->m_transfer; int n = m_name.findRev("/"); if (n >= 0){ QString path; QString p = m_name.left(n); while (!p.isEmpty()){ if (!path.isEmpty()) path += "/"; QString pp = getToken(p, '/'); if (pp == ".."){ QString errMsg = i18n("Bad path: %1") .arg(m_name); m_dlg->m_msg->setError(errMsg.toUtf8()); ft->setError(); return; } path += pp; QDir dd(ft->dir() + "/" + path); if (!dd.exists()){ QDir d(ft->dir()); if (!d.mkdir(path)){ QString errMsg = i18n("Can't create: %1") .arg(path); m_dlg->m_msg->setError(errMsg.toUtf8()); ft->setError(); return; } } } } m_dlg->m_msg->addFile(m_name, size); if (m_name.isEmpty() || (m_name[(int)(m_name.length() - 1)] == '/')){ ft->startReceive(0); return; } QString shortName = m_name; m_name = ft->dir() + m_name; if (ft->m_file) delete ft->m_file; m_dlg->process(); ft->m_file = new QFile(m_name); if (ft->m_file->exists()){ switch (ft->overwrite()){ case Skip: skip(); return; case Replace: if (ft->m_file->open(QIODevice::WriteOnly | QIODevice::Truncate)){ ft->startReceive(0); return; } break; case Resume: if (ft->m_file->open(QIODevice::WriteOnly)){ resume(); return; } break; default: if (ft->m_file->open(QIODevice::WriteOnly)){ QStringList buttons; QString forAll; if (ft->files()) forAll = i18n("For all files"); buttons.append(i18n("&Replace")); buttons.append(i18n("&Skip")); if (bCanResume && (ft->m_file->size() < size)) buttons.append(i18n("Resu&me")); m_dlg->m_ask = new BalloonMsg(NULL, quoteString(i18n("File %1 exists") .arg(shortName)), buttons, m_dlg->lblState, NULL, false, true, 150, forAll); QObject::connect(m_dlg->m_ask, SIGNAL(action(int, void*)), m_dlg, SLOT(action(int, void*))); raiseWindow(m_dlg); m_dlg->m_ask->show(); return; } } }else{
bool JabberClient::send(Message *msg, void *_data) { if ((getState() != Connected) || (_data == NULL)) return false; JabberUserData *data = (JabberUserData*)_data; switch (msg->type()){ case MessageAuthRefused:{ string grp; Group *group = NULL; Contact *contact = getContacts()->contact(msg->contact()); if (contact && contact->getGroup()) group = getContacts()->group(contact->getGroup()); if (group) grp = group->getName().utf8(); listRequest(data, data->Name, grp.c_str(), false); if (data->Subscribe & SUBSCRIBE_FROM){ m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<presence to=\"" << data->ID; m_socket->writeBuffer << "\" type=\"unsubscribed\"><status>" << (const char*)(quoteString(msg->getPlainText(), false).utf8()) << "</status></presence>"; sendPacket(); if ((msg->getFlags() & MESSAGE_NOHISTORY) == 0){ msg->setClient(dataName(data).c_str()); Event e(EventSent, msg); e.process(); } Event e(EventMessageSent, msg); e.process(); delete msg; return true; } } case MessageGeneric:{ Contact *contact = getContacts()->contact(msg->contact()); if ((contact == NULL) || (data == NULL)) return false; m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<message type=\"chat\" to=\"" << data->ID; m_socket->writeBuffer << "\"><body>" << (const char*)msg->getPlainText().utf8() << "</body>"; if (data->richText){ char bgColor[8]; sprintf(bgColor, "%06X", msg->getBackground() & 0xFFFFFF); m_socket->writeBuffer << "<html xmlns='http://jabber.org/protocol/xhtml-im'>" << "<body bgcolor=\"#" << bgColor << "\">" << removeImages(msg->getRichText()).utf8() << "</body></html>"; } m_socket->writeBuffer << "</message>"; sendPacket(); if ((msg->getFlags() & MESSAGE_NOHISTORY) == 0){ msg->setClient(dataName(data).c_str()); Event e(EventSent, msg); e.process(); } Event e(EventMessageSent, msg); e.process(); delete msg; return true; } case MessageAuthRequest:{ m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<presence to=\"" << data->ID; m_socket->writeBuffer << "\" type=\"subscribe\"><status>" << (const char*)(quoteString(msg->getPlainText(), false).utf8()) << "</status></presence>"; sendPacket(); if ((msg->getFlags() & MESSAGE_NOHISTORY) == 0){ msg->setClient(dataName(data).c_str()); Event e(EventSent, msg); e.process(); } Event e(EventMessageSent, msg); e.process(); delete msg; return true; } case MessageAuthGranted:{ m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<presence to=\"" << data->ID; m_socket->writeBuffer << "\" type=\"subscribed\"></presence>"; sendPacket(); if ((msg->getFlags() & MESSAGE_NOHISTORY) == 0){ msg->setClient(dataName(data).c_str()); Event e(EventSent, msg); e.process(); } Event e(EventMessageSent, msg); e.process(); delete msg; return true; } case MessageJabberOnline: if (isAgent(data->ID) && (data->Status == STATUS_OFFLINE)){ m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<presence to=\"" << data->ID << "\"></presence>"; sendPacket(); delete msg; return true; } break; case MessageJabberOffline: if (isAgent(data->ID) && (data->Status != STATUS_OFFLINE)){ m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<presence to=\"" << data->ID << "\" type=\"unavailable\"></presence>"; sendPacket(); delete msg; return true; } break; case MessageTypingStart: if (getTyping()){ data->composeId = ++m_msg_id; string msg_id = "msg"; msg_id += number(data->composeId); m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<message to=\"" << data->ID << "\"><x xmlns='jabber:x:event'><composing/><id>" << msg_id.c_str() << "</id></x></message>"; sendPacket(); delete msg; return true; } break; case MessageTypingStop: if (getTyping()){ if (data->composeId == 0) return false; string msg_id = "msg"; msg_id += number(data->composeId); m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<message to=\"" << data->ID << "\"><x xmlns='jabber:x:event'><id>" << msg_id.c_str() << "</id></x></message>"; sendPacket(); delete msg; return true; } break; } return false; }
void ViewParser::tag_start(const QString &tag, const list<QString> &attrs) { // the tag that will be actually written out QString oTag = tag; if (m_bInHead) return; QString style; if (tag == "img"){ QString src; for (list<QString>::const_iterator it = attrs.begin(); it != attrs.end(); ++it){ QString name = (*it).lower(); ++it; QString value = *it; if (name == "src"){ src = value; break; } } if (src.left(10) == "icon:smile"){ bool bOK; unsigned nSmile = src.mid(10).toUInt(&bOK, 16); if (bOK){ const smile *s = smiles(nSmile); if (s == NULL) return; if (*s->exp == 0){ res += quoteString(s->paste); return; } } } }else if (tag == "a"){ m_bInLink = true; }else if (tag == "html"){ // we display as a part of a larger document return; }else if (tag == "head"){ m_bInHead = 1; return; }else if (tag == "body"){ // we display as a part of a larger document oTag = "span"; }else if (tag == "p"){ m_bPara = false; if (m_bFirst){ m_bFirst = false; }else{ res += "<br>"; } for (list<QString>::const_iterator it = attrs.begin(); it != attrs.end(); ++it){ QString name = (*it).lower(); ++it; QString value = *it; if (name == "dir"){ if (value == "rtl"){ res += "<span dir=\"rtl\">"; m_bSpan = true; } break; } } return; } QString tagText; tagText += "<"; tagText += oTag; for (list<QString>::const_iterator it = attrs.begin(); it != attrs.end(); ++it){ QString name = (*it).lower(); ++it; QString value = *it; // Handling for attributes of specific tags. if (tag == "body"){ if (name == "bgcolor"){ style += "background-color:" + value + ";"; continue; } }else if (tag == "font"){ if (name == "color" && m_bIgnoreColors) continue; } // Handle for generic attributes. if (name == "style"){ style += value; continue; } tagText += " "; tagText += name; if (!value.isEmpty()){ tagText += "=\""; tagText += value; tagText += "\""; } } // Quite crude but working CSS to remove color styling. // It won't filter out colors as part of 'background', but life's tough. // (If it's any comfort, Qt probably won't display it either.) if (!style.isEmpty()){ if (m_bIgnoreColors){ list<QString> opt = parseStyle(style); list<QString> new_opt; for (list<QString>::iterator it = opt.begin(); it != opt.end(); ++it){ QString name = *it; it++; if (it == opt.end()) break; QString value = *it; if ((name == "color") || (name == "background-color") || (name == "font-size") || (name == "font-style") || (name == "font-weight") || (name == "font-family")) continue; new_opt.push_back(name); new_opt.push_back(value); } style = makeStyle(new_opt); } if (!style.isEmpty()) tagText += " style=\"" + style + "\""; } tagText += ">"; res += tagText; }
void ClientConnection::handleCommand(const std::string& line) { if (boost::iequals(line, "RETRIEVE TASKS")) { auto& query = findTasksForLoginQ(); query.execute(_userId); std::unique_ptr<ClientTask> task; while (query.next(task)) { _stream.writeLine(concatln("TASK ", task->_id, " TITLE ", quoteString(task->_title), " SPENT ", toSeconds(task->_timeSpent))); for (const auto& line : task->_description) { _stream.writeLine(concatln(line)); } _stream.writeLine("\n"); } _stream.writeLine("END TASKS\n"); } else if (boost::iequals(line, "LOG UPLOAD")) { auto& lastEntryTimeQ = findLastLogEntryTimeForClientQ(); lastEntryTimeQ.execute(_clientId); boost::optional<Timestamp> lastEntryTime; bool res = lastEntryTimeQ.next(lastEntryTime); assert(res); assert(! lastEntryTimeQ.next(lastEntryTime)); if (lastEntryTime) { _stream.writeLine(concatln("LAST ENTRY AT ", formatTimestamp(*lastEntryTime))); } else { _stream.writeLine("NO ENTRYS\n"); } int taskId; std::set<std::string> employeeIds; bool loop = true; while (loop) { auto line = _stream.readLine(); LogEntry entry; if (parse(line, TimestampToken(entry._timestamp), " ", BareStringToken(entry._userId), " LOGIN")) { entry._type = LogEntryType_LOGIN; } else if (parse(line, TimestampToken(entry._timestamp), " ", BareStringToken(entry._userId), " LOGOUT")) { entry._type = LogEntryType_LOGOUT; } else if (parse(line, TimestampToken(entry._timestamp), " ", BareStringToken(entry._userId), " TASK ", IntToken(taskId), " START")) { entry._type = LogEntryType_TASK_START; entry._taskId = taskId; } else if (parse(line, TimestampToken(entry._timestamp), " ", BareStringToken(entry._userId), " TASK ", IntToken(taskId), " PAUSE")) { entry._type = LogEntryType_TASK_PAUSE; entry._taskId = taskId; } else if (parse(line, TimestampToken(entry._timestamp), " ", BareStringToken(entry._userId), " TASK ", IntToken(taskId), " FINISH")) { entry._type = LogEntryType_TASK_FINISH; entry._taskId = taskId; } else if (boost::iequals(line, "END LOG")) { loop = false; } else { throw ProtocolError("Invalid log entry", line); } if (loop) { employeeIds.insert(entry._userId); insertLogEntry(entry); } } for (const auto& employeeId : employeeIds) { processLogs(employeeId); } emit tasksStatusChanged(); } else { throw ProtocolError("Invalid command", line); } }