Example #1
0
void UmlItem::write_multiplicity(FileOut & out, QCString s, UmlItem * who)
{
  if (!s.isEmpty()) {
    QCString min;
    QCString max;
    int index = s.find("..");
    
    if (index != -1) {
      min = s.left(index).stripWhiteSpace();
      max = s.mid(index+2).stripWhiteSpace();
    }
    else
      min = max = s.stripWhiteSpace();
    
    out.indent();
    out << "<lowerValue xmi:type=\"uml:LiteralString\"";
    out.id_prefix(who, "MULTIPLICITY_L_");
    out << " value=\"" << min << "\"/>\n";
    
    out.indent();
    out << "<upperValue xmi:type=\"uml:LiteralString\"";
    out.id_prefix(who, "MULTIPLICITY_U_");
    out << " value=\"" << max << "\"/>\n";
  }
}
Example #2
0
void Definition::_setBriefDescription(const char *b,const char *briefFile,int briefLine)
{
  static QCString outputLanguage = "English";
  static bool needsDot = outputLanguage!="Japanese" && 
                         outputLanguage!="Chinese" &&
                         outputLanguage!="Korean";
  QCString brief = b;
  brief = brief.stripWhiteSpace();
  if (brief.isEmpty()) return;
  int bl = brief.length();
  if (bl>0 && needsDot) // add punctuation if needed
  {
    int c = brief.at(bl-1);
    switch(c)
    {
      case '.': case '!': case '?': case '>': case ':': case ')': break;
      default: 
        if (uni_isupper(brief.at(0)) && !lastCharIsMultibyte(brief)) brief+='.'; 
        break;
    }
  }

  if (!_docsAlreadyAdded(brief,m_impl->briefSignatures))
  {
    if (m_impl->brief && !m_impl->brief->doc.isEmpty())
    {
       //printf("adding to details\n");
       _setDocumentation(brief,briefFile,briefLine,FALSE,TRUE);
    }
    else
    {
      //fprintf(stderr,"Definition::setBriefDescription(%s,%s,%d)\n",b,briefFile,briefLine);
      if (m_impl->brief==0)
      {
        m_impl->brief = new BriefInfo;
      }
      m_impl->brief->doc=brief;
      if (briefLine!=-1)
      {
        m_impl->brief->file = briefFile;
        m_impl->brief->line = briefLine;
      }
      else
      {
        m_impl->brief->file = briefFile;
        m_impl->brief->line = 1;
      }
    }
  }
  else
  {
    //printf("do nothing!\n");
  }
}
Example #3
0
bool ClassData::tool_cmd(ToolCom * com, const char * args,
			 BrowserNode * bn,
			 const QString & comment) {
  if (((unsigned char) args[-1]) >= firstSetCmd) {
    if (!bn->is_writable() && !root_permission())
      com->write_ack(FALSE);
    else {
      switch ((unsigned char) args[-1]) {
      case setIsAbstractCmd:
	if ((*args == 0) && 
	    strcmp(browser_node->get_stereotype(), "enum") &&
	    ((BrowserClass *) browser_node)->have_abstract_operation()) {
	  com->write_ack(FALSE);
	  return TRUE;
	}
	else
	  is_abstract = (*args != 0);
	break;
      case setActiveCmd:
	is_active = (*args != 0);
	break;
      case setVisibilityCmd:
	{
	  UmlVisibility v;
	  
	  if (! com->get_visibility(v, args)) {
	    com->write_ack(FALSE);
	    return TRUE;
	  }
	  else
	    uml_visibility = v;
	}
	break;
      case setBaseTypeCmd:
	if (stereotype != "typedef") {
	  com->write_ack(FALSE);
	  return TRUE;
	}
	else {
	  AType t;
	  
	  com->get_type(t, args);
	  set_base_type(t);	  
	}
	break;
      case setConstraintCmd:
	constraint = args;
	break;
      case setIsCppExternalCmd:
	cpp_external = (*args != 0);
	break;
      case setCppVisibilityCmd:
	{
	  UmlVisibility v;
	  
	  if (! com->get_extended_visibility(v, args)) {
	    com->write_ack(FALSE);
	    return TRUE;
	  }
	  else
	    cpp_visibility = v;
	}
	break;
      case setCppDeclCmd:
	cpp_decl = args;
	break;
      case setIsJavaExternalCmd:
	java_external = (*args != 0);
	break;
      case setJavaDeclCmd:
	java_decl = args;
	break;
      case setJavaAnnotationCmd:
	{
	  QCString s = args;
	  
	  s = s.stripWhiteSpace();
	  if (! s.isEmpty())
	    s += '\n';
	  java_annotation = s;
	}
	break;
      case setIsJavaPublicCmd:
	{
	  UmlVisibility v = (*args != 0) ? UmlPublic : UmlPackageVisibility;
	  
	  if ((cpp_visibility == UmlDefaultVisibility) &&
	      (uml_visibility != UmlPublic) &&
	      (uml_visibility != UmlPackageVisibility))
	    cpp_visibility = uml_visibility;
	  uml_visibility = v;
	}
	break;
      case setIsJavaFinalCmd:
	java_final = (*args != 0);
	break;
      case setIsPhpExternalCmd:
	php_external = (*args != 0);
	break;
      case setPhpDeclCmd:
	php_decl = args;
	break;
      case setIsPhpFinalCmd:
	php_final = (*args != 0);
	break;
      case setIsPythonExternalCmd:
	python_external = (*args != 0);
	break;
      case setPythonDeclCmd:
	python_decl = args;
	break;
      case setIsPython2_2Cmd:
	python_2_2 = (*args != 0);
	break;
      case setIdlDeclCmd:
	idl_decl = args;
	break;
      case setSwitchTypeCmd:
	if (GenerationSettings::idl_class_stereotype(stereotype) != "union") {
	  com->write_ack(FALSE);
	  return TRUE;
	}
	else {
	  AType t;
	  
	  com->get_type(t, args);
	  set_switch_type(t);
	}
	break;
      case setIsIdlExternalCmd:
	idl_external = (*args != 0);
	break;
      case setIsIdlLocalCmd:
	idl_local = (*args != 0);
	break;
      case setIsIdlCustomCmd:
	idl_custom = (*args != 0);
	break;
      case setIsClassMemberCmd:
      case setIsVolatileCmd:
	com->write_ack(FALSE);
	return TRUE;
      case removeFormalCmd:
	{
	  unsigned rank = com->get_unsigned(args);
	  
	  if (rank < nformals) {
	    if (nformals == 1) {
	      delete [] formals;
	      formals = 0;
	    }
	    else
	      while (++rank != nformals)
		formals[rank - 1] = formals[rank];
	    nformals -= 1;
	    DontUpdateActuals = FALSE;
	  }
	  else {
	    com->write_ack(FALSE);
	    return TRUE;
	  }
	}
	break;
      case addFormalCmd:
	{
	  unsigned rank = com->get_unsigned(args);
	  
	  if (rank <= nformals) {
	    FormalParamData * new_formals = new FormalParamData[++nformals];
	    unsigned index;
	    
	    for (index = 0; index != rank; index += 1)
	      new_formals[index] = formals[index];
	    
	    new_formals[index].read(com, args);
	    
	    while (++index != nformals)
	      new_formals[index] = formals[index - 1];
	    
	    delete [] formals;
	    formals = new_formals;
	    DontUpdateActuals = FALSE;
	  }
	  else {
	    FormalParamData::skip(com, args);
	    com->write_ack(FALSE);
	    return TRUE;
	  }
	}
	break;
      case replaceFormalCmd:
	{
	  unsigned rank = com->get_unsigned(args);
	  
	  if (rank < nformals) {
	    formals[rank].read(com, args);
	    DontUpdateActuals = FALSE;
	  }
	  else {
	    FormalParamData::skip(com, args);
	    com->write_ack(FALSE);
	    return TRUE;
	  }
	}
	break;
      case replaceActualCmd:
	{
	  unsigned rank = com->get_unsigned(args);
	  
	  if (rank < actuals.count()) {
	    AType t;
	    
	    com->get_type(t, args);
	    actuals.at(rank)->set_value(t);
	  }
	  else {
	    com->write_ack(FALSE);
	    return TRUE;
	  }
	}
	break;
      default:
	return BasicData::tool_cmd(com, args, bn, comment);
      }
  
      // ok case
      bn->modified();	// call modified
      bn->package_modified();
      com->write_ack(TRUE);
    }
  }
  else {
    // get only !
    switch ((unsigned char) args[-1]) {
    case formalsCmd:
      {
	com->write_unsigned((unsigned) nformals);
	for (int index = 0; index != nformals; index += 1)
	  formals[index].send_uml_def(com);
      }
      break;
    case actualsCmd:
      {
	com->write_unsigned((unsigned) actuals.count());
	for (ActualParamData * a = actuals.first(); a != 0; a = actuals.next())
	  a->send_uml_def(com);
      }
      break;
    default:
      return BasicData::tool_cmd(com, args, bn, comment);
    }
  }
  
  return TRUE;
}
Example #4
0
//-----------------------------------------------------------------------------
// Used by KPIM::splitAddress(...) and KPIM::getFirstEmailAddress(...).
KPIM::EmailParseResult splitAddressInternal( const QCString& address,
                                             QCString & displayName,
                                             QCString & addrSpec,
                                             QCString & comment,
                                             bool allowMultipleAddresses )
{
//  kdDebug() << "KMMessage::splitAddress( " << address << " )" << endl;

  displayName = "";
  addrSpec = "";
  comment = "";

  if ( address.isEmpty() )
    return KPIM::AddressEmpty;

  // The following is a primitive parser for a mailbox-list (cf. RFC 2822).
  // The purpose is to extract a displayable string from the mailboxes.
  // Comments in the addr-spec are not handled. No error checking is done.

  enum { TopLevel, InComment, InAngleAddress } context = TopLevel;
  bool inQuotedString = false;
  int commentLevel = 0;
  bool stop = false;

  for ( char* p = address.data(); *p && !stop; ++p ) {
    switch ( context ) {
    case TopLevel : {
      switch ( *p ) {
      case '"' : inQuotedString = !inQuotedString;
                 displayName += *p;
                 break;
      case '(' : if ( !inQuotedString ) {
                   context = InComment;
                   commentLevel = 1;
                 }
                 else
                   displayName += *p;
                 break;
      case '<' : if ( !inQuotedString ) {
                   context = InAngleAddress;
                 }
                 else
                   displayName += *p;
                 break;
      case '\\' : // quoted character
                 displayName += *p;
                 ++p; // skip the '\'
                 if ( *p )
                   displayName += *p;
                 else
                   return KPIM::UnexpectedEnd;
                 break;
          case ',' :
          case ';' : if ( !inQuotedString ) {
                   if ( allowMultipleAddresses )
                     stop = true;
                   else
                     return KPIM::UnexpectedComma;
                 }
                 else
                   displayName += *p;
                 break;
      default :  displayName += *p;
      }
      break;
    }
    case InComment : {
      switch ( *p ) {
      case '(' : ++commentLevel;
                 comment += *p;
                 break;
      case ')' : --commentLevel;
                 if ( commentLevel == 0 ) {
                   context = TopLevel;
                   comment += ' '; // separate the text of several comments
                 }
                 else
                   comment += *p;
                 break;
      case '\\' : // quoted character
                 comment += *p;
                 ++p; // skip the '\'
                 if ( *p )
                   comment += *p;
                 else
                   return KPIM::UnexpectedEnd;
                 break;
      default :  comment += *p;
      }
      break;
    }
    case InAngleAddress : {
      switch ( *p ) {
      case '"' : inQuotedString = !inQuotedString;
                 addrSpec += *p;
                 break;
      case '>' : if ( !inQuotedString ) {
                   context = TopLevel;
                 }
                 else
                   addrSpec += *p;
                 break;
      case '\\' : // quoted character
                 addrSpec += *p;
                 ++p; // skip the '\'
                 if ( *p )
                   addrSpec += *p;
                 else
                   return KPIM::UnexpectedEnd;
                 break;
      default :  addrSpec += *p;
      }
      break;
    }
    } // switch ( context )
  }
  // check for errors
  if ( inQuotedString )
    return KPIM::UnbalancedQuote;
  if ( context == InComment )
    return KPIM::UnbalancedParens;
  if ( context == InAngleAddress )
    return KPIM::UnclosedAngleAddr;

  displayName = displayName.stripWhiteSpace();
  comment = comment.stripWhiteSpace();
  addrSpec = addrSpec.stripWhiteSpace();

  if ( addrSpec.isEmpty() ) {
    if ( displayName.isEmpty() )
      return KPIM::NoAddressSpec;
    else {
      addrSpec = displayName;
      displayName.truncate( 0 );
    }
  }
/*
  kdDebug() << "display-name : \"" << displayName << "\"" << endl;
  kdDebug() << "comment      : \"" << comment << "\"" << endl;
  kdDebug() << "addr-spec    : \"" << addrSpec << "\"" << endl;
*/
  return KPIM::AddressOk;
}
Example #5
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();
}
Example #6
0
static CWResult        mocify(CWPluginContext context, const QCString &source)
{
    CWDisplayLines(context, line_count++);

    source.stripWhiteSpace();

    CWResult err;
        bool            dotmoc=false;
        QCString stem = source, ext;
        int dotpos = stem.findRev('.');
    if(dotpos != -1) {
        ext = stem.right(stem.length() - (dotpos+1));
        stem = stem.left(dotpos);
        if(ext == "cpp")
            dotmoc = true;
    } else {
        //whoa!
    }
    QCString dest;
    if(dotmoc)
        dest = stem + ".moc";
    else
        dest = "moc_" + stem + ".cpp";

    //moc it
    CWFileSpec destSpec;
        moc_status mocd = do_moc(context, source, dest, &destSpec, dotmoc);

#if 0
    QCString derr = "Weird";
    switch(mocd) {
    case moc_success: derr = "Success"; break;
    case moc_parse_error: derr = "Parser Error"; break;
    case moc_no_qobject:derr = "No QOBJECT"; break;
    case moc_not_time: derr = "Not Time"; break;
    case moc_no_source: derr = "No Source"; break;
    case moc_general_error: derr = "General Error"; break;
    }
        char        dmsg[200];
        sprintf(dmsg, "\"%s\" %s", source.data(), derr.data());
        CWReportMessage(context, NULL, dmsg, NULL, messagetypeError, 0);
#endif

    //handle project
    if(mocd == moc_no_qobject) {
        char        msg[400];
                sprintf(msg, "\"%s\" No relevant classes found. No output generated.", source.data());
                CWReportMessage(context, NULL, msg, NULL, messagetypeWarning, 0);
        } else if ((mocd == moc_success || mocd == moc_not_time) && !dotmoc)
        {
                long                        whichFile;
                CWNewProjectEntryInfo ei;
                memset(&ei, '\0', sizeof(ei));
                ei.groupPath = "QtGenerated";
                    err = CWAddProjectEntry(context, &destSpec, true, &ei, &whichFile);
                    if (!CWSUCCESS(err))
                    {
                            char        msg[200];
                            sprintf(msg, "\"%s\" not added", dest.data());
                            CWReportMessage(context, NULL, msg, NULL, messagetypeWarning, 0);
                    }
                    if(mocd == moc_success)
                        CWSetModDate(context, &destSpec, NULL, true);
        }
        return cwNoErr;
}
Example #7
0
int
BaseG::encsign(Block &block, const KeyIDList &recipients,
               const char *passphrase)
{
    QCString cmd;
    int exitStatus = 0;

    if(!recipients.isEmpty() && passphrase != 0)
        cmd = "--batch --armor --sign --encrypt --textmode";
    else if(!recipients.isEmpty())
        cmd = "--batch --armor --encrypt --textmode";
    else if(passphrase != 0)
        cmd = "--batch --escape-from --clearsign";
    else
    {
        kdDebug(5100) << "kpgpbase: Neither recipients nor passphrase specified." << endl;
        return OK;
    }

    if(passphrase != 0)
        cmd += addUserId();

    if(!recipients.isEmpty())
    {
        cmd += " --set-filename stdin";

        QCString pgpUser = Module::getKpgp()->user();
        if(Module::getKpgp()->encryptToSelf() && !pgpUser.isEmpty())
        {
            cmd += " -r 0x";
            cmd += pgpUser;
        }

        for(KeyIDList::ConstIterator it = recipients.begin();
                it != recipients.end(); ++it)
        {
            cmd += " -r 0x";
            cmd += (*it);
        }
    }

    clear();
    input = block.text();
    exitStatus = runGpg(cmd.data(), passphrase);
    if(!output.isEmpty())
        block.setProcessedText(output);
    block.setError(error);

    if(exitStatus != 0)
    {
        // this error message is later hopefully overwritten
        errMsg = i18n("Unknown error.");
        status = ERROR;
    }

#if 0
    // #### FIXME: As we check the keys ourselves the following problems
    //             shouldn't occur. Therefore I don't handle them for now.
    //             IK 01/2002
    if(!recipients.isEmpty())
    {
        int index = 0;
        bool bad = FALSE;
        unsigned int num = 0;
        QCString badkeys = "";
        // Examples:
        // gpg: 0x12345678: skipped: public key not found
        // gpg: 0x12345678: skipped: public key is disabled
        // gpg: 0x12345678: skipped: unusable public key
        // (expired or revoked key)
        // gpg: 23456789: no info to calculate a trust probability
        // (untrusted key, 23456789 is the key Id of the encryption sub key)
        while((index = error.find("skipped: ", index)) != -1)
        {
            bad = TRUE;
            index = error.find('\'', index);
            int index2 = error.find('\'', index + 1);
            badkeys += error.mid(index, index2 - index + 1) + ", ";
            num++;
        }
        if(bad)
        {
            badkeys.stripWhiteSpace();
            if(num == recipients.count())
                errMsg = i18n("Could not find public keys matching the userid(s)\n"
                              "%1;\n"
                              "the message is not encrypted.")
                         .arg(badkeys.data());
            else
                errMsg = i18n("Could not find public keys matching the userid(s)\n"
                              "%1;\n"
                              "these persons will not be able to read the message.")
                         .arg(badkeys.data());
            status |= MISSINGKEY;
            status |= ERROR;
        }
    }
#endif
    if(passphrase != 0)
    {
        // Example 1 (bad passphrase, clearsign only):
        // gpg: skipped `0x12345678': bad passphrase
        // gpg: [stdin]: clearsign failed: bad passphrase
        // Example 2 (bad passphrase, sign & encrypt):
        // gpg: skipped `0x12345678': bad passphrase
        // gpg: [stdin]: sign+encrypt failed: bad passphrase
        // Example 3 (unusable secret key, clearsign only):
        // gpg: skipped `0x12345678': unusable secret key
        // gpg: [stdin]: clearsign failed: unusable secret key
        // Example 4 (unusable secret key, sign & encrypt):
        // gpg: skipped `0xAC0EB35D': unusable secret key
        // gpg: [stdin]: sign+encrypt failed: unusable secret key
        if(error.find("bad passphrase") != -1)
        {
            errMsg = i18n("Signing failed because the passphrase is wrong.");
            status |= BADPHRASE;
            status |= ERR_SIGNING;
            status |= ERROR;
        }
        else if(error.find("unusable secret key") != -1)
        {
            errMsg = i18n("Signing failed because your secret key is unusable.");
            status |= ERR_SIGNING;
            status |= ERROR;
        }
        else if(!(status & ERROR))
        {
            //kdDebug(5100) << "Base: Good Passphrase!" << endl;
            status |= SIGNED;
        }
    }

    //kdDebug(5100) << "status = " << status << endl;
    block.setStatus(status);
    return status;
}
Example #8
0
int
BaseG::decrypt(Block &block, const char *passphrase)
{
    int index, index2;
    int exitStatus = 0;

    clear();
    input = block.text();
    exitStatus = runGpg("--batch --decrypt", passphrase);
    if(!output.isEmpty() && (error.find("gpg: quoted printable") == -1))
        block.setProcessedText(output);
    block.setError(error);

    if(exitStatus == -1)
    {
        errMsg = i18n("Error running gpg");
        status = RUN_ERR;
        block.setStatus(status);
        return status;
    }

    // Example 1 (good passphrase, decryption successful):
    // gpg: encrypted with 2048-bit ELG-E key, ID 12345678, created 2000-11-11
    //       "Foo Bar <*****@*****.**>"
    //
    // Example 2 (bad passphrase):
    // gpg: encrypted with 1024-bit RSA key, ID 12345678, created 1991-01-01
    //       "Foo Bar <*****@*****.**>"
    // gpg: public key decryption failed: bad passphrase
    // gpg: decryption failed: secret key not available
    //
    // Example 3 (no secret key available):
    // gpg: encrypted with RSA key, ID 12345678
    // gpg: decryption failed: secret key not available
    //
    // Example 4 (good passphrase for second key, decryption successful):
    // gpg: encrypted with 2048-bit ELG-E key, ID 12345678, created 2000-01-01
    //       "Foo Bar (work) <*****@*****.**>"
    // gpg: public key decryption failed: bad passphrase
    // gpg: encrypted with 2048-bit ELG-E key, ID 23456789, created 2000-02-02
    //       "Foo Bar (home) <*****@*****.**>"
    if(error.find("gpg: encrypted with") != -1)
    {
        //kdDebug(5100) << "kpgpbase: message is encrypted" << endl;
        status |= ENCRYPTED;
        if(error.find("\ngpg: decryption failed") != -1)
        {
            if((index = error.find("bad passphrase")) != -1)
            {
                if(passphrase != 0)
                {
                    errMsg = i18n("Bad passphrase; could not decrypt.");
                    kdDebug(5100) << "Base: passphrase is bad" << endl;
                    status |= BADPHRASE;
                    status |= ERROR;
                }
                else
                {
                    // Search backwards the user ID of the needed key
                    index2 = error.findRev('"', index) - 1;
                    index = error.findRev("      \"", index2) + 7;
                    // The conversion from UTF8 is necessary because gpg stores and
                    // prints user IDs in UTF8
                    block.setRequiredUserId(QString::fromUtf8(error.mid(index, index2 - index + 1)));
                    kdDebug(5100) << "Base: key needed is \"" << block.requiredUserId() << "\"!" << endl;
                }
            }
            else if(error.find("secret key not available") != -1)
            {
                // no secret key fitting this message
                status |= NO_SEC_KEY;
                status |= ERROR;
                errMsg = i18n("You do not have the secret key needed to decrypt this message.");
                kdDebug(5100) << "Base: no secret key for this message" << endl;
            }
        }
        // check for persons
#if 0
        // ##### FIXME: This information is anyway currently not used
        //       I'll change it to always determine the recipients.
        index = error.find("can only be read by:");
        if(index != -1)
        {
            index = error.find('\n', index);
            int end = error.find("\n\n", index);

            mRecipients.clear();
            while((index2 = error.find('\n', index + 1)) <= end)
            {
                QCString item = error.mid(index + 1, index2 - index - 1);
                item.stripWhiteSpace();
                mRecipients.append(item);
                index = index2;
            }
        }
#endif
    }

    // Example 1 (unknown signature key):
    // gpg: Signature made Wed 02 Jan 2002 11:26:33 AM CET using DSA key ID 2E250C64
    // gpg: Can't check signature: public key not found
    if((index = error.find("Signature made")) != -1)
    {
        //kdDebug(5100) << "Base: message is signed" << endl;
        status |= SIGNED;
        // get signature date and signature key ID
        // Example: Signature made Sun 06 May 2001 03:49:27 PM CEST using DSA key ID 12345678
        index2 = error.find("using", index + 15);
        block.setSignatureDate(error.mid(index + 15, index2 - (index + 15) - 1));
        kdDebug(5100) << "Message was signed on '" << block.signatureDate() << "'\n";
        index2 = error.find("key ID ", index2) + 7;
        block.setSignatureKeyId(error.mid(index2, 8));
        kdDebug(5100) << "Message was signed with key '" << block.signatureKeyId() << "'\n";
        // move index to start of next line
        index = error.find('\n', index2) + 1;

        if((error.find("Key matching expected", index) != -1)
                || (error.find("Can't check signature", index) != -1))
        {
            status |= UNKNOWN_SIG;
            status |= GOODSIG;
            block.setSignatureUserId(QString::null);
        }
        else if(error.find("Good signature", index) != -1)
        {
            status |= GOODSIG;
            // get the primary user ID of the signer
            index = error.find('"', index);
            index2 = error.find('\n', index + 1);
            index2 = error.findRev('"', index2 - 1);
            block.setSignatureUserId(error.mid(index + 1, index2 - index - 1));
        }
        else if(error.find("BAD signature", index) != -1)
        {
            //kdDebug(5100) << "BAD signature" << endl;
            status |= ERROR;
            // get the primary user ID of the signer
            index = error.find('"', index);
            index2 = error.find('\n', index + 1);
            index2 = error.findRev('"', index2 - 1);
            block.setSignatureUserId(error.mid(index + 1, index2 - index - 1));
        }
        else if(error.find("Can't find the right public key", index) != -1)
        {
            // #### fix this hack
            // I think this can't happen anymore because if the pubring is missing
            // the current GnuPG creates a new empty one.
            status |= UNKNOWN_SIG;
            status |= GOODSIG; // this is a hack...
            block.setSignatureUserId(i18n("??? (file ~/.gnupg/pubring.gpg not found)"));
        }
        else
        {
            status |= ERROR;
            block.setSignatureUserId(QString::null);
        }
    }
    //kdDebug(5100) << "status = " << status << endl;
    block.setStatus(status);
    return status;
}
Example #9
0
bool UmlAttribute::manage_enum_item(QCString name, UmlClass * cl
#ifdef ROUNDTRIP
				    , bool roundtrip,
				    QList<UmlItem> & expected_order
#endif
				    )
{   
  QCString comment = Lex::get_comments();
  QCString description = Lex::get_description();
  UmlAttribute * item = 0;	// initialize to avoid warning
#ifdef ROUNDTRIP
  Class * container = 0;	// initialize to avoid warning
  bool created = FALSE;		// initialize to avoid warning
#endif
  
  if (!Package::scanning()) {
#ifdef ROUNDTRIP
    container = cl->get_class();
    
    if (!roundtrip ||
	((item = search_attr(container, name)) == 0)) {
#endif
      if ((item = UmlBaseAttribute::create(cl, name)) == 0) {
	JavaCatWindow::trace(QCString("<font face=helvetica><b>cannot add enum item <i>")
			     + name + "</i> in <i>" + cl->name() 
			     + "</i></b></font><br>");  
	return FALSE;
      }
      
      item->set_Visibility(PublicVisibility);
#ifdef ROUNDTRIP
      if (roundtrip)
	container->set_updated();
    
      created = TRUE;
    }
#endif
  }
  
  Lex::mark();
  
  QCString aux;
  QCString s;
  
  if ((s = Lex::read_word()).isEmpty()) {
    if (! Package::scanning())
      Lex::premature_eof();
    return FALSE;
  }
  else if ((s == ";") || (s == "}")) {
    aux = Lex::region();
    Lex::unread_word(s);
  }
  else if (s == ",") {
    aux = Lex::region();
    Lex::finish_line();
    comment = Lex::get_comments(comment);
    description = Lex::get_description(description);
  }
  else if ((s == "(") || (s == "{")) {
    char c = UmlOperation::skip_expr(1);	// goes after opt init and body
    if (c == 0) {
      if (! Package::scanning())
	Lex::premature_eof();
      return FALSE;
    }
    // c is ',' or ';'
    if (c == ';')
      Lex::unread_word(";");
    aux = Lex::region();
  }
  else {
    if (! Package::scanning())
      Lex::error_near(s);
    return FALSE;
  }
  
  if (!Package::scanning()) {
    // here aux = opt init and body + final character , ; or }
    QCString decl = JavaSettings::enumItemDecl();
    int index;
    
    if ((decl.find("${name}") == -1) ||
	((index = decl.find("${value}")) == -1)) {
      decl = "  ${name}${value},${comment}";
      index = decl.find("${value}");
    }
    
    aux.resize(aux.length()); // remove , ; or }, warning resize count \000
    if (!aux.stripWhiteSpace().isEmpty())
      decl.replace(index, 8, aux);

#ifdef ROUNDTRIP
    if (roundtrip && !created) {
      if (decl.find("${description}") != -1) {
	if (nequal(item->description(), description)) {
	  item->set_Description(description);
	  container->set_updated();
	}
      }
      else if (nequal(item->description(), Lex::simplify_comment(comment))) {
	item->set_Description(comment); // comment was changed
	container->set_updated();
      }
      
      if (neq(item->javaDecl(), decl)) {
	item->set_JavaDecl(decl);
	container->set_updated();
      }
    
      item->set_usefull();
      
      expected_order.append(item);
    }
    else {
#endif
      if (!comment.isEmpty())
	item->set_Description((decl.find("${description}") != -1)
			      ? description : Lex::simplify_comment(comment));
      
      item->set_JavaDecl(decl);
      
#ifdef ROUNDTRIP
      if (roundtrip)
	expected_order.append(item);
    }
#endif
  }
    
  return TRUE;
}
Example #10
0
bool ClassContainer::read_type(UmlTypeSpec & typespec, Class ** cl, 
			       const QValueList<FormalParameterList> & tmplts,
			       QValueList<UmlTypeSpec> * actuals,
			       QCString & str_actuals, QCString s,
			       UmlClass ** first_actual_class, QCString & def,
			       QCString & genericname) {
  str_actuals = 0;
  if (actuals != 0)
    actuals->clear();
  
  if (s.isEmpty() && (s = Lex::read_word()).isEmpty()) {
    Lex::premature_eof();
    return FALSE;
  }
    
  QCString path; // type without <..>
  QCString type; // real type form
  bool internal_template = FALSE;	// true if type is ...<...>...
  int pfixdef_length = 0;		// generic form including first class
  int first_actual_class_length = 0;	// first class's name length
  
  genericname = s;
  
  for (;;) {
    internal_template = (path != type);
    
    path += s;
    type += s;
    
    s = Lex::read_word();
  
    if (s != "<")
      break;
    
    type += s;
    str_actuals = s;
    
    // read <...>
    do {
      Lex::mark();
      
      int level = 0;
      QCString firstword;	// first element in current actual
      int pfixlen = 0;		// type length including firstword
      
      for (;;) {
	s = Lex::read_word(TRUE);
	
	if (s == ",") {
	  if (level == 0)
	    break;
	}
	else if (s == ">") {
	  if (level-- == 0)
	    break;
	}
	else if (s == "]")
	  level -= 1;
	else if ((s == "<") || (s == "["))
	  level += 1;
	else if (s.isEmpty()) {
	  Lex::premature_eof();
	  return FALSE;
	}
	else if (firstword.isEmpty()) {
	  firstword = s;
	  pfixlen = type.length() + Lex::region().length();
	}
      }
      
      QCString e = Lex::region();
      
      type += e;
      str_actuals += e;

      if (actuals != 0) {
	UmlTypeSpec t;
	
	e.resize(e.length()); // remove , or >
	e = e.stripWhiteSpace();
	if (! e.isEmpty())
	  compute_type(e, t, tmplts);
	if (actuals != 0)
	  actuals->append(t);
      }
      else if ((first_actual_class != 0) &&
	       (*first_actual_class == 0) && 
	       !firstword.isEmpty()) {
	UmlTypeSpec t;
	
	compute_type(firstword, t, tmplts);
	if (t.type != 0) {
	  *first_actual_class = t.type;
	  first_actual_class_length = firstword.length();
	  pfixdef_length = pfixlen - first_actual_class_length;
	}
      }
    } while (s == ",");
    
    s = Lex::read_word();
    if (s.isEmpty() || (*s != '.'))
      break;
    str_actuals = 0;
    if (actuals != 0)
      actuals->clear();
  }
  
  if (! s.isEmpty())
    Lex::unread_word(s);
  
  compute_type(path, typespec, tmplts, cl);
  if (typespec.type != 0) {
    if (internal_template)
      // typespec.type stay unchanged
      typespec.explicit_type = type;
  }
  else if ((first_actual_class != 0) && (*first_actual_class != 0)) {
    def = type.left(pfixdef_length) + "${type}" + 
      type.mid(pfixdef_length+first_actual_class_length);
  }
  else
    // path may be not good
    typespec.explicit_type = type;
  
  return TRUE;
}
Example #11
0
bool EvaSetting::saveSetting(const int id, const char * md5Pwd, const bool recorded, const bool hidden , 
			const int type, const Q_UINT32 server, const Q_UINT16 port, const QString username, const QCString base64Param)
{
	QString home = QDir::homeDirPath();
	
	QDir d;
	QString fullPath = home + "/.eva";
	if (!d.exists(fullPath)){
		if(!d.cd(home)){
			emit exceptionEvent(QString("can't enter user's home directory"));
			return false;		
		}
		if(!d.mkdir(QString(".eva"),false)){
			emit exceptionEvent(QString("can't create Eva directory"));
			return false;		
		}		
	}
	QString fullName = fullPath + "/" + filename;
	loadSetting();
	//if id exists, update information, otherwise add a new record
	int userIndex = findUser(id);
	Q_UINT8 flag = 0x00;
	if(recorded) flag|=0x01;
	if(hidden) flag |= 0x02;
	switch(type){
	case 0: 
		flag |= 0x10;  // udp;
		break;
	case 1: 
		flag |= 0x08;  // tcp;
		break;
	case 2: 
		flag |= 0x04;  // http proxy;
		break;
	}	
	
	QString s_username = "******";
	QCString s_param = " ";
	if( !username.isEmpty() && username.stripWhiteSpace() != "") s_username = username;
	if( !base64Param.isEmpty() && base64Param.stripWhiteSpace() != "") s_param = base64Param;
	if( userIndex == -1){
		//new record
		LoginRecord *record = new LoginRecord();
		
		record->id = (uint)id;
		
		char *pwd = (char *)malloc(16 * sizeof(char));
		memcpy(pwd, md5Pwd, 16);
		//FIXME memory leak here!!!!
		record->md5Pwd = (Q_UINT8 *)pwd;
		
		record->flag = flag;
		record->proxy = server;
		record->port = port;
		record->proxyUserName = s_username;
		record->base64param = s_param;
		
		userList.append(record);
		userIndex = userList.count()-1;
	}else{
		// update information
		memcpy(userList.at(userIndex)->md5Pwd, md5Pwd, 16);
		userList.at(userIndex)->flag = flag;
		userList.at(userIndex)->proxy = server;
		userList.at(userIndex)->port = port;
		
		userList.at(userIndex)->proxyUserName = s_username;
		userList.at(userIndex)->base64param = s_param;
	}
	QFile file(fullName);
	if(!file.open(IO_WriteOnly)){
		//QString msg = qApp->translate("QFile",file.errorString());
		emit exceptionEvent(fullName);
		return false;
	}
  
	QDataStream stream(&file);
	// save the lastest user's id
	stream<<(Q_UINT32)(userIndex);
	// saving now
	for(uint i=0; i<userList.count(); i++){
		LoginRecord *r= userList.at(i);
		stream<<r->id;
		stream.writeRawBytes((char *)(r->md5Pwd), 16);
		stream<<r->flag;
		stream<<r->proxy;
		stream<<r->port;
		Q_UINT8 len = strlen(r->proxyUserName.ascii());
		stream<<len;
		//stream<<r->proxyUserName;
		stream.writeRawBytes(r->proxyUserName.ascii(), len);
		len = strlen(r->base64param.data());
		stream<<len;
		stream.writeRawBytes(r->base64param.data(), len);
	}
	file.flush();
	file.close();
	return true;
}