bool KConfigBase::groupIsImmutable(const QString &group) const { if(getConfigState() != ReadWrite) return true; KEntryKey groupKey(group.utf8(), 0); KEntry entry = lookupData(groupKey); return entry.bImmutable; }
OsStatus SmsNotifier::handleAlarm(const OsTime alarmTime, const UtlString& callingHost, const cAlarmData* alarmData, const UtlString& alarmMsg) { OsStatus retval = OS_FAILED; //execute the mail command for each user UtlString groupKey(alarmData->getGroupName()); if (!groupKey.isNull()) { UtlContainable* pContact = mContacts.findValue(&groupKey); if (pContact) { // Process the comma separated list of contacts UtlString* contactList = dynamic_cast<UtlString*> (pContact); if (!contactList->isNull()) { MailMessage message(mSmsStrFrom, mReplyTo, mSmtpServer); UtlTokenizer tokenList(*contactList); UtlString entry; while (tokenList.next(entry, ",")) { message.To(entry, entry); } UtlString body; UtlString tempStr; UtlString sevStr = Os::Logger::instance().priorityName(alarmData->getSeverity()); body.append(alarmMsg); Os::Logger::instance().log(FAC_ALARM, PRI_DEBUG, "AlarmServer: sms body is %s", body.data()); message.Body(body); UtlSList subjectParams; UtlString codeStr(alarmData->getCode()); UtlString titleStr(sevStr); subjectParams.append(&codeStr); subjectParams.append(&titleStr); assembleMsg(mSmsStrSubject, subjectParams, tempStr); message.Subject(tempStr); // delegate send to separate task so as not to block EmailSendTask::getInstance()->sendMessage(message); } } } return retval; }
OsStatus EmailNotifier::handleAlarm(const OsTime alarmTime, const UtlString& callingHost, const cAlarmData* alarmData, const UtlString& alarmMsg) { OsStatus retval = OS_FAILED; //execute the mail command for each user UtlString groupKey(alarmData->getGroupName()); if (!groupKey.isNull()) { UtlContainable* pContact = mContacts.findValue(&groupKey); if (pContact) { // Process the comma separated list of contacts UtlString* contactList = dynamic_cast<UtlString*> (pContact); if (!contactList->isNull()) { MailMessage message(mEmailStrFrom, mReplyTo, mSmtpServer); UtlTokenizer tokenList(*contactList); UtlString entry; while (tokenList.next(entry, ",")) { message.To(entry, entry); } UtlString body; UtlString tempStr; body = mEmailStrIntro; body.append("\n"); assembleMsg(mEmailStrAlarm, alarmData->getCode(), tempStr); body.append(tempStr); body.append("\n"); assembleMsg(mEmailStrHost, callingHost, tempStr); body.append(tempStr); body.append("\n"); OsDateTime logTime(alarmTime); UtlString strTime; logTime.getIsoTimeStringZus(strTime); assembleMsg(mEmailStrTime, strTime, tempStr); body.append(tempStr); body.append("\n"); UtlString sevStr = OsSysLog::priorityName(alarmData->getSeverity()); assembleMsg(mEmailStrSeverity, sevStr, tempStr); body.append(tempStr); body.append("\n"); assembleMsg(mEmailStrDescription, alarmMsg, tempStr); body.append(tempStr); body.append("\n"); assembleMsg(mEmailStrResolution, alarmData->getResolution(), tempStr); body.append(tempStr); OsSysLog::add(FAC_ALARM, PRI_DEBUG, "AlarmServer: email body is %s", body.data()); message.Body(body); UtlSList subjectParams; UtlString codeStr(alarmData->getCode()); UtlString titleStr(alarmData->getShortTitle()); subjectParams.append(&codeStr); subjectParams.append(&titleStr); assembleMsg(mEmailStrSubject, subjectParams, tempStr); message.Subject(tempStr); // delegate send to separate task so as not to block EmailSendTask::getInstance()->sendMessage(message); } } } return retval; }
void KConfigINIBackEnd::parseSingleConfigFile(QFile &rFile, KEntryMap *pWriteBackMap, bool bGlobal, bool bDefault) { const char *s; // May get clobbered by sigsetjump, but we don't use them afterwards. const char *eof; // May get clobbered by sigsetjump, but we don't use them afterwards. QByteArray data; if(!rFile.isOpen()) // come back, if you have real work for us ;-> return; // using kdDebug() here leads to an infinite loop // remove this for the release, aleXXX // qWarning("Parsing %s, global = %s default = %s", // rFile.name().latin1(), bGlobal ? "true" : "false", bDefault ? "true" : "false"); QCString aCurrentGroup("<default>"); unsigned int ll = localeString.length(); #ifdef HAVE_MMAP static volatile const char *map; map = (const char *)mmap(0, rFile.size(), PROT_READ, MAP_PRIVATE, rFile.handle(), 0); if(map != MAP_FAILED) { s = (const char *)map; eof = s + rFile.size(); #ifdef SIGBUS struct sigaction act; act.sa_handler = mmap_sigbus_handler; sigemptyset(&act.sa_mask); #ifdef SA_ONESHOT act.sa_flags = SA_ONESHOT; #else act.sa_flags = SA_RESETHAND; #endif sigaction(SIGBUS, &act, &mmap_old_sigact); if(sigsetjmp(mmap_jmpbuf, 1)) { qWarning("SIGBUS while reading %s", rFile.name().latin1()); munmap((char *)map, rFile.size()); sigaction(SIGBUS, &mmap_old_sigact, 0); return; } #endif } else #endif { rFile.at(0); data = rFile.readAll(); s = data.data(); eof = s + data.size(); } bool fileOptionImmutable = false; bool groupOptionImmutable = false; bool groupSkip = false; int line = 0; for(; s < eof; s++) { line++; while((s < eof) && isspace(*s) && (*s != '\n')) s++; // skip leading whitespace, shouldn't happen too often // skip empty lines, lines starting with # if((s < eof) && ((*s == '\n') || (*s == '#'))) { sktoeol: // skip till end-of-line while((s < eof) && (*s != '\n')) s++; continue; // Empty or comment or no keyword } const char *startLine = s; if(*s == '[') // group { // In a group [[ and ]] have a special meaning while((s < eof) && (*s != '\n')) { if(*s == ']') { if((s + 1 < eof) && (*(s + 1) == ']')) s++; // Skip "]]" else break; } s++; // Search till end of group } const char *e = s; while((s < eof) && (*s != '\n')) s++; // Search till end of line / end of file if((e >= eof) || (*e != ']')) { fprintf(stderr, "Invalid group header at %s:%d\n", rFile.name().latin1(), line); continue; } // group found; get the group name by taking everything in // between the brackets if((e - startLine == 3) && (startLine[1] == '$') && (startLine[2] == 'i')) { if(!kde_kiosk_exception) fileOptionImmutable = true; continue; } aCurrentGroup = decodeGroup(startLine + 1, e - startLine); // cout<<"found group ["<<aCurrentGroup<<"]"<<endl; // Backwards compatibility if(aCurrentGroup == "KDE Desktop Entry") aCurrentGroup = "Desktop Entry"; groupOptionImmutable = fileOptionImmutable; e++; if((e + 2 < eof) && (*e++ == '[') && (*e++ == '$')) // Option follows { if((*e == 'i') && !kde_kiosk_exception) { groupOptionImmutable = true; } } KEntryKey groupKey(aCurrentGroup, 0); KEntry entry = pConfig->lookupData(groupKey); groupSkip = entry.bImmutable; if(groupSkip && !bDefault) continue; entry.bImmutable |= groupOptionImmutable; pConfig->putData(groupKey, entry, false); if(pWriteBackMap) { // add the special group key indicator (*pWriteBackMap)[groupKey] = entry; } continue; } if(groupSkip && !bDefault) goto sktoeol; // Skip entry bool optionImmutable = groupOptionImmutable; bool optionDeleted = false; bool optionExpand = false; const char *endOfKey = 0, *locale = 0, *elocale = 0; for(; (s < eof) && (*s != '\n'); s++) { if(*s == '=') // find the equal sign { if(!endOfKey) endOfKey = s; goto haveeq; } if(*s == '[') // find the locale or options. { const char *option; const char *eoption; endOfKey = s; option = ++s; for(;; s++) { if((s >= eof) || (*s == '\n') || (*s == '=')) { fprintf(stderr, "Invalid entry (missing ']') at %s:%d\n", rFile.name().latin1(), line); goto sktoeol; } if(*s == ']') break; } eoption = s; if(*option != '$') { // Locale if(locale) { fprintf(stderr, "Invalid entry (second locale!?) at %s:%d\n", rFile.name().latin1(), line); goto sktoeol; } locale = option; elocale = eoption; } else { // Option while(option < eoption) { option++; if((*option == 'i') && !kde_kiosk_exception) optionImmutable = true; else if(*option == 'e') optionExpand = true; else if(*option == 'd') { optionDeleted = true; goto haveeq; } else if(*option == ']') break; } } } } fprintf(stderr, "Invalid entry (missing '=') at %s:%d\n", rFile.name().latin1(), line); continue; haveeq: for(endOfKey--;; endOfKey--) { if(endOfKey < startLine) { fprintf(stderr, "Invalid entry (empty key) at %s:%d\n", rFile.name().latin1(), line); goto sktoeol; } if(!isspace(*endOfKey)) break; } const char *st = ++s; while((s < eof) && (*s != '\n')) s++; // Search till end of line / end of file if(locale) { unsigned int cl = static_cast< unsigned int >(elocale - locale); if((ll != cl) || memcmp(locale, localeString.data(), ll)) { // backward compatibility. C == en_US if(cl != 1 || ll != 5 || *locale != 'C' || memcmp(localeString.data(), "en_US", 5)) { // cout<<"mismatched locale '"<<QCString(locale, elocale-locale +1)<<"'"<<endl; // We can ignore this one if(!pWriteBackMap) continue; // We just ignore it // We just store it as is to be able to write it back later. endOfKey = elocale; locale = 0; } } } // insert the key/value line QCString key(startLine, endOfKey - startLine + 2); QCString val = printableToString(st, s - st); // qDebug("found key '%s' with value '%s'", key.data(), val.data()); KEntryKey aEntryKey(aCurrentGroup, decodeKey(key)); aEntryKey.bLocal = (locale != 0); aEntryKey.bDefault = bDefault; KEntry aEntry; aEntry.mValue = val; aEntry.bGlobal = bGlobal; aEntry.bImmutable = optionImmutable; aEntry.bDeleted = optionDeleted; aEntry.bExpand = optionExpand; aEntry.bNLS = (locale != 0); if(pWriteBackMap) { // don't insert into the config object but into the temporary // scratchpad map pWriteBackMap->insert(aEntryKey, aEntry); } else { // directly insert value into config object // no need to specify localization; if the key we just // retrieved was localized already, no need to localize it again. pConfig->putData(aEntryKey, aEntry, false); } } if(fileOptionImmutable) bFileImmutable = true; #ifdef HAVE_MMAP if(map) { munmap((char *)map, rFile.size()); #ifdef SIGBUS sigaction(SIGBUS, &mmap_old_sigact, 0); #endif } #endif }