void FileDef::acquireFileVersion() { QCString vercmd = Config_getString("FILE_VERSION_FILTER"); if (!vercmd.isEmpty() && filepath!="generated") { msg("Version of %s : ",filepath.data()); QCString cmd = vercmd+" \""+filepath+"\""; Debug::print(Debug::ExtCmd,0,"Executing popen(`%s`)\n",cmd.data()); FILE *f=portable_popen(cmd,"r"); if (!f) { err("error: could not execute %s\n",vercmd.data()); return; } const int bufSize=1024; char buf[bufSize]; int numRead = fread(buf,1,bufSize,f); portable_pclose(f); if (numRead > 0) { fileVersion = QCString(buf,numRead).stripWhiteSpace(); msg("%s\n",fileVersion.data()); } else { msg("no version available\n"); } } }
KeyList BaseG::parseKeyList(const QCString &output, bool secretKeys) { KeyList keys; Key *key = 0; int offset; // search start of key data if(!strncmp(output.data(), "pub:", 4) || !strncmp(output.data(), "sec:", 4)) offset = 0; else { if(secretKeys) offset = output.find("\nsec:"); else offset = output.find("\npub:"); if(offset == -1) return keys; else offset++; } do { key = parseKeyData(output, offset); if(key != 0) keys.append(key); } while(key != 0); //kdDebug(5100) << "finished parsing keys" << endl; return keys; }
void NDnsWorker::run() { hostent *h = 0; #ifdef HAVE_GETHOSTBYNAME_R hostent buf; char char_buf[1024]; int err; gethostbyname_r(host.data(), &buf, char_buf, sizeof(char_buf), &h, &err); #else // lock for gethostbyname QMutexLocker locker(workerMutex); // check for cancel workerCancelled->lock(); bool cancel = cancelled; workerCancelled->unlock(); if(!cancel) h = gethostbyname(host.data()); #endif if(!h) { success = false; QApplication::postEvent(par, new NDnsWorkerEvent(this)); return; } in_addr a = *((struct in_addr *)h->h_addr_list[0]); addr.setAddress(ntohl(a.s_addr)); success = true; QApplication::postEvent(par, new NDnsWorkerEvent(this)); }
int main(int argc, char *argv[]) { KApplication::kdeinitExec("konsole"); KApplication k(argc, argv, "klaunchertest"); kapp->dcopClient()->registerAs(kapp->name()); #if 0 QString error; QCString dcopService; int pid; int result = KApplication::startServiceByDesktopName( QString::fromLatin1("konsole"), QString::null, &error, &dcopService, &pid ); printf("Result = %d, error = \"%s\", dcopService = \"%s\", pid = %d\n", result, error.ascii(), dcopService.data(), pid); result = KApplication::startServiceByDesktopName( QString::fromLatin1("konqueror"), QString::null, &error, &dcopService, &pid ); printf("Result = %d, error = \"%s\", dcopService = \"%s\", pid = %d\n", result, error.ascii(), dcopService.data(), pid); #endif }
void queryObjects(const QCString &app, const QCString &filter) { int filterLen = filter.length(); bool ok = false; bool isDefault = false; KStringList objs = dcop->remoteObjects(app, &ok); for(const auto &objId : objs) { if(objId == "default") { isDefault = true; continue; } if(startsWith(objId, filter, filterLen)) { if(isDefault) printf("%s (default)\n", objId.data()); else printf("%s\n", objId.data()); } isDefault = false; } if(!ok) { if(!dcop->isApplicationRegistered(app)) qWarning("No such application: '%s'", app.data()); else qWarning("Application '%s' not accessible", app.data()); exit(1); } }
void OContactAccessBackend_XML::updateJournal( const OContact& cnt, journal_action action ) { QFile f( m_journalName ); bool created = !f.exists(); if ( !f.open(IO_WriteOnly|IO_Append) ) return; QString buf; QCString str; // if the file was created, we have to set the Tag "<CONTACTS>" to // get a XML-File which is readable by our parser. // This is just a cheat, but better than rewrite the parser. if ( created ){ buf = "<Contacts>"; QCString cstr = buf.utf8(); f.writeBlock( cstr.data(), cstr.length() ); } buf = "<Contact "; cnt.save( buf ); buf += " action=\"" + QString::number( (int)action ) + "\" "; buf += "/>\n"; QCString cstr = buf.utf8(); f.writeBlock( cstr.data(), cstr.length() ); }
QCString dcopNetworkId() { QCString result; result.resize(1025); QFile file(DCOPClient::dcopServerFile()); if (!file.open(IO_ReadOnly)) return ""; int i = file.readLine(result.data(), 1024); if (i <= 0) return ""; result.data()[i-1] = '\0'; // strip newline return result; }
bool ODateBookAccessBackend_XML::save() { if (!m_changed) return true; int total_written; QString strFileNew = m_name + ".new"; QFile f( strFileNew ); if (!f.open( IO_WriteOnly | IO_Raw ) ) return false; QString buf( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); buf += "<!DOCTYPE DATEBOOK><DATEBOOK>\n"; buf += "<events>\n"; QCString str = buf.utf8(); total_written = f.writeBlock( str.data(), str.length() ); if ( total_written != int(str.length() ) ) { f.close(); QFile::remove( strFileNew ); return false; } if (!forAll( m_raw, f ) ) { f.close(); QFile::remove( strFileNew ); return false; } if (!forAll( m_rep, f ) ) { f.close(); QFile::remove( strFileNew ); return false; } buf = "</events>\n</DATEBOOK>\n"; str = buf.utf8(); total_written = f.writeBlock( str.data(), str.length() ); if ( total_written != int(str.length() ) ) { f.close(); QFile::remove( strFileNew ); return false; } f.close(); if ( ::rename( strFileNew, m_name ) < 0 ) { QFile::remove( strFileNew ); return false; } m_changed = false; return true; }
bool DM::localSessions(SessList &list) { if(DMType == OldKDM) return false; QCString re; if(DMType == GDM) { if(!exec("CONSOLE_SERVERS\n", re)) return false; QStringList sess = QStringList::split(QChar(';'), re.data() + 3); for(QStringList::ConstIterator it = sess.begin(); it != sess.end(); ++it) { QStringList ts = QStringList::split(QChar(','), *it, true); SessEnt se; se.display = ts[0]; se.user = ts[1]; se.vt = ts[2].toInt(); se.session = "<unknown>"; se.self = ts[0] == ::getenv("DISPLAY"); /* Bleh */ se.tty = false; list.append(se); } } else { if(!exec("list\talllocal\n", re)) return false; QStringList sess = QStringList::split(QChar('\t'), re.data() + 3); for(QStringList::ConstIterator it = sess.begin(); it != sess.end(); ++it) { QStringList ts = QStringList::split(QChar(','), *it, true); SessEnt se; se.display = ts[0]; if(ts[1][0] == '@') se.from = ts[1].mid(1), se.vt = 0; else se.vt = ts[1].mid(2).toInt(); se.user = ts[2]; se.session = ts[3]; se.self = (ts[4].find('*') >= 0); se.tty = (ts[4].find('t') >= 0); list.append(se); } } return true; }
static void format_warn(const char *file,int line,const char *text) { QCString fileSubst = file==0 ? "<unknown>" : file; QCString lineSubst; lineSubst.setNum(line); QCString textSubst = text; QCString versionSubst; if (file) // get version from file name { bool ambig; FileDef *fd=findFileDef(Doxygen::inputNameDict,file,ambig); if (fd) { versionSubst = fd->getVersion(); } } // substitute markers by actual values QCString msgText = substitute( substitute( substitute( substitute( outputFormat, "$file",fileSubst ), "$text",textSubst ), "$line",lineSubst ), "$version",versionSubst )+'\n'; // print resulting message fwrite(msgText.data(),1,msgText.length(),warnFile); }
static void qDBusObjectPathKeyMapToIterator(DBusMessageIter* it, const QDBusData& var) { DBusMessageIter sub; QCString sig; QDBusDataMap<QDBusObjectPath> map = var.toObjectPathKeyMap(); sig += DBUS_DICT_ENTRY_BEGIN_CHAR; sig += qDBusTypeForQDBusType(map.keyType()); if (map.hasContainerValueType()) sig += map.containerValueType().buildDBusSignature(); else sig += qDBusTypeForQDBusType(map.valueType()); sig += DBUS_DICT_ENTRY_END_CHAR; dbus_message_iter_open_container(it, DBUS_TYPE_ARRAY, sig.data(), &sub); QDBusDataMap<QDBusObjectPath>::ConstIterator mit = map.begin(); for (; mit != map.end(); ++mit) { DBusMessageIter itemIterator; dbus_message_iter_open_container(&sub, DBUS_TYPE_DICT_ENTRY, 0, &itemIterator); qAppendToMessage(&itemIterator, mit.key()); qDBusDataToIterator(&itemIterator, mit.data()); dbus_message_iter_close_container(&sub, &itemIterator); } dbus_message_iter_close_container(it, &sub); }
void send(QSocketDevice& socket, const QString& type, const QStringList& args, bool debug) { TclObject list; list.lappend(type); for (unsigned int i = 0; i < args.size(); ++i) list.lappend(args[i]); if (debug) logDebug("send: " + list.toString()); QString message = list.toString(); if (message.contains('\n')) message = "\002" + message + "\003"; else message += "\n"; QCString data = message.utf8(); int len = data.length(); int pos = 0; while (pos < len) { int count = socket.writeBlock(data.data() + pos, len - pos); socket.flush(); if (count == -1) { logError("writeBlock error: %d", errno); exit(4); } pos += count; } }
void ConnectionHandler::respond(int ok, QCString s) { QCString buf; switch(ok) { case Res_OK: buf = "OK"; break; case Res_NO: default: buf = "NO"; break; } if(!s.isEmpty()) { buf += ' '; buf += s; } buf += '\n'; send(m_Fd, buf.data(), buf.length(), 0); }
QCString SshProcess::dcopForward() { QCString result; setDcopTransport("tcp"); QCString srv = StubProcess::dcopServer(); if(srv.isEmpty()) return result; int i = srv.find('/'); if(i == -1) return result; if(srv.left(i) != "tcp") return result; int j = srv.find(':', ++i); if(j == -1) return result; QCString host = srv.mid(i, j - i); bool ok; int port = srv.mid(++j).toInt(&ok); if(!ok) return result; m_dcopPort = 10000 + (int)((40000.0 * rand()) / (1.0 + RAND_MAX)); result.sprintf("%d:%s:%d", m_dcopPort, host.data(), port); return result; }
bool DCOPRef::sendInternal(const QCString &fun, const QCString &args, const QByteArray &data) { if(isNull()) { qWarning("DCOPRef: send '%s' on null reference error", STR(fun)); return false; } Q_UNUSED(data); QCString sig = fun; if(fun.find('(') == -1) { sig += args; if(args.find("<unknown") != -1) qWarning( "DCOPRef: unknown type error " "<\"%s\",\"%s\">::send(\"%s\",%s", STR(m_app), STR(m_obj), STR(fun), args.data() + 1); } DCOPClient *dc = dcopClient(); if(!dc || !dc->isAttached()) { qWarning("DCOPRef::send(): no DCOP client or client not attached error"); return false; } return dc->send(m_app, m_obj, sig, data); }
bool DM::bootOptions(QStringList &opts, int &defopt, int ¤t) { if(DMType != NewKDM) return false; QCString re; if(!exec("listbootoptions\n", re)) return false; opts = QStringList::split('\t', QString::fromLocal8Bit(re.data())); if(opts.size() < 4) return false; bool ok; defopt = opts[2].toInt(&ok); if(!ok) return false; current = opts[3].toInt(&ok); if(!ok) return false; opts = QStringList::split(' ', opts[1]); for(QStringList::Iterator it = opts.begin(); it != opts.end(); ++it) (*it).replace("\\s", " "); return true; }
bool doCompileAndLink(const QString &filedata, const QString &flags, int *retcode=0) { QDir dir("."); QString fname = "atest.c"; QString out = "atest"; QFile f(fname); QCString cs = filedata.latin1(); if(!f.open(IO_WriteOnly | IO_Truncate)) { debug("unable to open atest.c for writing"); return false; } if(f.writeBlock(cs.data(), cs.length()) == -1) { debug("error writing to atest.c"); return false; } f.close(); debug(QString("Wrote atest.c:\n%1").arg(filedata)); QString str = qvar("QMAKE_CXX") + ' ' + fname + " -o " + out; if(!flags.isEmpty()) { str += ' '; str += flags; } int r = doCommand(str); if(r == 0 && retcode) *retcode = doCommand(QString("./") + out); dir.remove(fname); dir.remove(out); if(r != 0) return false; return true; }
int KNFile::findString(const char *s) { QCString searchBuffer; searchBuffer.resize(2048); char *buffPtr = searchBuffer.data(), *pos; int readBytes, currentFilePos; while(!atEnd()) { currentFilePos = at(); readBytes = readBlock(buffPtr, 2047); if(readBytes == -1) return -1; else buffPtr[readBytes] = 0; // terminate string pos = strstr(buffPtr, s); if(pos == 0) { if(!atEnd()) at(at() - strlen(s)); else return -1; } else { return currentFilePos + (pos - buffPtr); } } return -1; }
static QCString encodeDirName(const QCString &anchor) { // convert to md5 hash uchar md5_sig[16]; QCString sigStr(33); MD5Buffer((const unsigned char *)anchor.data(),anchor.length(),md5_sig); MD5SigToString(md5_sig,sigStr.rawData(),33); return sigStr; // old algorithm // QCString result; // int l = anchor.length(),i; // for (i=0;i<l;i++) // { // char c = anchor.at(i); // if ((c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9')) // { // result+=c; // } // else // { // static char hexStr[]="0123456789ABCDEF"; // char escChar[]={ '_', 0, 0, 0 }; // escChar[1]=hexStr[c>>4]; // escChar[2]=hexStr[c&0xf]; // result+=escChar; // } // } // return result; }
int GaduSession::sendMessage( uin_t recipient, const Kopete::Message& msg, int msgClass ) { QString sendMsg; QCString cpMsg; KGaduMessage* gadumessage; if ( isConnected() ) { gadumessage = rtf->convertToGaduMessage( msg ); if ( gadumessage ) { const void* data = (const void*)gadumessage->rtf.data(); cpMsg = textcodec->fromUnicode( gadumessage->message ); int o; o = gg_send_message_richtext( session_, msgClass, recipient, (const unsigned char *)cpMsg.data(), (const unsigned char*) data, gadumessage->rtf.size() ); gadumessage->rtf.resize(0); delete gadumessage; return o; } else { sendMsg = msg.plainBody(); sendMsg.replace( QString::fromAscii( "\n" ), QString::fromAscii( "\r\n" ) ); cpMsg = textcodec->fromUnicode( sendMsg ); return gg_send_message( session_, msgClass, recipient, (const unsigned char *)cpMsg.data() ); } } else { emit error( i18n("Not Connected"), i18n("You are not connected to the server.") ); } return 1; }
bool ReadOnlyPart::openURL( const KURL &url ) { if ( url.isMalformed() || !closeURL() ) return false; m_url = url; emit setWindowCaption( m_url.prettyURL() ); if ( m_url.isLocalFile() && m_url.query().isEmpty() ) { emit started( 0 ); m_file = m_url.path(); bool ret = openFile(); if ( ret ) emit completed(); return ret; } m_job = KIO::get( m_url, false, false ); m_file = m_url.fileName(); if ( m_url.isLocalFile() && m_url.query().startsWith( "??" ) ) { m_file = m_url.query().mid( 2 ); int sl = m_file.findRev( '/' ); if ( sl >= 0 ) m_file.remove( 0, sl + 1 ); } int extensionPos = m_file.findRev( '.' ); if ( extensionPos > 0 ) m_file.remove( 0, extensionPos ); else m_file = ""; // HACK: the m_job is assumed to be unique // we also assume sizeof(m_job) == sizeof(ulong) m_file.prepend( QString::number( (ulong)m_job, 36 ) ); m_file.prepend( QString::fromLatin1( "/tmp/.konqe-part-%1" ) ); QCString fn; int fd = -1; for ( int i = 0; ( fd == -1 ) && ( i < TMP_MAX ); i++ ) { fn = QFile::encodeName( m_file.arg( (ulong)::random(), 0, 36 ) ); fd = ::open( fn.data(), O_RDWR | O_CREAT | O_EXCL, 0600 ); } if ( fd == -1 ) { abortLoad(); emit canceled( i18n( "File I/O Error" ) ); return false; } m_tempFile.setName( QFile::decodeName( fn ) ); m_tempFile.open( IO_ReadWrite, fd ); m_file = ""; // Don't allow accesses while downloading connect( m_job, SIGNAL( destroyed() ), SLOT( slotJobDestroyed () ) ); connect( m_job, SIGNAL( result( KIO::Job * ) ), SLOT( slotJobFinished ( KIO::Job * ) ) ); connect( m_job, SIGNAL( data( KIO::Job*, const QByteArray &) ), SLOT( slotData( KIO::Job*, const QByteArray & ) ) ); emit started( m_job ); return true; }
void Qhp::finalize() { // Finish TOC handlePrevSection(); for (int i = m_prevSectionLevel; i > 0; i--) { m_toc.close("section"); } m_toc.close("toc"); m_doc.insert(m_toc); // Finish index m_index.close("keywords"); m_doc.insert(m_index); // Finish files m_files.close("files"); m_doc.insert(m_files); m_doc.close("filterSection"); m_doc.close("QtHelpProject"); QCString fileName = Config_getString(HTML_OUTPUT) + "/" + getQhpFileName(); QFile file(fileName); if (!file.open(IO_WriteOnly)) { err("Could not open file %s for writing\n", fileName.data()); exit(1); } m_doc.dumpTo(file); }
int XmlProtocol::internalWriteString(const QString &s, TrackItem::Type t, int id) { QCString cs = s.utf8(); QByteArray a(cs.length()); memcpy(a.data(), cs.data(), a.size()); return internalWriteData(a, t, id); }
void KoXmlWriter::addAttributePt( const char* attrName, double value ) { QCString str; str.setNum( value, 'g', DBL_DIG ); str += "pt"; addAttribute( attrName, str.data() ); }
void GaduSession::login( KGaduLoginParams* loginp ) { QCString desc = textcodec->fromUnicode( loginp->statusDescr ); memset( ¶ms_, 0, sizeof(params_) ); params_.status_descr = (char*)desc.data(); params_.uin = loginp->uin; params_.password = (char *)( loginp->password.ascii() ); params_.status = loginp->status | ( loginp->forFriends ? GG_STATUS_FRIENDS_MASK : 0 ); params_.async = 1; params_.tls = loginp->useTls; params_ .server_addr = loginp->server; params_.client_addr = loginp->client_addr; params_.client_port = loginp->client_port; kdDebug(14100) << "LOGIN IP: " << loginp->client_addr << endl; if ( loginp->useTls ) { params_.server_port = GG_HTTPS_PORT; } else { if ( loginp->server ) { params_.server_port = GG_DEFAULT_PORT; } } kdDebug(14100)<<"gadusession::login, server ( " << loginp->server << " ), tls(" << loginp->useTls << ") " <<endl; login( ¶ms_ ); }
DCOPReply DCOPRef::callInternal(const QCString &fun, const QCString &args, const QByteArray &data, EventLoopFlag useEventLoop, int timeout) { DCOPReply reply; if(isNull()) { qWarning("DCOPRef: call '%s' on null reference error", STR(fun)); return reply; } QCString sig = fun; if(fun.find('(') == -1) { sig += args; if(args.find("<unknown") != -1) qWarning( "DCOPRef: unknown type error " "<\"%s\",\"%s\">::call(\"%s\",%s", STR(m_app), STR(m_obj), STR(fun), args.data() + 1); } DCOPClient *dc = dcopClient(); if(!dc || !dc->isAttached()) { qWarning("DCOPRef::call(): no DCOP client or client not attached error"); return reply; } dc->call(m_app, m_obj, sig, data, reply.type, reply.data, useEventLoop == UseEventLoop, timeout); return reply; }
void Nntp::readyRead() { // new data arrived on the command socket // of we should read the list of available groups, let's do so if ( readGroups ) { parseGroups(); return; } // of we should read an article, let's do so if ( readArticle ) { parseArticle(); return; } // read the new data from the socket QCString s; s.resize( commandSocket->bytesAvailable() + 1 ); commandSocket->readBlock( s.data(), commandSocket->bytesAvailable() ); if ( !url() ) return; // of the code of the server response was 200, we know that the // server is ready to get commands from us now if ( s.left( 3 ) == "200" ) connectionReady = TRUE; }
void VhdlParser::oneLineComment(QCString qcs) { bool isEndCode=qcs.contains("\\endcode"); int index = qcs.find("\\code"); if (isEndCode) { int end = inputString.find(qcs.data(),iCodeLen); makeInlineDoc(end); } else if (index > 0) { // assert(false); strComment=qcs; startCodeBlock(index); strComment.resize(0); } if (!isEndCode && index==-1) { int j=qcs.find("--!"); qcs=qcs.right(qcs.length()-3-j); if (!checkMultiComment(qcs,iDocLine)) { handleCommentBlock(qcs,TRUE); } } }
/*! * \brief Initialize the Eclipse generator * * This method opens the XML TOC file and writes headers of the files. * \sa finalize() */ void EclipseHelp::initialize() { // -- read path prefix from the configuration //m_pathprefix = Config_getString("ECLIPSE_PATHPREFIX"); //if (m_pathprefix.isEmpty()) m_pathprefix = "html/"; // -- open the contents file QCString name = Config_getString("HTML_OUTPUT") + "/toc.xml"; m_tocfile = new QFile(name); if (!m_tocfile->open(IO_WriteOnly)) { err("Could not open file %s for writing\n", name.data()); exit(1); } // -- initialize its text stream m_tocstream.setDevice(m_tocfile); //m_tocstream.setEncoding(FTextStream::UnicodeUTF8); // -- write the opening tag QCString title = Config_getString("PROJECT_NAME"); if (title.isEmpty()) { title = "Doxygen generated documentation"; } m_tocstream << "<toc label=\"" << convertToXML(title) << "\" topic=\"" << convertToXML(m_pathprefix) << "index" << Doxygen::htmlFileExtension << "\">" << endl; ++ m_depth; }
void Slave::unlinkSocket() { if (m_socket.isEmpty()) return; QCString filename = QFile::encodeName(m_socket); unlink(filename.data()); m_socket = QString::null; }