本文整理汇总了C++中PR_smprintf函数的典型用法代码示例。如果您正苦于以下问题:C++ PR_smprintf函数的具体用法?C++ PR_smprintf怎么用?C++ PR_smprintf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PR_smprintf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: nssutil_formatPair
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;
}
示例2: CallCreateInstance
// 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;
}
示例3: CallCreateInstance
// 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;
}
示例4: DefaultServerNicknameForCert
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;
}
示例5: PR_smprintf
/*
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);
}
示例6: FipsMode
/*************************************************************************
*
* 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;
}
示例7: Pk11Install_yyerror
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;
}
示例8: DosQueryResourceSize
/* 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;
}
示例9: DEBUG_LOG
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;
}
示例10: lg_keydb_name_cb
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;
}
示例11: nsIMAPBodypartLeaf
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);
}
示例12: lg_OpenKeyDB
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;
}
示例13: do_CreateInstance
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;
}
示例14: DEBUG_LOG
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
示例15: PR_FREEIF
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);
}