예제 #1
0
nsresult nsMsgMdnGenerator::CreateThirdPart()
{
    DEBUG_MDN("nsMsgMdnGenerator::CreateThirdPart");
    char *tmpBuffer = nsnull;
    nsresult rv = NS_OK;

    tmpBuffer = PR_smprintf("--%s" CRLF, m_mimeSeparator.get());
    PUSH_N_FREE_STRING(tmpBuffer);

    tmpBuffer = PR_smprintf("%s" CRLF, "Content-Type: text/rfc822-headers; name=\042MDNPart3.txt\042");
    PUSH_N_FREE_STRING(tmpBuffer);

    tmpBuffer = PR_smprintf("%s" CRLF, "Content-Transfer-Encoding: 7bit");
    PUSH_N_FREE_STRING(tmpBuffer);

    tmpBuffer = PR_smprintf("%s" CRLF CRLF, "Content-Disposition: inline");
    PUSH_N_FREE_STRING(tmpBuffer);

    rv = OutputAllHeaders();

    if (NS_FAILED(rv))
        return rv;

    rv = WriteString(CRLF);
    if (NS_FAILED(rv))
        return rv;

    tmpBuffer = PR_smprintf("--%s--" CRLF, m_mimeSeparator.get());
    PUSH_N_FREE_STRING(tmpBuffer);

    return rv;
}
예제 #2
0
static char *
nssutil_formatPair(char *name, char *value, char quote)
{
    char openQuote = quote;
    char closeQuote = NSSUTIL_ArgGetPair(quote);
    char *newValue = NULL;
    char *returnValue;
    PRBool need_quote = PR_FALSE;

    if (!value || (*value == 0))
        return nssutil_nullString;

    if (nssutil_argHasBlanks(value) || NSSUTIL_ArgIsQuote(value[0]))
        need_quote = PR_TRUE;

    if ((need_quote && nssutil_argHasChar(value, closeQuote)) || nssutil_argHasChar(value, NSSUTIL_ARG_ESCAPE)) {
        value = newValue = nssutil_formatValue(NULL, value, quote);
        if (newValue == NULL)
            return nssutil_nullString;
    }
    if (need_quote) {
        returnValue = PR_smprintf("%s=%c%s%c", name, openQuote, value, closeQuote);
    } else {
        returnValue = PR_smprintf("%s=%s", name, value);
    }
    if (returnValue == NULL)
        returnValue = nssutil_nullString;

    if (newValue)
        PORT_Free(newValue);

    return returnValue;
}
예제 #3
0
// This function takes a message uri, converts it into a file path & msgKey 
// pair. It then turns that into a mailbox url object. It also registers a url
// listener if appropriate. AND it can take in a mailbox action and set that field
// on the returned url as well.
nsresult nsMailboxService::PrepareMessageUrl(const char * aSrcMsgMailboxURI, nsIUrlListener * aUrlListener,
                                             nsMailboxAction aMailboxAction, nsIMailboxUrl ** aMailboxUrl,
                                             nsIMsgWindow *msgWindow)
{
  nsresult rv = CallCreateInstance(kCMailboxUrl, aMailboxUrl);
  if (NS_SUCCEEDED(rv) && aMailboxUrl && *aMailboxUrl)
  {
    // okay now generate the url string
    char * urlSpec;
    nsCAutoString folderURI;
    nsFileSpec folderPath;
    nsMsgKey msgKey;
    const char *part = PL_strstr(aSrcMsgMailboxURI, "part=");
    const char *header = PL_strstr(aSrcMsgMailboxURI, "header=");
    rv = nsParseLocalMessageURI(aSrcMsgMailboxURI, folderURI, &msgKey);
    NS_ENSURE_SUCCESS(rv,rv);
    rv = nsLocalURI2Path(kMailboxRootURI, folderURI.get(), folderPath);
    
    if (NS_SUCCEEDED(rv))
    {
      // set up the url spec and initialize the url with it.
      nsFilePath filePath(folderPath); // convert to file url representation...
      nsCAutoString buf;
      NS_EscapeURL((const char *)filePath,-1,
                   esc_Directory|esc_Forced|esc_AlwaysCopy,buf);
      if (mPrintingOperation)
        urlSpec = PR_smprintf("mailbox://%s?number=%d&header=print", buf.get(), msgKey);
      else if (part)
        urlSpec = PR_smprintf("mailbox://%s?number=%d&%s", buf.get(), msgKey, part);
      else if (header)
        urlSpec = PR_smprintf("mailbox://%s?number=%d&%s", buf.get(), msgKey, header);
      else
        urlSpec = PR_smprintf("mailbox://%s?number=%d", buf.get(), msgKey);
      
      nsCOMPtr <nsIMsgMailNewsUrl> url = do_QueryInterface(*aMailboxUrl);
      url->SetSpec(nsDependentCString(urlSpec));
      PR_Free(urlSpec);
      
      (*aMailboxUrl)->SetMailboxAction(aMailboxAction);
      
      // set up the url listener
      if (aUrlListener)
        rv = url->RegisterListener(aUrlListener);
      
      url->SetMsgWindow(msgWindow);
      nsCOMPtr<nsIMsgMessageUrl> msgUrl = do_QueryInterface(url);
      if (msgUrl)
      {
        msgUrl->SetOriginalSpec(aSrcMsgMailboxURI);
        msgUrl->SetUri(aSrcMsgMailboxURI);
      }
      
    } // if we got a url
  } // if we got a url
  
  return rv;
}
예제 #4
0
// This function takes a message uri, converts it into a file path & msgKey
// pair. It then turns that into a mailbox url object. It also registers a url
// listener if appropriate. AND it can take in a mailbox action and set that field
// on the returned url as well.
nsresult nsMailboxService::PrepareMessageUrl(const char * aSrcMsgMailboxURI, nsIUrlListener * aUrlListener,
                                             nsMailboxAction aMailboxAction, nsIMailboxUrl ** aMailboxUrl,
                                             nsIMsgWindow *msgWindow)
{
  nsresult rv = CallCreateInstance(NS_MAILBOXURL_CONTRACTID, aMailboxUrl);
  if (NS_SUCCEEDED(rv) && aMailboxUrl && *aMailboxUrl)
  {
    // okay now generate the url string
    char * urlSpec;
    nsCAutoString folderURI;
    nsMsgKey msgKey;
    nsCString folderPath;
    const char *part = PL_strstr(aSrcMsgMailboxURI, "part=");
    const char *header = PL_strstr(aSrcMsgMailboxURI, "header=");
    rv = nsParseLocalMessageURI(aSrcMsgMailboxURI, folderURI, &msgKey);
    NS_ENSURE_SUCCESS(rv,rv);
    rv = nsLocalURI2Path(kMailboxRootURI, folderURI.get(), folderPath);

    if (NS_SUCCEEDED(rv))
    {
      // set up the url spec and initialize the url with it.
      nsCAutoString buf;
      MsgEscapeURL(folderPath,
                   nsINetUtil::ESCAPE_URL_DIRECTORY | nsINetUtil::ESCAPE_URL_FORCED, buf);
      if (mPrintingOperation)
        urlSpec = PR_smprintf("mailbox://%s?number=%lu&header=print", buf.get(), msgKey);
      else if (part)
        urlSpec = PR_smprintf("mailbox://%s?number=%lu&%s", buf.get(), msgKey, part);
      else if (header)
        urlSpec = PR_smprintf("mailbox://%s?number=%lu&%s", buf.get(), msgKey, header);
      else
        urlSpec = PR_smprintf("mailbox://%s?number=%lu", buf.get(), msgKey);

      nsCOMPtr <nsIMsgMailNewsUrl> url = do_QueryInterface(*aMailboxUrl);
      url->SetSpec(nsDependentCString(urlSpec));
      PR_smprintf_free(urlSpec);

      (*aMailboxUrl)->SetMailboxAction(aMailboxAction);

      // set up the url listener
      if (aUrlListener)
        rv = url->RegisterListener(aUrlListener);

      url->SetMsgWindow(msgWindow);
      nsCOMPtr<nsIMsgMessageUrl> msgUrl = do_QueryInterface(url);
      if (msgUrl)
      {
        msgUrl->SetOriginalSpec(aSrcMsgMailboxURI);
        msgUrl->SetUri(aSrcMsgMailboxURI);
      }

    } // if we got a url
  } // if we got a url

  return rv;
}
예제 #5
0
char*
DefaultServerNicknameForCert(CERTCertificate* cert)
{
  char* nickname = nullptr;
  int count;
  bool conflict;
  char* servername = nullptr;

  servername = CERT_GetCommonName(&cert->subject);
  if (!servername) {
    // Certs without common names are strange, but they do exist...
    // Let's try to use another string for the nickname
    servername = CERT_GetOrgUnitName(&cert->subject);
    if (!servername) {
      servername = CERT_GetOrgName(&cert->subject);
      if (!servername) {
        servername = CERT_GetLocalityName(&cert->subject);
        if (!servername) {
          servername = CERT_GetStateName(&cert->subject);
          if (!servername) {
            servername = CERT_GetCountryName(&cert->subject);
            if (!servername) {
              // We tried hard, there is nothing more we can do.
              // A cert without any names doesn't really make sense.
              return nullptr;
            }
          }
        }
      }
    }
  }

  count = 1;
  while (1) {
    if (count == 1) {
      nickname = PR_smprintf("%s", servername);
    }
    else {
      nickname = PR_smprintf("%s #%d", servername, count);
    }
    if (!nickname) {
      break;
    }

    conflict = SEC_CertNicknameConflict(nickname, &cert->derSubject,
                                        cert->dbhandle);
    if (!conflict) {
      break;
    }
    PR_Free(nickname);
    count++;
  }
  PR_FREEIF(servername);
  return nickname;
}
예제 #6
0
/*
 GenerateFullFolderNameWithDefaultNamespace takes a folder name in canonical form,
  converts it to online form, allocates a string to contain the full online server name
  including the namespace prefix of the default namespace of the given type, in the form:
  PR_smprintf("%s%s", prefix, onlineServerName) if there is a NULL owner
  PR_smprintf("%s%s%c%s", prefix, owner, delimiter, onlineServerName) if there is an owner
  It then converts this back to canonical form and returns it (allocated) to libmsg.
  It returns NULL if there is no namespace of the given type.
  If nsUsed is not passed in as NULL, then *nsUsed is filled in and returned;  it is the
  namespace used for generating the folder name.
*/
char *nsIMAPNamespaceList::GenerateFullFolderNameWithDefaultNamespace(const char *hostName,
        const char *canonicalFolderName,
        const char *owner,
        EIMAPNamespaceType nsType,
        nsIMAPNamespace **nsUsed)
{
    nsresult rv = NS_OK;

    nsCOMPtr<nsIImapHostSessionList> hostSession =
        do_GetService(kCImapHostSessionListCID, &rv);
    NS_ENSURE_SUCCESS(rv, nullptr);
    nsIMAPNamespace *ns;
    char *fullFolderName = nullptr;
    rv = hostSession->GetDefaultNamespaceOfTypeForHost(hostName, nsType, ns);
    NS_ENSURE_SUCCESS(rv, nullptr);
    if (ns)
    {
        if (nsUsed)
            *nsUsed = ns;
        const char *prefix = ns->GetPrefix();
        char *convertedFolderName = AllocateServerFolderName(canonicalFolderName, ns->GetDelimiter());
        if (convertedFolderName)
        {
            char *convertedReturnName = nullptr;
            if (owner)
            {
                convertedReturnName = PR_smprintf("%s%s%c%s", prefix, owner, ns->GetDelimiter(), convertedFolderName);
            }
            else
            {
                convertedReturnName = PR_smprintf("%s%s", prefix, convertedFolderName);
            }

            if (convertedReturnName)
            {
                fullFolderName = AllocateCanonicalFolderName(convertedReturnName, ns->GetDelimiter());
                PR_Free(convertedReturnName);
            }
            PR_Free(convertedFolderName);
        }
        else
        {
            NS_ASSERTION(false, "couldn't allocate server folder name");
        }
    }
    else
    {
        // Could not find other users namespace on the given host
        NS_ASSERTION(false, "couldn't find namespace for given host");
    }
    return (fullFolderName);
}
예제 #7
0
파일: pk11.c 프로젝트: emaldona/nss
/*************************************************************************
 *
 * F i p s M o d e
 * If arg=="true", enable FIPS mode on the internal module.  If arg=="false",
 * disable FIPS mode on the internal module.
 */
