Esempio n. 1
0
void RTFDocVisitor::visitPre(DocSection *s)
{
  if (m_hide) return;
  DBG_RTF("{\\comment RTFDocVisitor::visitPre(DocSection)}\n");
  if (!m_lastIsPara) m_t << "\\par" << endl;
  m_t << "{\\bkmkstart " << rtfFormatBmkStr(s->file()+"_"+s->anchor()) << "}" << endl;
  m_t << "{\\bkmkend " << rtfFormatBmkStr(s->file()+"_"+s->anchor()) << "}" << endl;
  m_t << "{{" // start section
      << rtf_Style_Reset;
  QCString heading;
  int level = QMIN(s->level()+1,4);
  heading.sprintf("Heading%d",level);
  // set style
  m_t << rtf_Style[heading]->reference << endl;
  // make table of contents entry
  filter(s->title());
  m_t << endl << "\\par" << "}" << endl;
  m_t << "{\\tc\\tcl" << level << " \\v ";
  filter(s->title());
  m_t << "}" << endl;
  m_lastIsPara=TRUE;
}
Esempio n. 2
0
int main(int argc, char ** argv)
{
  int port_index;
  
  if (argc == 2)
    port_index = 1;
  else if (argc == 3) {
    set_verbose();
    port_index = 2;
  }
  else
    return 0;
  
  if (UmlCom::connect(QCString(argv[port_index]).toUInt())) {
    try {
      UmlCom::trace("<b>IDL generator</b> release 2.15<br>");
      
      UmlCom::targetItem()->generate();
      
      QCString s;
      
      s.sprintf("<hr><font face=helvetica>Generation done : %d warnings, %d errors</font><br>",
		n_warnings(), n_errors());
      UmlCom::trace(s);
      
      UmlCom::message("");
    
      UmlCom::bye(n_errors());
    }
    catch (...) {
    }
  }
  
  UmlCom::close();
  return 0;
}
Esempio n. 3
0
void UmlNode::importIt(FileIn & in, Token & token, UmlItem * where)
{
  where = where->container(aNode, token, in);
  
  if (where == 0)
    return;
    
  QCString s = token.valueOf("name");
  
  if (s.isEmpty()) {
    static unsigned n = 0;
    
    s.sprintf("anonymous_node_%u", ++n);
  }
    
  UmlNode * node = create((UmlDeploymentView *) where, s);
  
  if (node == 0)
    in.error("cannot create node '" + s +
	     "' in '" + where->name() + "'");
  
  node->addItem(token.xmiId(), in);
  
  if (token.xmiType() == "uml:Device")
    node->set_Stereotype("device");

  if (! token.closed()) {
    QCString k = token.what();
    const char * kstr = k;
    
    while (in.read(), !token.close(kstr))
      node->UmlItem::import(in, token);
  }

  node->unload(TRUE, FALSE);
}
Esempio n. 4
0
int KDEsuClient::setPriority(int prio)
{
    QCString cmd;
    cmd.sprintf("PRIO %d\n", prio);
    return command(cmd);
}
Esempio n. 5
0
void KDesktopConfig::load( bool useDefaults )
{
  // get number of desktops
  NETRootInfo info( qt_xdisplay(), NET::NumberOfDesktops | NET::DesktopNames );
  int n = info.numberOfDesktops();

  int konq_screen_number = 0;
  if (qt_xdisplay())
     konq_screen_number = DefaultScreen(qt_xdisplay());

  QCString groupname;
  if (konq_screen_number == 0)
     groupname = "Desktops";
  else
     groupname.sprintf("Desktops-screen-%d", konq_screen_number);

  KConfig * kwinconfig = new KConfig("kwinrc");

  kwinconfig->setReadDefaults( useDefaults );

  kwinconfig->setGroup("Desktops");
  for(int i = 1; i <= maxDesktops; i++)
  {
    QString key_name(QString("Name_") + QString::number(i));
    QString name = QString::fromUtf8(info.desktopName(i));
    if (name.isEmpty()) // Get name from configuration if none is set in the WM.
    {
        name = kwinconfig->readEntry(key_name, i18n("Desktop %1").arg(i));
    }
    _nameInput[i-1]->setText(name);

    // Is this entry immutable or not in the range of configured desktops?
    _labelImmutable[i - 1] = kwinconfig->entryIsImmutable(key_name);
    _nameInput[i-1]->setEnabled(i <= n && !_labelImmutable[i - 1]);
  }

  _numInput->setEnabled(!kwinconfig->entryIsImmutable("Number"));

  delete kwinconfig;
  kwinconfig = 0;

  QString configfile;
  if (konq_screen_number == 0)
      configfile = "kdesktoprc";
  else
      configfile.sprintf("kdesktop-screen-%drc", konq_screen_number);

  KConfig *config = new KConfig(configfile, false, false);

  config->setReadDefaults( useDefaults );

  config->setGroup("Mouse Buttons");
  _wheelOption->setChecked(config->readBoolEntry("WheelSwitchesWorkspace",false));

  _wheelOptionImmutable = config->entryIsImmutable("WheelSwitchesWorkspace");

  if (_wheelOptionImmutable || n<2)
     _wheelOption->setEnabled( false );

  delete config;
  config = 0;

  _numInput->setValue(n);
  emit changed( useDefaults );
}
Esempio n. 6
0
int main(int argc, char **argv)
{
    // Ensure that user configuration doesn't change the results of those tests
    // KDEHOME needs to be writable though, for a ksycoca database
    setenv("KDEHOME", QFile::encodeName(QDir::homeDirPath() + "/.kde-kurifiltertest"), true);
    setenv("KDE_FORK_SLAVES", "yes", true); // simpler, for the final cleanup

    KAboutData aboutData(appName, programName, version, description);
    KCmdLineArgs::init(argc, argv, &aboutData);
    KCmdLineArgs::addCmdLineOptions(options);

    KApplication app;
    app.disableAutoDcopRegistration();

    // Allow testing of the search engine using both delimiters...
    char delimiter = KCmdLineArgs::parsedArgs()->isSet("s") ? ' ' : ':';

    // Many tests check the "default search engine" feature.
    // There is no default search engine by default (since it was annoying when making typos),
    // so the user has to set it up, which we do here.
    {
        KSimpleConfig cfg("kuriikwsfilterrc");
        cfg.setGroup("General");
        cfg.writeEntry("DefaultSearchEngine", "google");
        cfg.writeEntry("Verbose", true);
        cfg.writeEntry("KeywordDelimiter", delimiter);
        cfg.sync();
    }

    // Enable verbosity for debugging
    {
        KSimpleConfig cfg("kshorturifilterrc");
        cfg.writeEntry("Verbose", true);
        cfg.sync();
    }

    QStringList minicliFilters;
    minicliFilters << "kshorturifilter"
                   << "kurisearchfilter"
                   << "localdomainurifilter";

    // URI that should require no filtering
    filter("http://www.kde.org", "http://www.kde.org", KURIFilterData::NET_PROTOCOL);
    filter("http://www.kde.org/developer//index.html", "http://www.kde.org/developer//index.html", KURIFilterData::NET_PROTOCOL);
    // URL with reference
    filter("http://www.kde.org/index.html#q8", "http://www.kde.org/index.html#q8", KURIFilterData::NET_PROTOCOL);
    // local file with reference
    filter("file:/etc/passwd#q8", "file:///etc/passwd#q8", KURIFilterData::LOCAL_FILE);
    filter("file:///etc/passwd#q8", "file:///etc/passwd#q8", KURIFilterData::LOCAL_FILE);
    filter("/etc/passwd#q8", "file:///etc/passwd#q8", KURIFilterData::LOCAL_FILE);
    // local file with query (can be used by javascript)
    filter("file:/etc/passwd?foo=bar", "file:///etc/passwd?foo=bar", KURIFilterData::LOCAL_FILE);
    testLocalFile("/tmp/kurifiltertest?foo");     // local file with ? in the name (#58990)
    testLocalFile("/tmp/kurlfiltertest#foo");     // local file with '#' in the name
    testLocalFile("/tmp/kurlfiltertest#foo?bar"); // local file with both
    testLocalFile("/tmp/kurlfiltertest?foo#bar"); // local file with both, the other way round

    // hostnames are lowercased by KURL
    filter("http://www.myDomain.commyPort/ViewObjectRes//Default:name=hello", "http://www.mydomain.commyport/ViewObjectRes//Default:name=hello",
           KURIFilterData::NET_PROTOCOL);
    filter("ftp://ftp.kde.org", "ftp://ftp.kde.org", KURIFilterData::NET_PROTOCOL);
    filter("ftp://[email protected]:500", "ftp://[email protected]:500", KURIFilterData::NET_PROTOCOL);

    // ShortURI/LocalDomain filter tests. NOTE: any of these tests can fail
    // if you have specified your own patterns in kshorturifilterrc. For
    // examples, see $KDEDIR/share/config/kshorturifilterrc .
    filter("linuxtoday.com", "http://linuxtoday.com", KURIFilterData::NET_PROTOCOL);
    filter("LINUXTODAY.COM", "http://linuxtoday.com", KURIFilterData::NET_PROTOCOL);
    filter("kde.org", "http://kde.org", KURIFilterData::NET_PROTOCOL);
    filter("ftp.kde.org", "ftp://ftp.kde.org", KURIFilterData::NET_PROTOCOL);
    filter("ftp.kde.org:21", "ftp://ftp.kde.org:21", KURIFilterData::NET_PROTOCOL);
    filter("cr.yp.to", "http://cr.yp.to", KURIFilterData::NET_PROTOCOL);
    filter("[email protected]:3128", "http://[email protected]:3128", KURIFilterData::NET_PROTOCOL);
    filter("127.0.0.1", "http://127.0.0.1", KURIFilterData::NET_PROTOCOL);
    filter("127.0.0.1:3128", "http://127.0.0.1:3128", KURIFilterData::NET_PROTOCOL);
    filter("*****@*****.**", "mailto:[email protected]", KURIFilterData::NET_PROTOCOL);
    filter("*****@*****.**", "mailto:[email protected]", KURIFilterData::NET_PROTOCOL);
    filter("www.123.foo", "http://www.123.foo", KURIFilterData::NET_PROTOCOL);
    filter("[email protected]:3128", "http://[email protected]:3128", KURIFilterData::NET_PROTOCOL);

    // Exotic IPv4 address formats...
    filter("127.1", "http://127.1", KURIFilterData::NET_PROTOCOL);
    filter("127.0.1", "http://127.0.1", KURIFilterData::NET_PROTOCOL);

    // Local domain filter - If you uncomment these test, make sure you
    // you adjust it based on the localhost entry in your /etc/hosts file.
    // filter( "localhost:3128", "http://localhost.localdomain:3128", KURIFilterData::NET_PROTOCOL );
    // filter( "localhost", "http://localhost.localdomain", KURIFilterData::NET_PROTOCOL );
    // filter( "localhost/~blah", "http://localhost.localdomain/~blah", KURIFilterData::NET_PROTOCOL );

    filter("/", "/", KURIFilterData::LOCAL_DIR);
    filter("/", "/", KURIFilterData::LOCAL_DIR, "kshorturifilter");
    filter("~/.bashrc", QDir::homeDirPath().local8Bit() + "/.bashrc", KURIFilterData::LOCAL_FILE, "kshorturifilter");
    filter("~", QDir::homeDirPath().local8Bit(), KURIFilterData::LOCAL_DIR, "kshorturifilter", "/tmp");
    filter("~foobar", 0, KURIFilterData::ERROR, "kshorturifilter");
    filter("*****@*****.**", "mailto:[email protected]", KURIFilterData::NET_PROTOCOL); // new in KDE-3.2

    // Windows style SMB (UNC) URL. Should be converted into the valid smb format...
    filter("\\\\mainserver\\share\\file", "smb://mainserver/share/file", KURIFilterData::NET_PROTOCOL);

    // Should not be filtered at all. All valid protocols of this form will be ignored.
    filter("ftp:", "ftp:", KURIFilterData::UNKNOWN);
    filter("http:", "http:", KURIFilterData::UNKNOWN);

    /*
     Automatic searching tests. NOTE: If the Default search engine is set to 'None',
     this stuff will fail as the status returned will then be KURIFilterData::UNKNOWN.
    */
    filter("gg:", 0, KURIFilterData::NET_PROTOCOL);
    filter("KDE", 0, KURIFilterData::NET_PROTOCOL);
    filter("FTP", 0, KURIFilterData::NET_PROTOCOL);

    // If your default search engine is set to 'Google', you can uncomment the test below.
    filter("gg:", "http://www.google.com/search?q=gg%3A&ie=UTF-8&oe=UTF-8", KURIFilterData::NET_PROTOCOL);
    filter("KDE", "http://www.google.com/search?q=KDE&ie=UTF-8&oe=UTF-8", KURIFilterData::NET_PROTOCOL);
    filter("FTP", "http://www.google.com/search?q=FTP&ie=UTF-8&oe=UTF-8", KURIFilterData::NET_PROTOCOL);

    // Typing 'cp' or any other valid unix command in konq's location bar should result in
    // a search using the default search engine
    // 'ls' is a bit of a special case though, due to the toplevel domain called 'ls'
    filter("cp", "http://www.google.com/search?q=cp&ie=UTF-8&oe=UTF-8", KURIFilterData::NET_PROTOCOL, QStringList(), 0,
           false /* don't check for executables, see konq_misc.cc */);

    // Executable tests - No IKWS in minicli
    filter("cp", "cp", KURIFilterData::EXECUTABLE, minicliFilters);
    filter("kfmclient", "kfmclient", KURIFilterData::EXECUTABLE, minicliFilters);
    filter("xwininfo", "xwininfo", KURIFilterData::EXECUTABLE, minicliFilters);
    filter("KDE", "KDE", NO_FILTERING, minicliFilters);
    filter("I/dont/exist", "I/dont/exist", NO_FILTERING, minicliFilters);
    filter("/I/dont/exist", 0, KURIFilterData::ERROR, minicliFilters);
    filter("/I/dont/exist#a", 0, KURIFilterData::ERROR, minicliFilters);
    filter("kfmclient --help", "kfmclient --help", KURIFilterData::EXECUTABLE, minicliFilters); // the args are in argsAndOptions()
    filter("/usr/bin/gs", "/usr/bin/gs", KURIFilterData::EXECUTABLE, minicliFilters);
    filter("/usr/bin/gs -q -option arg1", "/usr/bin/gs -q -option arg1", KURIFilterData::EXECUTABLE,
           minicliFilters); // the args are in argsAndOptions()

    // ENVIRONMENT variable
    setenv("SOMEVAR", "/somevar", 0);
    setenv("ETC", "/etc", 0);

    QCString qtdir = getenv("QTDIR");
    QCString home = getenv("HOME");
    QCString kdehome = getenv("KDEHOME");

    filter("$SOMEVAR/kdelibs/kio", 0, KURIFilterData::ERROR); // note: this dir doesn't exist...
    filter("$ETC/passwd", "/etc/passwd", KURIFilterData::LOCAL_FILE);
    filter("$QTDIR/doc/html/functions.html#s", QCString("file://") + qtdir + "/doc/html/functions.html#s", KURIFilterData::LOCAL_FILE);
    filter("http://www.kde.org/$USER", "http://www.kde.org/$USER", KURIFilterData::NET_PROTOCOL); // no expansion

    // Assume the default (~/.kde) if
    if(kdehome.isEmpty())
    {
        kdehome += "$HOME/.kde";
        setenv("KDEHOME", kdehome.data(), 0);
    }

    filter("$KDEHOME/share", kdehome + "/share", KURIFilterData::LOCAL_DIR);
    KStandardDirs::makeDir(kdehome + "/a+plus");
    filter("$KDEHOME/a+plus", kdehome + "/a+plus", KURIFilterData::LOCAL_DIR);

    // BR 27788
    KStandardDirs::makeDir(kdehome + "/share/Dir With Space");
    filter("$KDEHOME/share/Dir With Space", kdehome + "/share/Dir With Space", KURIFilterData::LOCAL_DIR);

    // support for name filters (BR 93825)
    filter("$KDEHOME/*.txt", kdehome + "/*.txt", KURIFilterData::LOCAL_DIR);
    filter("$KDEHOME/[a-b]*.txt", kdehome + "/[a-b]*.txt", KURIFilterData::LOCAL_DIR);
    filter("$KDEHOME/a?c.txt", kdehome + "/a?c.txt", KURIFilterData::LOCAL_DIR);
    filter("$KDEHOME/?c.txt", kdehome + "/?c.txt", KURIFilterData::LOCAL_DIR);
    // but let's check that a directory with * in the name still works
    KStandardDirs::makeDir(kdehome + "/share/Dir*With*Stars");
    filter("$KDEHOME/share/Dir*With*Stars", kdehome + "/share/Dir*With*Stars", KURIFilterData::LOCAL_DIR);
    KStandardDirs::makeDir(kdehome + "/share/Dir?QuestionMark");
    filter("$KDEHOME/share/Dir?QuestionMark", kdehome + "/share/Dir?QuestionMark", KURIFilterData::LOCAL_DIR);
    KStandardDirs::makeDir(kdehome + "/share/Dir[Bracket");
    filter("$KDEHOME/share/Dir[Bracket", kdehome + "/share/Dir[Bracket", KURIFilterData::LOCAL_DIR);

    filter("$HOME/$KDEDIR/kdebase/kcontrol/ebrowsing", 0, KURIFilterData::ERROR);
    filter("$1/$2/$3", "http://www.google.com/search?q=$1/$2/$3&ie=UTF-8&oe=UTF-8",
           KURIFilterData::NET_PROTOCOL); // can be used as bogus or valid test. Currently triggers default search, i.e. google
    filter("$$$$", "http://www.google.com/search?q=$$$$&ie=UTF-8&oe=UTF-8", KURIFilterData::NET_PROTOCOL); // worst case scenarios.

    // Replaced the match testing with a 0 since
    // the shortURI filter will return the string
    // itself if the requested environment variable
    // is not already set.
    filter("$QTDIR", 0, KURIFilterData::LOCAL_DIR, "kshorturifilter");   // use specific filter.
    filter("$HOME", home, KURIFilterData::LOCAL_DIR, "kshorturifilter"); // use specific filter.


    QCString sc;
    filter(sc.sprintf("gg%cfoo bar", delimiter), "http://www.google.com/search?q=foo+bar&ie=UTF-8&oe=UTF-8", KURIFilterData::NET_PROTOCOL);
    filter(sc.sprintf("bug%c55798", delimiter), "http://bugs.kde.org/show_bug.cgi?id=55798", KURIFilterData::NET_PROTOCOL);

    filter(sc.sprintf("gg%cC++", delimiter), "http://www.google.com/search?q=C%2B%2B&ie=UTF-8&oe=UTF-8", KURIFilterData::NET_PROTOCOL);
    filter(sc.sprintf("ya%cfoo bar was here", delimiter), 0, -1); // this triggers default search, i.e. google
    filter(sc.sprintf("gg%cwww.kde.org", delimiter), "http://www.google.com/search?q=www.kde.org&ie=UTF-8&oe=UTF-8", KURIFilterData::NET_PROTOCOL);
    filter(sc.sprintf("av%c+rock +sample", delimiter), "http://www.altavista.com/cgi-bin/query?pg=q&kl=XX&stype=stext&q=%2Brock+%2Bsample",
           KURIFilterData::NET_PROTOCOL);
    filter(sc.sprintf("gg%cé", delimiter) /*eaccent in utf8*/, "http://www.google.com/search?q=%C3%A9&ie=UTF-8&oe=UTF-8",
           KURIFilterData::NET_PROTOCOL);
    filter(sc.sprintf("gg%cпрйвет", delimiter) /* greetings in russian utf-8*/,
           "http://www.google.com/search?q=%D0%BF%D1%80%D0%B9%D0%B2%D0%B5%D1%82&ie=UTF-8&oe=UTF-8", KURIFilterData::NET_PROTOCOL);

    // Absolute Path tests for kshorturifilter
    filter("./", kdehome + "/share", KURIFilterData::LOCAL_DIR, "kshorturifilter", kdehome + "/share/"); // cleanDirPath removes the trailing slash
    filter("../", kdehome, KURIFilterData::LOCAL_DIR, "kshorturifilter", kdehome + "/share");
    filter("config", kdehome + "/share/config", KURIFilterData::LOCAL_DIR, "kshorturifilter", kdehome + "/share");

    // Clean up
    KIO::NetAccess::del(kdehome, 0);

    kdDebug() << "All tests done. Go home..." << endl;
    return 0;
}
Esempio n. 7
0
void DocbookDocVisitor::visit(DocVerbatim *s)
{
  if (m_hide) return;
  SrcLangExt langExt = getLanguageFromFileName(m_langExt);
  switch(s->type())
  {
    case DocVerbatim::Code: // fall though
      m_t << "<literallayout><computeroutput>";
      Doxygen::parserManager->getParser(m_langExt)
        ->parseCode(m_ci,s->context(),s->text(),langExt,
            s->isExample(),s->exampleFile());
      m_t << "</computeroutput></literallayout>";
      break;
    case DocVerbatim::Verbatim:
      m_t << "<literallayout>";
      filter(s->text());
      m_t << "</literallayout>";
      break;
    case DocVerbatim::HtmlOnly:    
      break;
    case DocVerbatim::RtfOnly:     
      break;
    case DocVerbatim::ManOnly:     
      break;
    case DocVerbatim::LatexOnly:   
      break;
    case DocVerbatim::XmlOnly:     
      break;
    case DocVerbatim::DocbookOnly: 
      break;
      m_t << s->text();
      break;
    case DocVerbatim::Dot:
      {
        static int dotindex = 1;
        QCString baseName(4096);
        QCString name;
        QCString stext = s->text();
        m_t << "<para>" << endl;
        name.sprintf("%s%d", "dot_inline_dotgraph_", dotindex);
        baseName.sprintf("%s%d",
            (Config_getString(DOCBOOK_OUTPUT)+"/inline_dotgraph_").data(),
            dotindex++
            );
        QFile file(baseName+".dot");
        if (!file.open(IO_WriteOnly))
        {
          err("Could not open file %s.msc for writing\n",baseName.data());
        }
        file.writeBlock( stext, stext.length() );
        file.close();
        writeDotFile(baseName, s);
        m_t << "</para>" << endl;
      }
      break;
    case DocVerbatim::Msc:
      {
        static int mscindex = 1;
        QCString baseName(4096);
        QCString name;
        QCString stext = s->text();
        m_t << "<para>" << endl;
        name.sprintf("%s%d", "msc_inline_mscgraph_", mscindex);
        baseName.sprintf("%s%d",
            (Config_getString(DOCBOOK_OUTPUT)+"/inline_mscgraph_").data(),
            mscindex++
            );
        QFile file(baseName+".msc");
        if (!file.open(IO_WriteOnly))
        {
          err("Could not open file %s.msc for writing\n",baseName.data());
        }
        QCString text = "msc {";
        text+=stext;
        text+="}";
        file.writeBlock( text, text.length() );
        file.close();
        writeMscFile(baseName,s);
        m_t << "</para>" << endl;
      }
      break;
    case DocVerbatim::PlantUML:
      {
        static QCString docbookOutput = Config_getString(DOCBOOK_OUTPUT);
        QCString baseName = writePlantUMLSource(docbookOutput,s->exampleFile(),s->text());
        QCString shortName = baseName;
        int i;
        if ((i=shortName.findRev('/'))!=-1)
        {
          shortName=shortName.right(shortName.length()-i-1);
        }
        m_t << "<para>" << endl;
        writePlantUMLFile(baseName,s);
        m_t << "</para>" << endl;
      }
      break;
  }
}
Esempio n. 8
0
extern "C" KDE_EXPORT int kdemain(int argc, char **argv)
{
    {
        QCString multiHead = getenv("KDE_MULTIHEAD");
        if(multiHead.lower() == "true")
        {
            Display *dpy = XOpenDisplay(NULL);
            if(!dpy)
            {
                fprintf(stderr, "%s: FATAL ERROR: couldn't open display %s\n", argv[0], XDisplayName(NULL));
                exit(1);
            }

            int number_of_screens = ScreenCount(dpy);
            kicker_screen_number = DefaultScreen(dpy);
            int pos;
            QCString display_name = XDisplayString(dpy);
            XCloseDisplay(dpy);
            dpy = 0;

            if((pos = display_name.findRev('.')) != -1)
                display_name.remove(pos, 10);

            QCString env;
            if(number_of_screens != 1)
            {
                for(int i = 0; i < number_of_screens; i++)
                {
                    if(i != kicker_screen_number && fork() == 0)
                    {
                        kicker_screen_number = i;
                        // break here because we are the child process, we don't
                        // want to fork() anymore
                        break;
                    }
                }

                env.sprintf("DISPLAY=%s.%d", display_name.data(), kicker_screen_number);

                if(putenv(strdup(env.data())))
                {
                    fprintf(stderr, "%s: WARNING: unable to set DISPLAY environment variable\n", argv[0]);
                    perror("putenv()");
                }
            }
        }
    }

    KGlobal::locale()->setMainCatalogue("kicker");

    QCString appname;
    if(kicker_screen_number == 0)
        appname = "kicker";
    else
        appname.sprintf("kicker-screen-%d", kicker_screen_number);

    KAboutData aboutData(appname.data(), I18N_NOOP("KDE Panel"), version, description, KAboutData::License_BSD,
                         I18N_NOOP("(c) 1999-2004, The KDE Team"));

    aboutData.addAuthor("Aaron J. Seigo", I18N_NOOP("Current maintainer"), "*****@*****.**");
    aboutData.addAuthor("Matthias Elter", 0, "*****@*****.**");
    aboutData.addAuthor("Matthias Ettrich", 0, "*****@*****.**");
    aboutData.addAuthor("Wilco Greven", 0, "*****@*****.**");
    aboutData.addAuthor("Rik Hemsley", 0, "*****@*****.**");
    aboutData.addAuthor("Daniel M. Duley", 0, "*****@*****.**");
    aboutData.addAuthor("Preston Brown", 0, "*****@*****.**");
    aboutData.addAuthor("John Firebaugh", 0, "*****@*****.**");
    aboutData.addAuthor("Waldo Bastian", I18N_NOOP("Kiosk mode"), "*****@*****.**");

    aboutData.addCredit("Jessica Hall", /* I18N_NOOP("KConfigXT") */ 0, "*****@*****.**");
    aboutData.addCredit("Stefan Nikolaus", /* I18N_NOOP("Bug fixes") */ 0, "*****@*****.**");
    aboutData.addCredit("Benoît Minisini", /* I18N_NOOP("Bug fixes") */ 0, "*****@*****.**");
    KCmdLineArgs::init(argc, argv, &aboutData);

    if(!Kicker::start())
    {
        kdError() << "kicker is already running!" << endl;
        return 0;
    }

    if(signal(SIGTERM, sighandler) == SIG_IGN)
        signal(SIGTERM, SIG_IGN);
    if(signal(SIGINT, sighandler) == SIG_IGN)
        signal(SIGINT, SIG_IGN);
    if(signal(SIGHUP, sighandler) == SIG_IGN)
        signal(SIGHUP, SIG_IGN);

    // send it even before KApplication ctor, because ksmserver will launch another app as soon
    // as QApplication registers with it
    DCOPClient *cl = new DCOPClient;
    cl->attach();
    DCOPRef r("ksmserver", "ksmserver");
    r.setDCOPClient(cl);
    r.send("suspendStartup", QCString("kicker"));
    delete cl;
    Kicker *kicker = new Kicker;
    int rv = kicker->exec();
    delete kicker;
    return rv;
}
Esempio n. 9
0
void KNNntpClient::doFetchNewHeaders()
{
    KNGroup *target = static_cast<KNGroup *>(job->data());
    char *s;
    int first = 0, last = 0, oldlast = 0, toFetch = 0, rep = 0;
    QCString cmd;

    target->setLastFetchCount(0);

    sendSignal(TSdownloadNew);
    errorPrefix = i18n("No new articles could be retrieved for\n%1/%2.\nThe following error occurred:\n")
                  .arg(account.server()).arg(target->groupname());

    cmd = "GROUP ";
    cmd += target->groupname().utf8();
    if(!sendCommandWCheck(cmd, 211))         // 211 n f l s group selected
    {
        return;
    }

    currentGroup = target->groupname();

    progressValue = 90;

    s = strchr(getCurrentLine(), ' ');
    if(s)
    {
        s++;
        s = strchr(s, ' ');
    }
    if(s)
    {
        s++;
        first = atoi(s);
        target->setFirstNr(first);
        s = strchr(s, ' ');
    }
    if(s)
    {
        last = atoi(s);
    }
    else
    {
        QString tmp = i18n("No new articles could be retrieved.\nThe server sent a malformatted response:\n");
        tmp += getCurrentLine();
        job->setErrorString(tmp);
        closeConnection();
        return;
    }

    if(target->lastNr() == 0)   //first fetch
    {
        if(first > 0)
            oldlast = first - 1;
        else
            oldlast = first;
    }
    else
        oldlast = target->lastNr();

    toFetch = last - oldlast;
    //qDebug("knode: last %d  oldlast %d  toFetch %d\n",last,oldlast,toFetch);

    if(toFetch <= 0)
    {
        //qDebug("knode: No new Articles in group\n");
        target->setLastNr(last);     // don't get stuck when the article numbers wrap
        return;
    }

    if(toFetch > target->maxFetch())
    {
        toFetch = target->maxFetch();
        //qDebug("knode: Fetching only %d articles\n",toFetch);
    }

    progressValue = 100;
    predictedLines = toFetch;

    // get list of additional headers provided by the XOVER command
    // see RFC 2980 section 2.1.7
    QStrList headerformat;
    cmd = "LIST OVERVIEW.FMT";
    if(sendCommand(cmd, rep) && rep == 215)
    {
        QStrList tmp;
        if(getMsg(tmp))
        {
            for(QCString s = tmp.first(); s; s = tmp.next())
            {
                s = s.stripWhiteSpace();
                // remove the mandatory xover header
                if(s == "Subject:" || s == "From:" || s == "Date:" || s == "Message-ID:"
                        || s == "References:" || s == "Bytes:" || s == "Lines:")
                    continue;
                else
                    headerformat.append(s);
            }
        }
    }

    //qDebug("knode: KNNntpClient::doFetchNewHeaders() : xover %d-%d", last-toFetch+1, last);
    cmd.sprintf("xover %d-%d", last - toFetch + 1, last);
    if(!sendCommand(cmd, rep))
        return;

    // no articles in selected range...
    if(rep == 420)          // 420 No article(s) selected
    {
        target->setLastNr(last);
        return;
    }
    else if(rep != 224)     // 224 success
    {
        handleErrors();
        return;
    }

    QStrList headers;
    if(!getMsg(headers))
    {
        return;
    }

    progressValue = 1000;
    sendSignal(TSprogressUpdate);

    sendSignal(TSsortNew);

    mutex.lock();
    target->insortNewHeaders(&headers, &headerformat, this);
    target->setLastNr(last);
    mutex.unlock();
}
Esempio n. 10
0
int
Base::run( const char *cmd, const char *passphrase, bool onlyReadFromPGP )
{
  /* the pipe ppass is used for to pass the password to
   * pgp. passing the password together with the normal input through
   * stdin doesn't seem to work as expected (at least for pgp5.0)
   */
  char str[1025] = "\0";
  int pin[2], pout[2], perr[2], ppass[2];
  int len, len2;
  FILE *pass;
  pid_t child_pid;
  int childExitStatus;
  struct pollfd pollin, pollout, pollerr;
  int pollstatus;

  if(passphrase)
  {
    pipe(ppass);

    pass = fdopen(ppass[1], "w");
    fwrite(passphrase, sizeof(char), strlen(passphrase), pass);
    fwrite("\n", sizeof(char), 1, pass);
    fclose(pass);
    close(ppass[1]);

    // tell pgp which fd to use for the passphrase
    QCString tmp;
    tmp.sprintf("%d",ppass[0]);
    ::setenv("PGPPASSFD",tmp.data(),1);

    //Uncomment these lines for testing only! Doing so will decrease security!
    //kdDebug(5100) << "pgp PGPPASSFD = " << tmp << endl;
    //kdDebug(5100) << "pgp pass = "******"PGPPASSFD");

  //Uncomment these lines for testing only! Doing so will decrease security!
  kdDebug(5100) << "pgp cmd = " << cmd << endl;
  //kdDebug(5100) << "pgp input = " << QString(input)
  //          << "input length = " << input.length() << endl;

  error = "";
  output = "";

  pipe(pin);
  pipe(pout);
  pipe(perr);

  QApplication::flushX();
  if(!(child_pid = fork()))
  {
    /*We're the child.*/
    close(pin[1]);
    dup2(pin[0], 0);
    close(pin[0]);

    close(pout[0]);
    dup2(pout[1], 1);
    close(pout[1]);

    close(perr[0]);
    dup2(perr[1], 2);
    close(perr[1]);

    execl("/bin/sh", "sh", "-c", cmd,  (void *)0);
    _exit(127);
  }

  /*Only get here if we're the parent.*/
  close(pin[0]);
  close(pout[1]);
  close(perr[1]);

  // poll for "There is data to read."
  pollout.fd = pout[0];
  pollout.events = POLLIN;
  pollout.revents = 0; // init with 0, just in case
  pollerr.fd = perr[0];
  pollerr.events = POLLIN;
  pollerr.revents = 0; // init with 0, just in case

  // poll for "Writing now will not block."
  pollin.fd = pin[1];
  pollin.events = POLLOUT;
  pollin.revents = 0; // init with 0, just in case

  if (!onlyReadFromPGP) {
    if (!input.isEmpty()) {
      // write to pin[1] one line after the other to prevent dead lock
      for (unsigned int i=0; i<input.length(); i+=len2) {
        len2 = 0;

        // check if writing now to pin[1] will not block (5 ms timeout)
        //kdDebug(5100) << "Polling pin[1]..." << endl;
        pollstatus = poll(&pollin, 1, 5);
        if (pollstatus == 1) {
          //kdDebug(5100) << "Status for polling pin[1]: " << pollin.revents << endl;
          if (pollin.revents & POLLERR) {
            kdDebug(5100) << "PGP seems to have hung up" << endl;
            break;
          }
          else if (pollin.revents & POLLOUT) {
            // search end of next line
            if ((len2 = input.find('\n', i)) == -1)
              len2 = input.length()-i;
            else
              len2 = len2-i+1;

            //kdDebug(5100) << "Trying to write " << len2 << " bytes to pin[1] ..." << endl;
            len2 = write(pin[1], input.mid(i,len2).data(), len2);
            //kdDebug(5100) << "Wrote " << len2 << " bytes to pin[1] ..." << endl;
          }
        }
        else if (!pollstatus) {
          //kdDebug(5100) << "Timeout while polling pin[1]: "
          //              << pollin.revents << endl;
        }
        else if (pollstatus == -1) {
          kdDebug(5100) << "Error while polling pin[1]: "
                        << pollin.revents << endl;
        }

        if (pout[0] >= 0) {
          do {
            // check if there is data to read from pout[0]
            //kdDebug(5100) << "Polling pout[0]..." << endl;
            pollstatus = poll(&pollout, 1, 0);
            if (pollstatus == 1) {
              //kdDebug(5100) << "Status for polling pout[0]: " << pollout.revents << endl;
              if (pollout.revents & POLLIN) {
                //kdDebug(5100) << "Trying to read " << 1024 << " bytes from pout[0]" << endl;
                if ((len = read(pout[0],str,1024))>0) {
                  //kdDebug(5100) << "Read " << len << " bytes from pout[0]" << endl;
                  str[len] ='\0';
                  output += str;
                }
                else
                  break;
              }
            }
            else if (pollstatus == -1) {
              kdDebug(5100) << "Error while polling pout[0]: "
                            << pollout.revents << endl;
            }
          } while ((pollstatus == 1) && (pollout.revents & POLLIN));
        }

        if (perr[0] >= 0) {
          do {
            // check if there is data to read from perr[0]
            //kdDebug(5100) << "Polling perr[0]..." << endl;
            pollstatus = poll(&pollerr, 1, 0);
            if (pollstatus == 1) {
              //kdDebug(5100) << "Status for polling perr[0]: " << pollerr.revents << endl;
              if (pollerr.revents & POLLIN) {
                //kdDebug(5100) << "Trying to read " << 1024 << " bytes from perr[0]" << endl;
                if ((len = read(perr[0],str,1024))>0) {
                  //kdDebug(5100) << "Read " << len << " bytes from perr[0]" << endl;
                  str[len] ='\0';
                  error += str;
                }
                else
                  break;
              }
            }
            else if (pollstatus == -1) {
              kdDebug(5100) << "Error while polling perr[0]: "
                            << pollerr.revents << endl;
            }
          } while ((pollstatus == 1) && (pollerr.revents & POLLIN));
        }

        // abort writing to PGP if PGP hung up
        if ((pollstatus == 1) &&
            ((pollout.revents & POLLHUP) || (pollerr.revents & POLLHUP))) {
          kdDebug(5100) << "PGP hung up" << endl;
          break;
        }
      }
    }
    else // if input.isEmpty()
      write(pin[1], "\n", 1);
    //kdDebug(5100) << "All input was written to pin[1]" << endl;
  }
  close(pin[1]);

  pid_t waitpidRetVal;

  do {
    //kdDebug(5100) << "Checking if PGP is still running..." << endl;
    childExitStatus = 0;
    waitpidRetVal = waitpid(child_pid, &childExitStatus, WNOHANG);
    //kdDebug(5100) << "waitpid returned " << waitpidRetVal << endl;
    if (pout[0] >= 0) {
      do {
        // check if there is data to read from pout[0]
        //kdDebug(5100) << "Polling pout[0]..." << endl;
        pollstatus = poll(&pollout, 1, 0);
        if (pollstatus == 1) {
          //kdDebug(5100) << "Status for polling pout[0]: " << pollout.revents << endl;
          if (pollout.revents & POLLIN) {
            //kdDebug(5100) << "Trying to read " << 1024 << " bytes from pout[0]" << endl;
            if ((len = read(pout[0],str,1024))>0) {
              //kdDebug(5100) << "Read " << len << " bytes from pout[0]" << endl;
              str[len] ='\0';
              output += str;
            } else {
              /*
               * Apparently, on NetBSD when the child dies, the pipe begins
               * receiving empty data packets *before* waitpid() has signaled
               * that the child has died.  Also, notice that this happens
               * without any error bit being set in pollfd.revents (is this a
               * NetBSD bug??? ).  Notice that these anomalous packets exist
               * according to poll(), but have length 0 according to read().
               * Thus, kde can remain stuck inside this loop.
               *
               * A solution to this problem is to get out of the inner loop
               * when read() returns <=0.  In this way, kde has another chance
               * to call waitpid() to check if the child has died -- and this
               * time the call should succeed.
               *
               * Setting POLLHUP in pollfd.revents is not necessary, but I just
               * like the idea of signaling that something strange has
               * happened.
               */
              pollout.revents |= POLLHUP;
              break;
            }
          }
        }
        else if (pollstatus == -1) {
          kdDebug(5100) << "Error while polling pout[0]: "
                        << pollout.revents << endl;
        }
      } while ((pollstatus == 1) && (pollout.revents & POLLIN));
    }

    if (perr[0] >= 0) {
      do {
        // check if there is data to read from perr[0]
        //kdDebug(5100) << "Polling perr[0]..." << endl;
        pollstatus = poll(&pollerr, 1, 0);
        if (pollstatus == 1) {
          //kdDebug(5100) << "Status for polling perr[0]: " << pollerr.revents << endl;
          if (pollerr.revents & POLLIN) {
            //kdDebug(5100) << "Trying to read " << 1024 << " bytes from perr[0]" << endl;
            if ((len = read(perr[0],str,1024))>0) {
              //kdDebug(5100) << "Read " << len << " bytes from perr[0]" << endl;
              str[len] ='\0';
              error += str;
            } else {
              /*
               * Apparently, on NetBSD when the child dies, the pipe begins
               * receiving empty data packets *before* waitpid() has signaled
               * that the child has died.  Also, notice that this happens
               * without any error bit being set in pollfd.revents (is this a
               * NetBSD bug??? ).  Notice that these anomalous packets exist
               * according to poll(), but have length 0 according to read().
               * Thus, kde can remain stuck inside this loop.
               *
               * A solution to this problem is to get out of the inner loop
               * when read() returns <=0.  In this way, kde has another chance
               * to call waitpid() to check if the child has died -- and this
               * time the call should succeed.
               *
               * Setting POLLHUP in pollfd.revents is not necessary, but I just
               * like the idea of signaling that something strange has
               * happened.
               */
              pollerr.revents |= POLLHUP;
              break;
            }
          }
        }
        else if (pollstatus == -1) {
          kdDebug(5100) << "Error while polling perr[0]: "
                        << pollerr.revents << endl;
        }
      } while ((pollstatus == 1) && (pollerr.revents & POLLIN));
    }
  } while (waitpidRetVal == 0);

  close(pout[0]);
  close(perr[0]);

  unsetenv("PGPPASSFD");
  if(passphrase)
    close(ppass[0]);

  // Did the child exit normally?
  if (WIFEXITED(childExitStatus) != 0) {
    // Get the return code of the child
    childExitStatus = WEXITSTATUS(childExitStatus);
    kdDebug(5100) << "PGP exited with exit status " << childExitStatus 
                  << endl;
  }
  else {
    childExitStatus = -1;
    kdDebug(5100) << "PGP exited abnormally!" << endl;
  }

  //Uncomment these lines for testing only! Doing so will decrease security!
  //kdDebug(5100) << "pgp output = " << QString(output) << endl;
  //kdDebug(5100) << "pgp error = " << error << endl;

  /* Make the information visible, so that a user can
   * get to know what's going on during the pgp calls.
   */
  kdDebug(5100) << error << endl;

  return childExitStatus;
}
Esempio n. 11
0
int main(int argc, char **argv)
{

    KAboutData aboutData("test_cryptoconfig", "CryptoConfig Test", "0.1");
    KCmdLineArgs::init(argc, argv, &aboutData);
    KApplication app(false, false);

    Kleo::CryptoConfig *config = new QGpgMECryptoConfig();

    // Dynamic querying of the options
    cout << "Components:" << endl;
    QStringList components = config->componentList();

    for(QStringList::Iterator compit = components.begin(); compit != components.end(); ++compit)
    {
        cout << "Component " << (*compit).local8Bit() << ":" << endl;
        const Kleo::CryptoConfigComponent *comp = config->component(*compit);
        assert(comp);
        QStringList groups = comp->groupList();
        for(QStringList::Iterator groupit = groups.begin(); groupit != groups.end(); ++groupit)
        {
            const Kleo::CryptoConfigGroup *group = comp->group(*groupit);
            assert(group);
            cout << " Group " << (*groupit).local8Bit() << ": descr=\"" << group->description().local8Bit() << "\""
                 << " level=" << group->level() << endl;
            QStringList entries = group->entryList();
            for(QStringList::Iterator entryit = entries.begin(); entryit != entries.end(); ++entryit)
            {
                const Kleo::CryptoConfigEntry *entry = group->entry(*entryit);
                assert(entry);
                cout << "  Entry " << (*entryit).local8Bit() << ":"
                     << " descr=\"" << entry->description().local8Bit() << "\""
                     << " " << (entry->isSet() ? "is set" : "is not set");
                if(!entry->isList())
                    switch(entry->argType())
                    {
                        case Kleo::CryptoConfigEntry::ArgType_None:
                            break;
                        case Kleo::CryptoConfigEntry::ArgType_Int:
                            cout << " int value=" << entry->intValue();
                            break;
                        case Kleo::CryptoConfigEntry::ArgType_UInt:
                            cout << " uint value=" << entry->uintValue();
                            break;
                        case Kleo::CryptoConfigEntry::ArgType_LDAPURL:
                        case Kleo::CryptoConfigEntry::ArgType_URL:
                            cout << " URL value=" << entry->urlValue().prettyURL().local8Bit();
                        // fallthrough
                        case Kleo::CryptoConfigEntry::ArgType_Path:
                        // fallthrough
                        case Kleo::CryptoConfigEntry::ArgType_DirPath:
                        // fallthrough
                        case Kleo::CryptoConfigEntry::ArgType_String:

                            cout << " string value=" << entry->stringValue().local8Bit();
                            break;
                    }
                else // lists
                {
                    switch(entry->argType())
                    {
                        case Kleo::CryptoConfigEntry::ArgType_None:
                        {
                            cout << " set " << entry->numberOfTimesSet() << " times";
                            break;
                        }
                        case Kleo::CryptoConfigEntry::ArgType_Int:
                        {
                            assert(entry->isOptional());   // empty lists must be allowed (see issue121)
                            QValueList<int> lst = entry->intValueList();
                            QString str;
                            for(QValueList<int>::Iterator it = lst.begin(); it != lst.end(); ++it)
                            {
                                str += QString::number(*it);
                            }
                            cout << " int values=" << str.local8Bit();
                            break;
                        }
                        case Kleo::CryptoConfigEntry::ArgType_UInt:
                        {
                            assert(entry->isOptional());   // empty lists must be allowed (see issue121)
                            QValueList<uint> lst = entry->uintValueList();
                            QString str;
                            for(QValueList<uint>::Iterator it = lst.begin(); it != lst.end(); ++it)
                            {
                                str += QString::number(*it);
                            }
                            cout << " uint values=" << str.local8Bit();
                            break;
                        }
                        case Kleo::CryptoConfigEntry::ArgType_LDAPURL:
                        case Kleo::CryptoConfigEntry::ArgType_URL:
                        {
                            assert(entry->isOptional());   // empty lists must be allowed (see issue121)
                            KURL::List urls = entry->urlValueList();
                            cout << " url values=" << urls.toStringList().join(" ").local8Bit() << "\n    ";
                        }
                        // fallthrough
                        case Kleo::CryptoConfigEntry::ArgType_Path:
                        // fallthrough
                        case Kleo::CryptoConfigEntry::ArgType_DirPath:
                        // fallthrough
                        case Kleo::CryptoConfigEntry::ArgType_String:
                        {
                            assert(entry->isOptional());   // empty lists must be allowed (see issue121)
                            QStringList lst = entry->stringValueList();
                            cout << " string values=" << lst.join(" ").local8Bit();
                            break;
                        }
                    }
                }
                cout << endl;
            }
            // ...
        }
    }

    {
        // Static querying of a single boolean option
        static const char *s_groupName = "Monitor";
        static const char *s_entryName = "quiet";
        Kleo::CryptoConfigEntry *entry = config->entry("dirmngr", s_groupName, s_entryName);
        if(entry)
        {
            assert(entry->argType() == Kleo::CryptoConfigEntry::ArgType_None);
            bool val = entry->boolValue();
            cout << "quiet option initially: " << (val ? "is set" : "is not set") << endl;

            entry->setBoolValue(!val);
            assert(entry->isDirty());
            config->sync(true);

            // Clear cached values!
            config->clear();

            // Check new value
            Kleo::CryptoConfigEntry *entry = config->entry("dirmngr", s_groupName, s_entryName);
            assert(entry);
            assert(entry->argType() == Kleo::CryptoConfigEntry::ArgType_None);
            cout << "quiet option now: " << (val ? "is set" : "is not set") << endl;
            assert(entry->boolValue() == !val);

            // Set to default
            entry->resetToDefault();
            assert(entry->boolValue() == false);   // that's the default
            assert(entry->isDirty());
            assert(!entry->isSet());
            config->sync(true);
            config->clear();

            // Check value
            entry = config->entry("dirmngr", s_groupName, s_entryName);
            assert(!entry->isDirty());
            assert(!entry->isSet());
            cout << "quiet option reset to default: " << (entry->boolValue() ? "is set" : "is not set") << endl;
            assert(entry->boolValue() == false);

            // Reset old value
            entry->setBoolValue(val);
            assert(entry->isDirty());
            config->sync(true);

            cout << "quiet option reset to initial: " << (val ? "is set" : "is not set") << endl;
        }
        else
            cout << "Entry 'dirmngr/" << s_groupName << "/" << s_entryName << "' not found" << endl;
    }

    {
        // Static querying and setting of a single int option
        static const char *s_groupName = "LDAP";
        static const char *s_entryName = "ldaptimeout";
        Kleo::CryptoConfigEntry *entry = config->entry("dirmngr", s_groupName, s_entryName);
        if(entry)
        {
            assert(entry->argType() == Kleo::CryptoConfigEntry::ArgType_UInt);
            uint val = entry->uintValue();
            cout << "LDAP timeout initially: " << val << " seconds." << endl;

            // Test setting the option directly, then querying again
            //system( "echo 'ldaptimeout:0:101' | gpgconf --change-options dirmngr" );
            // Now let's do it with the C++ API instead
            entry->setUIntValue(101);
            assert(entry->isDirty());
            config->sync(true);

            // Clear cached values!
            config->clear();

            // Check new value
            Kleo::CryptoConfigEntry *entry = config->entry("dirmngr", s_groupName, s_entryName);
            assert(entry);
            assert(entry->argType() == Kleo::CryptoConfigEntry::ArgType_UInt);
            cout << "LDAP timeout now: " << entry->uintValue() << " seconds." << endl;
            assert(entry->uintValue() == 101);

            // Set to default
            entry->resetToDefault();
            assert(entry->uintValue() == 100);
            assert(entry->isDirty());
            assert(!entry->isSet());
            config->sync(true);
            config->clear();

            // Check value
            entry = config->entry("dirmngr", s_groupName, s_entryName);
            assert(!entry->isDirty());
            assert(!entry->isSet());
            cout << "LDAP timeout reset to default, " << entry->uintValue() << " seconds." << endl;
            assert(entry->uintValue() == 100);

            // Reset old value
            entry->setUIntValue(val);
            assert(entry->isDirty());
            config->sync(true);

            cout << "LDAP timeout reset to initial " << val << " seconds." << endl;
        }
        else
            cout << "Entry 'dirmngr/" << s_groupName << "/" << s_entryName << "' not found" << endl;
    }

    {
        // Static querying and setting of a single string option
        static const char *s_groupName = "Debug";
        static const char *s_entryName = "log-file";
        Kleo::CryptoConfigEntry *entry = config->entry("dirmngr", s_groupName, s_entryName);
        if(entry)
        {
            assert(entry->argType() == Kleo::CryptoConfigEntry::ArgType_Path);
            QString val = entry->stringValue();
            cout << "Log-file initially: " << val.local8Bit() << endl;

            // Test setting the option, sync'ing, then querying again
            entry->setStringValue(QString::fromUtf8("/tmp/test:%e5ä"));
            assert(entry->isDirty());
            config->sync(true);

            // Let's see how it prints it
            system("gpgconf --list-options dirmngr | grep log-file");

            // Clear cached values!
            config->clear();

            // Check new value
            Kleo::CryptoConfigEntry *entry = config->entry("dirmngr", s_groupName, s_entryName);
            assert(entry);
            assert(entry->argType() == Kleo::CryptoConfigEntry::ArgType_Path);
            cout << "Log-file now: " << entry->stringValue().local8Bit() << endl;
            assert(entry->stringValue() == QString::fromUtf8("/tmp/test:%e5ä"));     // (or even with %e5 decoded)

            // Reset old value
#if 0
            QString arg(val);
            if(!arg.isEmpty())
                arg.prepend('"');
            QCString sys;
            sys.sprintf("echo 'log-file:%s' | gpgconf --change-options dirmngr", arg.local8Bit().data());
            system(sys.data());
#endif
            entry->setStringValue(val);
            assert(entry->isDirty());
            config->sync(true);

            cout << "Log-file reset to initial " << val.local8Bit() << endl;
        }
        else
            cout << "Entry 'dirmngr/" << s_groupName << "/" << s_entryName << "' not found" << endl;
    }

    {
        // Static querying and setting of the LDAP URL list option
        static const char *s_groupName = "LDAP";
        static const char *s_entryName = "LDAP Server";
        Kleo::CryptoConfigEntry *entry = config->entry("dirmngr", s_groupName, s_entryName);
        if(entry)
        {
            assert(entry->argType() == Kleo::CryptoConfigEntry::ArgType_LDAPURL);
            assert(entry->isList());
            KURL::List val = entry->urlValueList();
            cout << "URL list initially: " << val.toStringList().join(", ").local8Bit() << endl;

            // Test setting the option, sync'ing, then querying again
            KURL::List lst;
            // We use non-empty paths to workaround a bug in KURL (kdelibs-3.2)
            lst << KURL("ldap://a:389/?b");
            // Test with query containing a litteral ':' (KURL supports this)
            // and a ' ' (KURL will escape it, see issue119)
            lst << KURL("ldap://foo:389/?a:b c");
            lst << KURL("ldap://server:389/?a%3db,c=DE");   // the query contains a litteral ','
            //cout << " trying to set: " << lst.toStringList().join(", ").local8Bit() << endl;
            assert(lst[0].query() == "?b");
            assert(lst[1].query() == "?a:b%20c");   // see, the space got escaped
            entry->setURLValueList(lst);
            assert(entry->isDirty());
            config->sync(true);

            // Let's see how it prints it
            system("gpgconf --list-options dirmngr | grep 'LDAP Server'");

            // Clear cached values!
            config->clear();

            // Check new value
            Kleo::CryptoConfigEntry *entry = config->entry("dirmngr", s_groupName, s_entryName);
            assert(entry);
            assert(entry->argType() == Kleo::CryptoConfigEntry::ArgType_LDAPURL);
            assert(entry->isList());
            // Get raw a:b:c:d:e form
            QStringList asStringList = entry->stringValueList();
            assert(asStringList.count() == 3);
            cout << "asStringList[0]=" << asStringList[0].local8Bit() << endl;
            cout << "asStringList[1]=" << asStringList[1].local8Bit() << endl;
            cout << "asStringList[2]=" << asStringList[2].local8Bit() << endl;
            assert(asStringList[0] == "a:389:::b");
            assert(asStringList[1] == "foo:389:::a%3ab c");   // the space must be decoded (issue119)
            assert(asStringList[2] == "server:389:::a=b,c=DE");   // all decoded
            // Get KURL form
            KURL::List newlst = entry->urlValueList();
            cout << "URL list now: " << newlst.toStringList().join(", ").local8Bit() << endl;
            assert(newlst.count() == 3);
            //cout << "newlst[0]=" << newlst[0].url().local8Bit() << endl;
            //cout << "lst[0]=" << lst[0].url().local8Bit() << endl;
            assert(newlst[0] == lst[0]);
            assert(newlst[1] == lst[1]);
            assert(newlst[2].url() == "ldap://server:389/?a=b,c=DE");   // != lst[2] due to the encoded =

            // Reset old value
            entry->setURLValueList(val);
            assert(entry->isDirty());
            config->sync(true);

            cout << "URL list reset to initial: " << val.toStringList().join(", ").local8Bit() << endl;
        }
        else
            cout << "Entry 'dirmngr/" << s_groupName << "/" << s_entryName << "' not found" << endl;
    }

    cout << "Done." << endl;
}
Esempio n. 12
0
void UmlAttribute::importIt(FileIn & in, Token & token, UmlItem * where)
{
  if (!token.valueOf("association").isNull())
    UmlRelation::importAsAttribute(in, token, where);
  else {
    where = where->container(anAttribute, token, in);
    
    if (where != 0) {
      QCString s = token.valueOf("name");
      
      if (s.isEmpty()) {
	static unsigned n = 0;
	
	s.sprintf("anonymous_attribute_%u", ++n);
      }
      else
        s = legalName(s);
      
      UmlAttribute * att = create((UmlClass *) where, s);
      
      if (att == 0)
	in.error("cannot create attribute '" + s +
		 "' in '" + where->name() + "'");
      
      att->addItem(token.xmiId(), in);
      
      if (token.what() == "ownedliteral")
	att->set_Visibility(PublicVisibility);
      else
	att->setVisibility(token.valueOf("visibility"));
      
      if (token.valueOf("isreadonly") == "true")
	 att->set_isReadOnly(TRUE);
      
      if (token.valueOf("isderived") == "true")
	 att->set_isDerived(TRUE, (token.valueOf("isderivedunion") == "true"));
      
      if (token.valueOf("isordered") == "true")
	 att->set_isOrdered(TRUE);
      
      if (token.valueOf("isunique") == "true")
	 att->set_isUnique(TRUE);
      
      if (!(s = token.valueOf("type")).isEmpty()) {
	UmlTypeSpec ts;
	
	if (att->setType(s, ts))
	  att->set_Type(ts);
      }
      
      if (!(s = token.valueOf("defaultvalue")).isEmpty())
	att->set_DefaultValue(s);
      
      if (token.valueOf("isstatic") == "true")
	att->set_isClassMember(TRUE);
	  
      if (! token.closed()) {
	QCString k = token.what();
	const char * kstr = k;
	
	while (in.read(), !token.close(kstr)) {
	  s = token.what();
	  
	  if (s == "type") {
	    UmlTypeSpec ts;
	    
	    if (att->setType(token, ts))
	      att->set_Type(ts);
	    if (! token.closed())
	      in.finish(s);
	  }
	  else if (s == "defaultvalue") {
	    att->set_DefaultValue(token.valueOf("value"));
	    if (! token.closed())
	      in.finish(s);
	  }
	  else if (s == "lowervalue")
	    att->importMultiplicity(in, token, FALSE);
	  else if (s == "uppervalue")
	    att->importMultiplicity(in, token, TRUE);
	  else if (s == "upperbound") {
	    if (! token.closed())
	      in.finish(s);
	  }
	  else if ((s == "specification") && (k == "ownedliteral")) {
	    if (! token.closed())
	      in.finish(s);
	  }
	  else if (s == "ownedrule")
	    att->set_Constraint(UmlItem::readConstraint(in, token));
	  else
	    att->UmlItem::import(in, token);
	}
      }
    }
  }
}
Esempio n. 13
0
extern "C" KDE_EXPORT int kdemain(int argc, char *argv[])
{
    bool restored = false;
    for(int arg = 1; arg < argc; arg++)
    {
        if(!qstrcmp(argv[arg], "-session"))
        {
            restored = true;
            break;
        }
    }

    if(!restored)
    {
        // we only do the multihead fork if we are not restored by the session
        // manager, since the session manager will register multiple kwins,
        // one for each screen...
        QCString multiHead = getenv("KDE_MULTIHEAD");
        if(multiHead.lower() == "true")
        {

            Display *dpy = XOpenDisplay(NULL);
            if(!dpy)
            {
                fprintf(stderr, "%s: FATAL ERROR while trying to open display %s\n", argv[0], XDisplayName(NULL));
                exit(1);
            }

            int number_of_screens = ScreenCount(dpy);
            KWinInternal::screen_number = DefaultScreen(dpy);
            int pos; // temporarily needed to reconstruct DISPLAY var if multi-head
            QCString display_name = XDisplayString(dpy);
            XCloseDisplay(dpy);
            dpy = 0;

            if((pos = display_name.findRev('.')) != -1)
                display_name.remove(pos, 10); // 10 is enough to be sure we removed ".s"

            QCString envir;
            if(number_of_screens != 1)
            {
                for(int i = 0; i < number_of_screens; i++)
                {
                    // if execution doesn't pass by here, then kwin
                    // acts exactly as previously
                    if(i != KWinInternal::screen_number && fork() == 0)
                    {
                        KWinInternal::screen_number = i;
                        // break here because we are the child process, we don't
                        // want to fork() anymore
                        break;
                    }
                }
                // in the next statement, display_name shouldn't contain a screen
                //   number. If it had it, it was removed at the "pos" check
                envir.sprintf("DISPLAY=%s.%d", display_name.data(), KWinInternal::screen_number);

                if(putenv(strdup(envir.data())))
                {
                    fprintf(stderr, "%s: WARNING: unable to set DISPLAY environment variable\n", argv[0]);
                    perror("putenv()");
                }
            }
        }
    }

    KGlobal::locale()->setMainCatalogue("kwin");

    KAboutData aboutData("kwin", I18N_NOOP("KWin"), version, description, KAboutData::License_GPL, I18N_NOOP("(c) 1999-2005, The KDE Developers"));
    aboutData.addAuthor("Matthias Ettrich", 0, "*****@*****.**");
    aboutData.addAuthor("Cristian Tibirna", 0, "*****@*****.**");
    aboutData.addAuthor("Daniel M. Duley", 0, "*****@*****.**");
    aboutData.addAuthor("Luboš Luňák", I18N_NOOP("Maintainer"), "*****@*****.**");

    KCmdLineArgs::init(argc, argv, &aboutData);
    KCmdLineArgs::addCmdLineOptions(args);

    if(signal(SIGTERM, KWinInternal::sighandler) == SIG_IGN)
        signal(SIGTERM, SIG_IGN);
    if(signal(SIGINT, KWinInternal::sighandler) == SIG_IGN)
        signal(SIGINT, SIG_IGN);
    if(signal(SIGHUP, KWinInternal::sighandler) == SIG_IGN)
        signal(SIGHUP, SIG_IGN);

    KApplication::disableAutoDcopRegistration();
    KWinInternal::Application a;
    KWinInternal::SessionManaged weAreIndeed;
    KWinInternal::SessionSaveDoneHelper helper;

    fcntl(ConnectionNumber(qt_xdisplay()), F_SETFD, 1);

    QCString appname;
    if(KWinInternal::screen_number == 0)
        appname = "kwin";
    else
        appname.sprintf("kwin-screen-%d", KWinInternal::screen_number);

    DCOPClient *client = a.dcopClient();
    client->registerAs(appname.data(), false);
    client->setDefaultObject("KWinInterface");

    return a.exec();
}
Esempio n. 14
0
int KDEsuClient::setScheduler(int sched)
{
    QCString cmd;
    cmd.sprintf("SCHD %d\n", sched);
    return command(cmd);
}
Esempio n. 15
0
void KNNntpClient::doCheckNewGroups()
{
    KNGroupListData *target = static_cast<KNGroupListData *>(job->data());

    sendSignal(TSdownloadNewGroups);
    errorPrefix = i18n("New groups could not be retrieved.\nThe following error occurred:\n");

    progressValue = 100;
    predictedLines = 30;     // rule of thumb ;-)

    QCString cmd;
    cmd.sprintf("NEWGROUPS %.2d%.2d%.2d 000000", target->fetchSince.year() % 100, target->fetchSince.month(), target->fetchSince.day());
    if(!sendCommandWCheck(cmd, 231))      // 231 list of new newsgroups follows
        return;

    char *s, *line;
    QString name;
    KNGroup::Status status;
    QSortedList<KNGroupInfo> tmpList;
    tmpList.setAutoDelete(true);

    while(getNextLine())
    {
        line = getCurrentLine();
        if(line[0] == '.')
        {
            if(line[1] == '.')
                line++;        // collapse double period into one
            else if(line[1] == 0)
                break;   // message complete
        }
        s = strchr(line, ' ');
        if(!s)
        {
#ifndef NDEBUG
            qDebug("knode: retrieved broken group-line - ignoring");
#endif
        }
        else
        {
            s[0] = 0;    // cut string
            name = QString::fromUtf8(line);

            while(s[1] != 0) s++;  // the last character determines the moderation status
            switch(s[0])
            {
                case 'n' :
                    status = KNGroup::readOnly;
                    break;
                case 'y' :
                    status = KNGroup::postingAllowed;
                    break;
                case 'm' :
                    status = KNGroup::moderated;
                    break;
                default  :
                    status = KNGroup::unknown;
            }

            tmpList.append(new KNGroupInfo(name, QString::null, true, false, status));
        }
        doneLines++;
    }

    if(!job->success() || job->canceled())
        return;     // stopped...

    if(target->getDescriptions)
    {
        errorPrefix = i18n("The group descriptions could not be retrieved.\nThe following error occurred:\n");
        progressValue = 100;
        doneLines = 0;
        predictedLines = tmpList.count() * 3;

        sendSignal(TSdownloadDesc);
        sendSignal(TSprogressUpdate);

        cmd = "LIST NEWSGROUPS ";
        QStrList desList;
        char *s;
        int rep;

        for(KNGroupInfo *group = tmpList.first(); group; group = tmpList.next())
        {
            if(!sendCommand(cmd + group->name.utf8(), rep))
                return;
            if(rep != 215)         // 215 informations follows
                break;
            desList.clear();
            if(!getMsg(desList))
                return;

            if(desList.count() > 0)         // group has a description
            {
                s = desList.first();
                while(*s != - '\0' && *s != '\t' && *s != ' ') s++;
                if(*s == '\0')
                {
#ifndef NDEBUG
                    qDebug("knode: retrieved broken group-description - ignoring");
#endif
                }
                else
                {
                    while(*s == ' ' || *s == '\t') s++;     // go on to the description
                    if(target->codecForDescriptions)           // some countries use local 8 bit characters in the tag line
                        group->description = target->codecForDescriptions->toUnicode(s);
                    else
                        group->description = QString::fromLocal8Bit(s);
                }
            }
        }
    }

    sendSignal(TSloadGrouplist);

    if(!target->readIn())
    {
        job->setErrorString(i18n("Unable to read the group list file"));
        return;
    }
    target->merge(&tmpList);
    sendSignal(TSwriteGrouplist);
    if(!target->writeOut())
    {
        job->setErrorString(i18n("Unable to write the group list file"));
        return;
    }
}
Esempio n. 16
0
void DocbookDocVisitor::visit(DocVerbatim *s)
{
  if (m_hide) return;
  SrcLangExt langExt = getLanguageFromFileName(m_langExt);
  switch(s->type())
  {
    case DocVerbatim::Code: // fall though
      m_t << "<literallayout><computeroutput>";
      Doxygen::parserManager->getParser(m_langExt)
        ->parseCode(m_ci,s->context(),s->text(),langExt,
            s->isExample(),s->exampleFile());
      m_t << "</computeroutput></literallayout>";
      break;
    case DocVerbatim::Verbatim:
      m_t << "<literallayout>";
      filter(s->text());
      m_t << "</literallayout>";
      break;
    case DocVerbatim::HtmlOnly:    
      break;
    case DocVerbatim::RtfOnly:     
      break;
    case DocVerbatim::ManOnly:     
      break;
    case DocVerbatim::LatexOnly:   
      break;
    case DocVerbatim::XmlOnly:     
      break;
    case DocVerbatim::DocbookOnly: 
      break;
      m_t << s->text();
      break;
    case DocVerbatim::Dot:
      {
        static int dotindex = 1;
        QCString baseName(4096);
        QCString name;
        QCString stext = s->text();
        m_t << "<para>" << endl;
        name.sprintf("%s%d", "dot_inline_dotgraph_", dotindex);
        baseName.sprintf("%s%d",
            (Config_getString("DOCBOOK_OUTPUT")+"/inline_dotgraph_").data(),
            dotindex++
            );
        QFile file(baseName+".dot");
        if (!file.open(IO_WriteOnly))
        {
          err("Could not open file %s.msc for writing\n",baseName.data());
        }
        file.writeBlock( stext, stext.length() );
        file.close();
        m_t << "    <figure>" << endl;
        m_t << "        <title>" << name << "</title>" << endl;
        m_t << "        <mediaobject>" << endl;
        m_t << "            <imageobject>" << endl;
        writeDotFile(baseName);
        m_t << "            </imageobject>" << endl;
        m_t << "       </mediaobject>" << endl;
        m_t << "    </figure>" << endl;
        m_t << "</para>" << endl;
      }
      break;
    case DocVerbatim::Msc:
      static int mscindex = 1;
      QCString baseName(4096);
      QCString name;
      QCString stext = s->text();
      m_t << "<para>" << endl;
      name.sprintf("%s%d", "msc_inline_mscgraph_", mscindex);
      baseName.sprintf("%s%d",
          (Config_getString("DOCBOOK_OUTPUT")+"/inline_mscgraph_").data(),
          mscindex++
          );
      QFile file(baseName+".msc");
      if (!file.open(IO_WriteOnly))
      {
        err("Could not open file %s.msc for writing\n",baseName.data());
      }
      QCString text = "msc {";
      text+=stext;
      text+="}";
      file.writeBlock( text, text.length() );
      file.close();
      m_t << "    <figure>" << endl;
      m_t << "        <title>" << name << "</title>" << endl;
      m_t << "        <mediaobject>" << endl;
      m_t << "            <imageobject>" << endl;
      writeMscFile(baseName);
      m_t << "            </imageobject>" << endl;
      m_t << "       </mediaobject>" << endl;
      m_t << "    </figure>" << endl;
      m_t << "</para>" << endl;
      break;
  }
}
Esempio n. 17
0
void UmlState::importIt(FileIn & in, Token & token, UmlItem * where)
{
  where = where->container(aState, token, in);
    
  if (where != 0) {
    bool machine = ((token.xmiType() == "uml:StateMachine") ||
		    (token.valueOf("issubmachinestate") == "true") ||
		    (token.what() == "ownedstatemachine")); // andromda emf
    QCString s = token.valueOf("name");
    
    if (s.isEmpty()) {
      static unsigned n = 0;
      
      s.sprintf((machine) ? "anonymous_state_machine_%u" 
			  : "anonymous_state_%u",
		++n);
    }
    
    UmlState * st = create(where, s);
    
    if (st == 0)
      in.error((machine) ? "cannot create state machine '"
			 : "cannot create state '"
	       + s + "' in '" + where->name() + "'");
    
    st->addItem(token.xmiId(), in);

    if (token.valueOf("isactive") == "true")
      st->set_isActive(TRUE);
    
    QCString ref = token.valueOf("submachine");
    QCString spec = token.valueOf("specification");
    
    if (! token.closed()) {
      QCString k = token.what();
      const char * kstr = k;
      
      while (in.read(), !token.close(kstr)) {
	s = token.what();
	
	if ((s == "entry") || (s == "doactivity") || (s == "exit"))
	  st->importActivity(in, token);
	else if (s == "specification") {
	  spec = token.xmiIdref();
	  if (! token.closed())
	    in.finish(s);
	}
	else
	  st->UmlItem::import(in, token);
      }
    }
    
    if (machine)
      st->set_Stereotype("machine");
    
    if (! ref.isEmpty()) {
      QMap<QCString, UmlItem *>::Iterator it = All.find(ref);
      
      if (it == All.end())
	UnresolvedWithContext::add(st, ref, 4);
      else if ((*it)->kind() == aState)
	st->set_Reference((UmlState *) *it);
    }
    
    if (! spec.isEmpty()) {
      QMap<QCString, UmlItem *>::Iterator it = All.find(spec);
      
      if (it == All.end())
	UnresolvedWithContext::add(st, spec, 3);
      else if ((*it)->kind() == anOperation)
	st->set_Specification((UmlOperation *) *it);
    }

    st->unload(TRUE, FALSE);
  }
}