Error
FipsMode(char *arg)
{
    char *internal_name;

    if (!PORT_Strcasecmp(arg, "true")) {
        if (!PK11_IsFIPS()) {
            internal_name = PR_smprintf("%s",
                                        SECMOD_GetInternalModule()->commonName);
            if (SECMOD_DeleteInternalModule(internal_name) != SECSuccess) {
                PR_fprintf(PR_STDERR, "%s\n", SECU_Strerror(PORT_GetError()));
                PR_smprintf_free(internal_name);
                PR_fprintf(PR_STDERR, errStrings[FIPS_SWITCH_FAILED_ERR]);
                return FIPS_SWITCH_FAILED_ERR;
            }
            PR_smprintf_free(internal_name);
            if (!PK11_IsFIPS()) {
                PR_fprintf(PR_STDERR, errStrings[FIPS_SWITCH_FAILED_ERR]);
                return FIPS_SWITCH_FAILED_ERR;
            }
            PR_fprintf(PR_STDOUT, msgStrings[FIPS_ENABLED_MSG]);
        } else {
            PR_fprintf(PR_STDERR, errStrings[FIPS_ALREADY_ON_ERR]);
            return FIPS_ALREADY_ON_ERR;
        }
    } else if (!PORT_Strcasecmp(arg, "false")) {
        if (PK11_IsFIPS()) {
            internal_name = PR_smprintf("%s",
                                        SECMOD_GetInternalModule()->commonName);
            if (SECMOD_DeleteInternalModule(internal_name) != SECSuccess) {
                PR_fprintf(PR_STDERR, "%s\n", SECU_Strerror(PORT_GetError()));
                PR_smprintf_free(internal_name);
                PR_fprintf(PR_STDERR, errStrings[FIPS_SWITCH_FAILED_ERR]);
                return FIPS_SWITCH_FAILED_ERR;
            }
            PR_smprintf_free(internal_name);
            if (PK11_IsFIPS()) {
                PR_fprintf(PR_STDERR, errStrings[FIPS_SWITCH_FAILED_ERR]);
                return FIPS_SWITCH_FAILED_ERR;
            }
            PR_fprintf(PR_STDOUT, msgStrings[FIPS_DISABLED_MSG]);
        } else {
            PR_fprintf(PR_STDERR, errStrings[FIPS_ALREADY_OFF_ERR]);
            return FIPS_ALREADY_OFF_ERR;
        }
    } else {
        PR_fprintf(PR_STDERR, errStrings[INVALID_FIPS_ARG]);
        return INVALID_FIPS_ARG;
    }

    return SUCCESS;
}
예제 #8
0
void
Pk11Install_yyerror(char *message)
{
    char *tmp;
    if (Pk11Install_yyerrstr) {
        tmp = PR_smprintf("%sline %d: %s\n", Pk11Install_yyerrstr,
                          Pk11Install_yylinenum, message);
        PR_smprintf_free(Pk11Install_yyerrstr);
    } else {
        tmp = PR_smprintf("line %d: %s\n", Pk11Install_yylinenum, message);
    }
    Pk11Install_yyerrstr = tmp;
}
예제 #9
0
/* Returned string needs to be PR_Free'd by caller */
static char *LoadRCDATAVersion(HMODULE hMod, ULONG resid)
{
   APIRET rc;
   ULONG  ulSize = 0;
   char  *string = 0;

   rc = DosQueryResourceSize(hMod, RT_RCDATA, resid, &ulSize);

   // version info is should be 8 chars
   if (rc == NO_ERROR && ulSize == 8)
   {
      char *version = NULL;
      rc = DosGetResource(hMod, RT_RCDATA, resid, (void**) &version);

      if (rc == NO_ERROR)
      {
         string = PR_smprintf("%d.%d.%d.%d\n",
                              version[0], version[2], version[4], version[6]);

         DosFreeResource(version);
      }
   }

   return string;
}
예제 #10
0
nsresult
nsEnigMsgCompose::WriteSignedHeaders1(EMBool isEightBit)
{
  nsresult rv;
  DEBUG_LOG(("nsEnigMsgCompose::WriteSignedHeaders1: %d\n", (int) isEightBit));

  rv = MakeBoundary("enig");
  if (NS_FAILED(rv))
    return rv;

  char* headers = PR_smprintf(
       "Content-Type: multipart/signed; micalg=pgp-%s;\r\n"
       " protocol=\"application/pgp-signature\";\r\n"
       " boundary=\"%s\"\r\n"
       "%s"
       "This is an OpenPGP/MIME signed message (RFC 2440 and 3156)\r\n"
       "--%s\r\n",
       mHashAlgorithm.get(), mBoundary.get(),
       isEightBit ? "Content-Transfer-Encoding: 8bit\r\n\r\n" : "\r\n",
       mBoundary.get());

  if (!headers)
    return NS_ERROR_OUT_OF_MEMORY;

  rv = WriteOut(headers, strlen(headers));

  PR_Free(headers);

  return rv;
}
예제 #11
0
파일: lginit.c 프로젝트: Jar-win/Waterfox
static char *
lg_keydb_name_cb(void *arg, int dbVersion)
{
    const char *configdir = (const char *)arg;
    const char *dbver;
    char *smpname = NULL;
    char *dbname = NULL;
    
    switch (dbVersion) {
      case 4:
	dbver = "4";
	break;
      case 3:
	dbver = "3";
	break;
      case 1:
	dbver = "1";
	break;
      case 2:
      default:
	dbver = "";
	break;
    }

    smpname = PR_smprintf(KEY_DB_FMT, configdir, dbver);
    if (smpname) {
	dbname = PORT_Strdup(smpname);
	PR_smprintf_free(smpname);
    }
    return dbname;
}
예제 #12
0
nsIMAPBodypartMessage::nsIMAPBodypartMessage(char *partNum,
                                             nsIMAPBodypart *parentPart,
                                             bool topLevelMessage,
                                             char *bodyType, char *bodySubType,
                                             char *bodyID,
                                             char *bodyDescription,
                                             char *bodyEncoding,
                                             int32_t partLength,
                                             bool preferPlainText)
 : nsIMAPBodypartLeaf(partNum, parentPart, bodyType, bodySubType, bodyID,
                      bodyDescription, bodyEncoding, partLength,
                      preferPlainText)
{
  m_topLevelMessage = topLevelMessage;
  if (m_topLevelMessage)
  {
    m_partNumberString = PR_smprintf("0");
    if (!m_partNumberString)
    {
      SetIsValid(false);
      return;
    }
  }
  m_body = NULL;
  m_headers = new nsIMAPMessageHeaders(m_partNumberString, this);  // We always have a Headers object
  if (!m_headers || !m_headers->GetIsValid())
  {
    SetIsValid(false);
    return;
  }
  SetIsValid(true);
}
예제 #13
0
파일: lginit.c 프로젝트: Jar-win/Waterfox
static CK_RV
lg_OpenKeyDB(const char * configdir, const char *prefix, PRBool readOnly,
    						NSSLOWKEYDBHandle **keydbPtr)
{
    NSSLOWKEYDBHandle *keydb;
    char * name = NULL;
    char * appName = NULL;

    if (prefix == NULL) {
	prefix = "";
    }
    configdir = lg_EvaluateConfigDir(configdir, &appName);

    name = PR_smprintf("%s" PATH_SEPARATOR "%s",configdir,prefix);	
    if (name == NULL) 
	return CKR_HOST_MEMORY;
    keydb = nsslowkey_OpenKeyDB(readOnly, appName, prefix, 
					lg_keydb_name_cb, (void *)name);
    PR_smprintf_free(name);
    if (appName) PORT_Free(appName);
    if (keydb == NULL)
	return CKR_NETSCAPE_KEYDB_FAILED;
    *keydbPtr = keydb;

    return CKR_OK;
}
예제 #14
0
/*
** Perform a three way test against PR_smprintf, PR_snprintf, and sprintf.
** Make sure the results are identical
*/
static void test_s(char *pattern, char *ss)
{
    char *s;
    unsigned char before[8];
    char buf[200];
    unsigned char after[8];
    int n;

    memset(before, 0xBB, 8);
    memset(after, 0xAA, 8);

    /* try all three routines */
    s = PR_smprintf(pattern, ss);
    PR_ASSERT(s != 0);
    n = PR_snprintf(buf, sizeof(buf), pattern, ss);
    PR_ASSERT(n <= sizeof(buf));
    sprintf(sbuf, pattern, ss);

    for (n = 0; n < 8; n++) {
	PR_ASSERT(before[n] == 0xBB);
	PR_ASSERT(after[n] == 0xAA);
    }

    /* compare results */
    if ((strncmp(s, buf, sizeof(buf)) != 0) ||
	(strncmp(s, sbuf, sizeof(sbuf)) != 0)) {
	fprintf(stderr,
	   "pattern='%s' ss=%.20s\nPR_smprintf='%s'\nPR_snprintf='%s'\n    sprintf='%s'\n",
	   pattern, ss, s, buf, sbuf);
	printf("FAIL\n");
	PR_smprintf_free(s);
	exit(-1);
    }
	PR_smprintf_free(s);
}
예제 #15
0
nsresult nsMailboxService::ParseMailbox(nsIMsgWindow *aMsgWindow, nsFileSpec& aMailboxPath, nsIStreamListener *aMailboxParser, 
										nsIUrlListener * aUrlListener, nsIURI ** aURL)
{
  nsresult rv;
  nsCOMPtr<nsIMailboxUrl> mailboxurl = do_CreateInstance(kCMailboxUrl, &rv);
  if (NS_SUCCEEDED(rv) && mailboxurl)
  {
    nsCOMPtr<nsIMsgMailNewsUrl> url = do_QueryInterface(mailboxurl);
    // okay now generate the url string
    nsFilePath filePath(aMailboxPath); // convert to file url representation...
    nsCAutoString buf;
    NS_EscapeURL((const char *)filePath,-1,
                     esc_Minimal|esc_Forced|esc_AlwaysCopy,buf);
    url->SetUpdatingFolder(PR_TRUE);
    url->SetMsgWindow(aMsgWindow);
    char *temp = PR_smprintf("mailbox://%s", buf.get());
    url->SetSpec(nsDependentCString(temp));
    PR_Free(temp);
    mailboxurl->SetMailboxParser(aMailboxParser);
    if (aUrlListener)
      url->RegisterListener(aUrlListener);
    
    RunMailboxUrl(url, nsnull);
    
    if (aURL)
    {
      *aURL = url;
      NS_IF_ADDREF(*aURL);
    }
  }
  
  return rv;
}
예제 #16
0
// nickname_collision
// what to do when the nickname collides with one already in the db.
// TODO: not handled, throw a dialog allowing the nick to be changed?
SECItem * PR_CALLBACK
nsPKCS12Blob::nickname_collision(SECItem *oldNick, PRBool *cancel, void *wincx)
{
  nsNSSShutDownPreventionLock locker;
  *cancel = false;
  nsresult rv;
  nsCOMPtr<nsINSSComponent> nssComponent(do_GetService(kNSSComponentCID, &rv));
  if (NS_FAILED(rv)) return nsnull;
  int count = 1;
  nsCString nickname;
  nsAutoString nickFromProp;
  nssComponent->GetPIPNSSBundleString("P12DefaultNickname", nickFromProp);
  NS_ConvertUTF16toUTF8 nickFromPropC(nickFromProp);
  // The user is trying to import a PKCS#12 file that doesn't have the
  // attribute we use to set the nickname.  So in order to reduce the
  // number of interactions we require with the user, we'll build a nickname
  // for the user.  The nickname isn't prominently displayed in the UI, 
  // so it's OK if we generate one on our own here.
  //   XXX If the NSS API were smarter and actually passed a pointer to
  //       the CERTCertificate* we're importing we could actually just
  //       call default_nickname (which is what the issuance code path
  //       does) and come up with a reasonable nickname.  Alas, the NSS
  //       API limits our ability to produce a useful nickname without
  //       bugging the user.  :(
  while (1) {
    // If we've gotten this far, that means there isn't a certificate
    // in the database that has the same subject name as the cert we're
    // trying to import.  So we need to come up with a "nickname" to 
    // satisfy the NSS requirement or fail in trying to import.  
    // Basically we use a default nickname from a properties file and 
    // see if a certificate exists with that nickname.  If there isn't, then
    // create update the count by one and append the string '#1' Or 
    // whatever the count currently is, and look for a cert with 
    // that nickname.  Keep updating the count until we find a nickname
    // without a corresponding cert.
    //  XXX If a user imports *many* certs without the 'friendly name'
    //      attribute, then this may take a long time.  :(
    if (count > 1) {
      nickname.Adopt(PR_smprintf("%s #%d", nickFromPropC.get(), count));
    } else {
      nickname = nickFromPropC;
    }
    CERTCertificate *cert = CERT_FindCertByNickname(CERT_GetDefaultCertDB(),
                                           const_cast<char*>(nickname.get()));
    if (!cert) {
      break;
    }
    CERT_DestroyCertificate(cert);
    count++;
  }
  SECItem *newNick = new SECItem;
  if (!newNick)
    return nsnull;

  newNick->type = siAsciiString;
  newNick->data = (unsigned char*) nsCRT::strdup(nickname.get());
  newNick->len  = strlen((char*)newNick->data);
  return newNick;
}
예제 #17
0
nsresult
nsEnigMimeDecrypt::ProcessPlainData(char* buf, PRUint32 readCount)
{
  DEBUG_LOG(("nsEnigMimeDecrypt::ProcessPlainData: readCount=%d\n", readCount));

  int status;
  ++mIterations;
  // Read synchronously


  if (mIterations == 1 && readCount > 25) {
    // add mime boundaries around text/plain message (bug 6627)
    if (PL_strncasecmp("content-type:", buf, 13)==0) {
      PRUint32 whitespace=13;
      while((whitespace<readCount) && buf[whitespace] &&
            ((buf[whitespace]==' ') || (buf[whitespace]=='\t'))) { whitespace++; }
      if (buf[whitespace] && (whitespace<readCount)) {
        mCtFound = PL_strncasecmp(buf + whitespace, "text/plain", 10);
        if (mCtFound != 0) {
          mCtFound=PL_strncasecmp(buf + whitespace, "text/html", 9);
        }
      }
      if (mCtFound == 0) {
        char* header = PR_smprintf(
        "Content-Type: multipart/mixed; boundary=\"enigDummy\""
        "\n\n--enigDummy\n");
        PR_SetError(0,0);
        status = mOutputFun(header, strlen(header), mOutputClosure);
        if (status < 0) {
          PR_SetError(status, 0);
          mOutputFun = NULL;
          mOutputClosure = NULL;

          return NS_ERROR_FAILURE;
        }
        mOutputLen += strlen(header);
      }
    }
  }

  if (readCount < kCharMax) {
    // make sure we can continue to write later
    if (buf[readCount-1]==0) --readCount;
  }

  PR_SetError(0,0);
  status = mOutputFun(buf, readCount, mOutputClosure);
  if (status < 0) {
    PR_SetError(status, 0);
    mOutputFun = NULL;
    mOutputClosure = NULL;

    return NS_ERROR_FAILURE;
  }

  mOutputLen += readCount;

  return NS_OK;
} // loop end
예제 #18
0
void
nsIMAPBodypartMultipart::SetBodySubType(char *bodySubType)
{
  PR_FREEIF(m_bodySubType);
  PR_FREEIF(m_contentType);
  m_bodySubType = bodySubType;
  if (m_bodyType && m_bodySubType)
    m_contentType = PR_smprintf("%s/%s", m_bodyType, m_bodySubType);
}
NS_IMETHODIMP
nsBaseDOMException::ToString(char **aReturn)
{
  *aReturn = nsnull;

  static const char defaultMsg[] = "<no message>";
  static const char defaultLocation[] = "<unknown>";
  static const char defaultName[] = "<unknown>";
  static const char format[] =
    "[Exception... \"%s\"  code: \"%d\" nsresult: \"0x%x (%s)\"  location: \"%s\"]";

  nsCAutoString location;

  if (mInner) {
    nsXPIDLCString filename;

    mInner->GetFilename(getter_Copies(filename));

    if (!filename.IsEmpty()) {
      PRUint32 line_nr = 0;

      mInner->GetLineNumber(&line_nr);

      char *temp = PR_smprintf("%s Line: %d", filename.get(), line_nr);
      if (temp) {
        location.Assign(temp);
        PR_smprintf_free(temp);
      }
    }
  }

  if (location.IsEmpty()) {
    location = defaultLocation;
  }

  const char* msg = mMessage ? mMessage : defaultMsg;
  const char* resultName = mName ? mName : defaultName;
  PRUint32 code = NS_ERROR_GET_CODE(mResult);

  *aReturn = PR_smprintf(format, msg, code, mResult, resultName,
                         location.get());

  return *aReturn ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
char *nsMsgSearchAdapter::GetImapCharsetParam(const char16_t *destCharset) {
  char *result = nullptr;

  // Specify a character set unless we happen to be US-ASCII.
  if (NS_strcmp(destCharset, u"us-ascii"))
    result = PR_smprintf("%s%s", nsMsgSearchAdapter::m_kImapCharset,
                         NS_ConvertUTF16toUTF8(destCharset).get());

  return result;
}
예제 #21
0
int main(int argc, char* argv[])
{
  ScopedLogging log;

  nsCOMPtr<nsILocalFile> appini;
  nsresult rv = XRE_GetBinaryPath(argv[0], getter_AddRefs(appini));
  if (NS_FAILED(rv)) {
    Output("Couldn't calculate the application directory.");
    return 255;
  }
  appini->SetNativeLeafName(NS_LITERAL_CSTRING("application.ini"));

  // Allow firefox.exe to launch XULRunner apps via -app <application.ini>
  // Note that -app must be the *first* argument.
  char *appEnv = nsnull;
  const char *appDataFile = PR_GetEnv("XUL_APP_FILE");
  if (appDataFile && *appDataFile) {
    rv = XRE_GetFileFromPath(appDataFile, getter_AddRefs(appini));
    if (NS_FAILED(rv)) {
      Output("Invalid path found: '%s'", appDataFile);
      return 255;
    }
  }
  else if (argc > 1 && IsArg(argv[1], "app")) {
    if (argc == 2) {
      Output("Incorrect number of arguments passed to -app");
      return 255;
    }

    rv = XRE_GetFileFromPath(argv[2], getter_AddRefs(appini));
    if (NS_FAILED(rv)) {
      Output("application.ini path not recognized: '%s'", argv[2]);
      return 255;
    }

    appEnv = PR_smprintf("XUL_APP_FILE=%s", argv[2]);
    PR_SetEnv(appEnv);
    argv[2] = argv[0];
    argv += 2;
    argc -= 2;
  }

  nsXREAppData *appData;
  rv = XRE_CreateAppData(appini, &appData);
  if (NS_FAILED(rv)) {
    Output("Couldn't read application.ini");
    return 255;
  }

  int result = XRE_main(argc, argv, appData);
  XRE_FreeAppData(appData);
  if (appEnv)
    PR_smprintf_free(appEnv);
  return result;
}
예제 #22
0
char *
nsMsgSearchAdapter::GetImapCharsetParam(const PRUnichar *destCharset)
{
  char *result = nsnull;

  // Specify a character set unless we happen to be US-ASCII.
  if (NS_strcmp(destCharset, NS_LITERAL_STRING("us-ascii").get()))
      result = PR_smprintf("%s%s", nsMsgSearchAdapter::m_kImapCharset, NS_ConvertUTF16toUTF8(destCharset).get());

  return result;
}
예제 #23
0
/*************************************************************************
 *
 * j a r _ c a l l b a c k
 */
static int
jar_callback(int status, JAR *foo, const char *bar, char *pathname,
	char *errortext) {
	char *string;

	string = PR_smprintf("JAR error %d: %s in file %s\n", status, errortext,
		pathname);
	error(PK11_INSTALL_ERROR_STRING, string);
	PR_smprintf_free(string);
	return 0;
}
예제 #24
0
void
ht_rjcprintf(PRFileDesc *file, const char *fmt, const char *data)
{
	char	*buf;

	buf = PR_smprintf(fmt, data);
	if(buf) {
		PR_Write(file, buf, strlen(buf));
		free(buf);
	}
}
예제 #25
0
파일: ConfigStore.cpp 프로젝트: encukou/pki
ConfigStore ConfigStore::GetSubStore(const char *substore)
{
	char *newname=NULL;
	const char *name = m_substore_name;
	if (strlen(name)==0) {	  // this is the root
		newname = PL_strdup(substore);
	} else {
		newname = PR_smprintf("%s.%s",name,substore);
	}
	return ConfigStore(m_root,newname);
}
static char *nssutil_formatIntPair(char *name, unsigned long value, 
                                  unsigned long def)
{
    char *returnValue;

    if (value == def) return nssutil_nullString;

    returnValue = PR_smprintf("%s=%d",name,value);

    return returnValue;
}
예제 #27
0
char*
nsTimeSampler::PrintStats()
{
    double mean = mTotalTime / mCount;
    double variance = fabs(mSquares / mCount - mean * mean);
    double stddev = sqrt(variance);
    PRUint32 imean = (PRUint32)mean;
    PRUint32 istddev = (PRUint32)stddev;
    return PR_smprintf("%d +/- %d ms", 
                       PR_IntervalToMilliseconds(imean),
                       PR_IntervalToMilliseconds(istddev));
}
예제 #28
0
파일: searchthread.c 프로젝트: Firstyear/ds
static int st_search(SearchThread *st)
{
    char *filterBuffer = NULL;
    char *pFilter;
    struct timeval timeout;
    struct timeval *timeoutp;
    int scope, attrsOnly = 0;
    LDAPMessage *result;
    int ret;

    scope = myScope;
    if (ntable || numeric) {
        char *s = NULL;
        char num[22]; /* string length of unsigned 64 bit integer + 1 */

        if (! numeric) {
            do {
                s = nt_getrand(ntable);
            } while ((s) && (strlen(s) < 1));
        } else {
            sprintf(num, "%d", get_large_random_number() % numeric);
            s = num;
        }
        filterBuffer = PR_smprintf("%s%s",filter, s ? s : "");
        pFilter = filterBuffer;
    } else {
        pFilter = filter;
    }

    /* Try to get attributes from the attrNameTable */
    if (!attrToReturn)
        attrToReturn = nt_get_all(attrTable);

    if (searchTimelimit <= 0) {
        timeoutp = NULL;
    } else {
        timeout.tv_sec = searchTimelimit;
        timeout.tv_usec = 0;
        timeoutp = &timeout;
    }
    ret = ldap_search_ext_s(st->ld, suffix, scope, pFilter, attrToReturn,
                            attrsOnly, NULL, NULL, timeoutp, -1, &result);
    if (ret != LDAP_SUCCESS) {
        fprintf(stderr, "T%d: failed to search 2, error=0x%02X\n",
                st->id, ret);
    }
    ldap_msgfree(result);
    if(filterBuffer){
        PR_smprintf_free(filterBuffer);
    }

    return ret;
}
예제 #29
0
void
ht_fprintf(PRFileDesc *file, const char *fmt, ...) 
{
    va_list ap;
    char *buf;
    va_start(ap, fmt);
    buf = PR_smprintf(fmt, ap);
    va_end(ap);
    if(buf) {
      	PR_Write(file, buf, strlen(buf));
	free(buf);
    }
}
예제 #30
0
파일: util.c 프로젝트: lofter2011/Icefox
/*
 *  R e m o v e A l l A r c
 *
 *  Remove .arc directories that are lingering
 *  from a previous run of signtool.
 *
 */
int
RemoveAllArc(char *tree)
{
    PRDir * dir;
    PRDirEntry * entry;
    char	*archive = NULL;
    int	retval = 0;

    dir = PR_OpenDir (tree);
    if (!dir)
        return - 1;

    for (entry = PR_ReadDir (dir, 0); entry; entry = PR_ReadDir (dir,
            0)) {

        if (entry->name[0] == '.') {
            continue;
        }

        if (archive)
            PR_Free(archive);
        archive = PR_smprintf("%s/%s", tree, entry->name);

        if (PL_strcaserstr (entry->name, ".arc")
                == (entry->name + strlen(entry->name) - 4) ) {

            if (verbosity >= 0) {
                PR_fprintf(outputFD, "removing: %s\n", archive);
            }

            if (rm_dash_r(archive)) {
                PR_fprintf(errorFD, "Error removing %s\n", archive);
                errorCount++;
                retval = -1;
                goto finish;
            }
        } else if (is_dir(archive)) {
            if (RemoveAllArc(archive)) {
                retval = -1;
                goto finish;
            }
        }
    }

finish:
    PR_CloseDir (dir);
    if (archive)
        PR_Free(archive);

    return retval;
}