本文整理汇总了C++中ToNewCString函数的典型用法代码示例。如果您正苦于以下问题:C++ ToNewCString函数的具体用法?C++ ToNewCString怎么用?C++ ToNewCString使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ToNewCString函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: listVMs
/**
* Display all registered VMs on the screen with some information about each
*
* @param virtualBox VirtualBox instance object.
*/
void listVMs(IVirtualBox *virtualBox)
{
nsresult rc;
printf("----------------------------------------------------\n");
printf("VM List:\n\n");
/*
* Get the list of all registered VMs
*/
IMachine **machines = NULL;
PRUint32 machineCnt = 0;
rc = virtualBox->GetMachines(&machineCnt, &machines);
if (NS_SUCCEEDED(rc))
{
/*
* Iterate through the collection
*/
for (PRUint32 i = 0; i < machineCnt; ++ i)
{
IMachine *machine = machines[i];
if (machine)
{
PRBool isAccessible = PR_FALSE;
machine->GetAccessible(&isAccessible);
if (isAccessible)
{
nsXPIDLString machineName;
machine->GetName(getter_Copies(machineName));
char *machineNameAscii = ToNewCString(machineName);
printf("\tName: %s\n", machineNameAscii);
free(machineNameAscii);
}
else
{
printf("\tName: <inaccessible>\n");
}
nsXPIDLString iid;
machine->GetId(getter_Copies(iid));
const char *uuidString = ToNewCString(iid);
printf("\tUUID: %s\n", uuidString);
free((void*)uuidString);
if (isAccessible)
{
nsXPIDLString configFile;
machine->GetSettingsFilePath(getter_Copies(configFile));
char *configFileAscii = ToNewCString(configFile);
printf("\tConfig file: %s\n", configFileAscii);
free(configFileAscii);
PRUint32 memorySize;
machine->GetMemorySize(&memorySize);
printf("\tMemory size: %uMB\n", memorySize);
nsXPIDLString typeId;
machine->GetOSTypeId(getter_Copies(typeId));
IGuestOSType *osType = nsnull;
virtualBox->GetGuestOSType (typeId.get(), &osType);
nsXPIDLString osName;
osType->GetDescription(getter_Copies(osName));
char *osNameAscii = ToNewCString(osName);
printf("\tGuest OS: %s\n\n", osNameAscii);
free(osNameAscii);
osType->Release();
}
/* don't forget to release the objects in the array... */
machine->Release();
}
}
}
printf("----------------------------------------------------\n\n");
}
示例2: ToNewCString
NS_INTERFACE_MAP_END
//----------------------------------------------------------------------
// nsISVGValue methods:
NS_IMETHODIMP
nsSVGPreserveAspectRatio::SetValueString(const nsAString& aValue)
{
char* str = ToNewCString(aValue);
if (!str) return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = NS_OK;
char* rest = str;
char* token;
const char* delimiters = "\x20\x9\xD\xA";
PRUint16 align, meetOrSlice;
token = nsCRT::strtok(rest, delimiters, &rest);
if (token && !strcmp(token, "defer"))
// Ignore: only applicable for preserveAspectRatio on 'image' elements
token = nsCRT::strtok(rest, delimiters, &rest);
if (token) {
if (!strcmp(token, "none"))
align = SVG_PRESERVEASPECTRATIO_NONE;
else if (!strcmp(token, "xMinYMin"))
align = SVG_PRESERVEASPECTRATIO_XMINYMIN;
else if (!strcmp(token, "xMidYMin"))
align = SVG_PRESERVEASPECTRATIO_XMIDYMIN;
else if (!strcmp(token, "xMaxYMin"))
align = SVG_PRESERVEASPECTRATIO_XMAXYMIN;
else if (!strcmp(token, "xMinYMid"))
align = SVG_PRESERVEASPECTRATIO_XMINYMID;
else if (!strcmp(token, "xMidYMid"))
align = SVG_PRESERVEASPECTRATIO_XMIDYMID;
else if (!strcmp(token, "xMaxYMid"))
align = SVG_PRESERVEASPECTRATIO_XMAXYMID;
else if (!strcmp(token, "xMinYMax"))
align = SVG_PRESERVEASPECTRATIO_XMINYMAX;
else if (!strcmp(token, "xMidYMax"))
align = SVG_PRESERVEASPECTRATIO_XMIDYMAX;
else if (!strcmp(token, "xMaxYMax"))
align = SVG_PRESERVEASPECTRATIO_XMAXYMAX;
else
rv = NS_ERROR_FAILURE;
if (NS_SUCCEEDED(rv)) {
token = nsCRT::strtok(rest, delimiters, &rest);
if (token) {
if (!strcmp(token, "meet"))
meetOrSlice = SVG_MEETORSLICE_MEET;
else if (!strcmp(token, "slice"))
meetOrSlice = SVG_MEETORSLICE_SLICE;
else
rv = NS_ERROR_FAILURE;
}
else
meetOrSlice = SVG_MEETORSLICE_MEET;
}
}
else // align not specified
rv = NS_ERROR_FAILURE;
if (nsCRT::strtok(rest, delimiters, &rest)) // there's more
rv = NS_ERROR_FAILURE;
if (NS_SUCCEEDED(rv)) {
WillModify();
mAlign = align;
mMeetOrSlice = meetOrSlice;
DidModify();
}
nsMemory::Free(str);
return rv;
}
示例3: MimeMessage_partial_message_html
static char *
MimeMessage_partial_message_html(const char *data, void *closure,
MimeHeaders *headers)
{
MimeMessage *msg = (MimeMessage *)closure;
nsCAutoString orig_url(data);
char *uidl = MimeHeaders_get(headers, HEADER_X_UIDL, PR_FALSE, PR_FALSE);
char *msgId = MimeHeaders_get(headers, HEADER_MESSAGE_ID, PR_FALSE,
PR_FALSE);
char *msgIdPtr = PL_strstr(msgId, "<");
int msgBase;
PRInt32 pos = orig_url.Find("mailbox-message");
if (pos != -1)
orig_url.Cut(pos + 7, 8);
pos = orig_url.Find("#");
if (pos != -1)
orig_url.Replace(pos, 1, "?number=", 8);
if (msgIdPtr)
msgIdPtr++;
else
msgIdPtr = msgId;
char *gtPtr = PL_strstr(msgIdPtr, ">");
if (gtPtr)
*gtPtr = 0;
msgBase = (msg->bodyLength > MSG_LINEBREAK_LEN) ? MIME_MSG_PARTIAL_FMT_1 : MIME_MSG_PARTIAL_FMT2_1;
nsCString partialMsgHtml;
nsCString item;
item.Adopt(MimeGetStringByID(msgBase));
partialMsgHtml += item;
item.Adopt(MimeGetStringByID(msgBase+1));
partialMsgHtml += item;
partialMsgHtml.Append(orig_url);
if (msgIdPtr) {
partialMsgHtml.AppendLiteral("&messageid=");
MsgEscapeString(nsDependentCString(msgIdPtr), nsINetUtil::ESCAPE_URL_PATH,
item);
partialMsgHtml.Append(item);
}
if (uidl) {
partialMsgHtml.AppendLiteral("&uidl=");
MsgEscapeString(nsDependentCString(uidl), nsINetUtil::ESCAPE_XALPHAS,
item);
partialMsgHtml.Append(item);
}
item.Adopt(MimeGetStringByID(msgBase+2));
partialMsgHtml += item;
return ToNewCString(partialMsgHtml);
}
示例4: lBFSTable
// walks the graph using a breadth-first-search algorithm which generates a discovered
// verticies tree. This tree is then walked up (from destination vertex, to origin vertex)
// and each link in the chain is added to an nsStringArray. A direct lookup for the given
// CONTRACTID should be made prior to calling this method in an attempt to find a direct
// converter rather than walking the graph.
nsresult
nsStreamConverterService::FindConverter(const char *aContractID, nsTArray<nsCString> **aEdgeList) {
nsresult rv;
if (!aEdgeList) return NS_ERROR_NULL_POINTER;
*aEdgeList = nullptr;
// walk the graph in search of the appropriate converter.
int32_t vertexCount = mAdjacencyList->Count();
if (0 >= vertexCount) return NS_ERROR_FAILURE;
// Create a corresponding color table for each vertex in the graph.
nsObjectHashtable lBFSTable(nullptr, nullptr, DeleteBFSEntry, nullptr);
mAdjacencyList->Enumerate(InitBFSTable, &lBFSTable);
NS_ASSERTION(lBFSTable.Count() == vertexCount, "strmconv BFS table init problem");
// This is our source vertex; our starting point.
nsAutoCString fromC, toC;
rv = ParseFromTo(aContractID, fromC, toC);
if (NS_FAILED(rv)) return rv;
nsCStringKey *source = new nsCStringKey(fromC.get());
if (!source) return NS_ERROR_OUT_OF_MEMORY;
SCTableData *data = (SCTableData*)lBFSTable.Get(source);
if (!data) {
delete source;
return NS_ERROR_FAILURE;
}
BFSState *state = data->data.state;
state->color = gray;
state->distance = 0;
CStreamConvDeallocator *dtorFunc = new CStreamConvDeallocator();
if (!dtorFunc) {
delete source;
return NS_ERROR_OUT_OF_MEMORY;
}
nsDeque grayQ(dtorFunc);
// Now generate the shortest path tree.
grayQ.Push(source);
while (0 < grayQ.GetSize()) {
nsCStringKey *currentHead = (nsCStringKey*)grayQ.PeekFront();
SCTableData *data2 = (SCTableData*)mAdjacencyList->Get(currentHead);
if (!data2) return NS_ERROR_FAILURE;
nsCOMArray<nsIAtom> *edges = data2->data.edges;
NS_ASSERTION(edges, "something went wrong with BFS strmconv algorithm");
if (!edges) return NS_ERROR_FAILURE;
// Get the state of the current head to calculate the distance of each
// reachable vertex in the loop.
data2 = (SCTableData*)lBFSTable.Get(currentHead);
if (!data2) return NS_ERROR_FAILURE;
BFSState *headVertexState = data2->data.state;
NS_ASSERTION(headVertexState, "problem with the BFS strmconv algorithm");
if (!headVertexState) return NS_ERROR_FAILURE;
int32_t edgeCount = edges->Count();
for (int32_t i = 0; i < edgeCount; i++) {
nsIAtom* curVertexAtom = edges->ObjectAt(i);
nsAutoString curVertexStr;
curVertexAtom->ToString(curVertexStr);
nsCStringKey *curVertex = new nsCStringKey(ToNewCString(curVertexStr),
curVertexStr.Length(), nsCStringKey::OWN);
if (!curVertex) return NS_ERROR_OUT_OF_MEMORY;
SCTableData *data3 = (SCTableData*)lBFSTable.Get(curVertex);
if (!data3) {
delete curVertex;
return NS_ERROR_FAILURE;
}
BFSState *curVertexState = data3->data.state;
NS_ASSERTION(curVertexState, "something went wrong with the BFS strmconv algorithm");
if (!curVertexState) return NS_ERROR_FAILURE;
if (white == curVertexState->color) {
curVertexState->color = gray;
curVertexState->distance = headVertexState->distance + 1;
curVertexState->predecessor = (nsCStringKey*)currentHead->Clone();
if (!curVertexState->predecessor) {
delete curVertex;
return NS_ERROR_OUT_OF_MEMORY;
}
grayQ.Push(curVertex);
} else {
delete curVertex; // if this vertex has already been discovered, we don't want
// to leak it. (non-discovered vertex's get cleaned up when
// they're popped).
//.........这里部分代码省略.........
示例5:
NS_IMETHODIMP
nsScriptError::GetCategory(char **result) {
*result = ToNewCString(mCategory);
return NS_OK;
}
示例6: lf
nsresult
nsOperaProfileMigrator::CopyPreferences(PRBool aReplace)
{
nsresult rv;
nsCOMPtr<nsIFile> operaPrefs;
mOperaProfile->Clone(getter_AddRefs(operaPrefs));
operaPrefs->Append(OPERA_PREFERENCES_FILE_NAME);
nsCOMPtr<nsILocalFile> lf(do_QueryInterface(operaPrefs));
NS_ENSURE_TRUE(lf, NS_ERROR_UNEXPECTED);
nsINIParser parser;
rv = parser.Init(lf);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIPrefBranch> branch(do_GetService(NS_PREFSERVICE_CONTRACTID));
// Traverse the standard transforms
PrefTransform* transform;
PrefTransform* end = gTransforms + sizeof(gTransforms)/sizeof(PrefTransform);
const char* lastSectionName = nsnull;
for (transform = gTransforms; transform < end; ++transform) {
if (transform->sectionName)
lastSectionName = transform->sectionName;
if (transform->type == _OPM(COLOR)) {
char* colorString = nsnull;
nsresult rv = ParseColor(parser, lastSectionName, &colorString);
if (NS_SUCCEEDED(rv)) {
transform->stringValue = colorString;
transform->prefHasValue = PR_TRUE;
transform->prefSetterFunc(transform, branch);
}
if (colorString)
free(colorString);
}
else {
nsCAutoString val;
rv = parser.GetString(lastSectionName,
transform->keyName,
val);
if (NS_SUCCEEDED(rv)) {
nsresult strerr;
switch (transform->type) {
case _OPM(STRING):
transform->stringValue = ToNewCString(val);
break;
case _OPM(INT): {
transform->intValue = val.ToInteger(&strerr);
}
break;
case _OPM(BOOL): {
transform->boolValue = val.ToInteger(&strerr) != 0;
}
break;
default:
break;
}
transform->prefHasValue = PR_TRUE;
transform->prefSetterFunc(transform, branch);
if (transform->type == _OPM(STRING) && transform->stringValue) {
NS_Free(transform->stringValue);
transform->stringValue = nsnull;
}
}
}
}
// Copy Proxy Settings
CopyProxySettings(parser, branch);
// Copy User Content Sheet
if (aReplace)
CopyUserContentSheet(parser);
return NS_OK;
}
示例7: ProcessFormat
NS_IMETHODIMP
nsAbLDAPAutoCompFormatter::GetAttributes(PRUint32 *aCount, char ** *aAttrs)
{
if (!aCount || !aAttrs) {
return NS_ERROR_INVALID_POINTER;
}
nsCStringArray mSearchAttrs;
nsresult rv = ProcessFormat(mNameFormat, 0, 0, &mSearchAttrs);
if (NS_FAILED(rv)) {
NS_WARNING("nsAbLDAPAutoCompFormatter::SetNameFormat(): "
"ProcessFormat() failed");
return rv;
}
rv = ProcessFormat(mAddressFormat, 0, 0, &mSearchAttrs);
if (NS_FAILED(rv)) {
NS_WARNING("nsAbLDAPAutoCompFormatter::SetNameFormat(): "
"ProcessFormat() failed");
return rv;
}
rv = ProcessFormat(mCommentFormat, 0, 0, &mSearchAttrs);
if (NS_FAILED(rv)) {
NS_WARNING("nsAbLDAPAutoCompFormatter::SetNameFormat(): "
"ProcessFormat() failed");
return rv;
}
// none of the formatting templates require any LDAP attributes
//
PRUint32 count = mSearchAttrs.Count(); // size of XPCOM array we'll need
if (!count) {
NS_ERROR("nsAbLDAPAutoCompFormatter::GetAttributes(): "
"current output format (if set) requires no search "
"attributes");
return NS_ERROR_NOT_INITIALIZED;
}
// build up the raw XPCOM array to return
//
PRUint32 rawSearchAttrsSize = 0; // grown as XPCOM array is built
char **rawSearchAttrs =
static_cast<char **>(nsMemory::Alloc(count * sizeof(char *)));
if (!rawSearchAttrs) {
NS_ERROR("nsAbLDAPAutoCompFormatter::GetAttributes(): out of "
"memory");
return NS_ERROR_OUT_OF_MEMORY;
}
// Loop through the string array, and build up the C-array.
//
while (rawSearchAttrsSize < count) {
if (!(rawSearchAttrs[rawSearchAttrsSize] =
ToNewCString(*(mSearchAttrs.CStringAt(rawSearchAttrsSize))))) {
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(rawSearchAttrsSize,
rawSearchAttrs);
NS_ERROR("nsAbLDAPAutoCompFormatter::GetAttributes(): out "
"of memory");
return NS_ERROR_OUT_OF_MEMORY;
}
rawSearchAttrsSize++;
}
*aCount = rawSearchAttrsSize;
*aAttrs = rawSearchAttrs;
return NS_OK;
}
示例8: GetName
/* read only attribute string name; */
NS_IMETHODIMP nsAbDirectoryQueryPropertyValue::GetName(char* *aName)
{
*aName = mName.IsEmpty() ? 0 : ToNewCString(mName);
return NS_OK;
}
示例9: writeoutto
nsresult writeoutto(const char* i_pURL, char** o_Result, int32_t urlFactory = URL_FACTORY_DEFAULT)
{
if (!o_Result || !i_pURL)
return NS_ERROR_FAILURE;
*o_Result = 0;
nsCOMPtr<nsIURI> pURL;
nsresult result = NS_OK;
switch (urlFactory) {
case URL_FACTORY_STDURL: {
nsIURI* url;
result = CallCreateInstance(kStdURLCID, &url);
if (NS_FAILED(result))
{
printf("CreateInstance failed\n");
return NS_ERROR_FAILURE;
}
pURL = url;
pURL->SetSpec(nsDependentCString(i_pURL));
break;
}
case URL_FACTORY_DEFAULT: {
nsCOMPtr<nsIIOService> pService =
do_GetService(kIOServiceCID, &result);
if (NS_FAILED(result))
{
printf("Service failed!\n");
return NS_ERROR_FAILURE;
}
result = pService->NewURI(nsDependentCString(i_pURL), nullptr, nullptr, getter_AddRefs(pURL));
}
}
nsCString output;
if (NS_SUCCEEDED(result))
{
nsCOMPtr<nsIURL> tURL = do_QueryInterface(pURL);
nsAutoCString temp;
int32_t port;
nsresult rv;
#define RESULT() NS_SUCCEEDED(rv) ? temp.get() : ""
rv = tURL->GetScheme(temp);
output += RESULT();
output += ',';
rv = tURL->GetUsername(temp);
output += RESULT();
output += ',';
rv = tURL->GetPassword(temp);
output += RESULT();
output += ',';
rv = tURL->GetHost(temp);
output += RESULT();
output += ',';
rv = tURL->GetPort(&port);
char portbuffer[40];
snprintf_literal(portbuffer, "%d", port);
output.Append(portbuffer);
output += ',';
rv = tURL->GetDirectory(temp);
output += RESULT();
output += ',';
rv = tURL->GetFileBaseName(temp);
output += RESULT();
output += ',';
rv = tURL->GetFileExtension(temp);
output += RESULT();
output += ',';
// removed with https://bugzilla.mozilla.org/show_bug.cgi?id=665706
// rv = tURL->GetParam(temp);
// output += RESULT();
output += ',';
rv = tURL->GetQuery(temp);
output += RESULT();
output += ',';
rv = tURL->GetRef(temp);
output += RESULT();
output += ',';
rv = tURL->GetSpec(temp);
output += RESULT();
*o_Result = ToNewCString(output);
} else {
output = "Can not create URL";
*o_Result = ToNewCString(output);
}
return NS_OK;
}
示例10: nsMsgI18NSaveAsCharset
nsresult nsMsgI18NSaveAsCharset(const char* contentType, const char *charset,
const char16_t* inString, char** outString,
char **fallbackCharset, bool *isAsciiOnly)
{
NS_ENSURE_ARG_POINTER(contentType);
NS_ENSURE_ARG_POINTER(charset);
NS_ENSURE_ARG_POINTER(inString);
NS_ENSURE_ARG_POINTER(outString);
*outString = nullptr;
if (NS_IsAscii(inString)) {
if (isAsciiOnly)
*isAsciiOnly = true;
*outString = ToNewCString(NS_LossyConvertUTF16toASCII(inString));
return (nullptr != *outString) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
if (isAsciiOnly)
*isAsciiOnly = false;
bool bTEXT_HTML = false;
nsresult res;
if (!PL_strcasecmp(contentType, TEXT_HTML)) {
bTEXT_HTML = true;
}
else if (PL_strcasecmp(contentType, TEXT_PLAIN)) {
return NS_ERROR_ILLEGAL_VALUE; // not supported type
}
nsCOMPtr <nsICharsetConverterManager> ccm =
do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &res);
NS_ENSURE_SUCCESS(res, res);
nsAutoCString charsetName;
res = ccm->GetCharsetAlias(charset, charsetName);
NS_ENSURE_SUCCESS(res, res);
nsCOMPtr <nsISaveAsCharset> conv = do_CreateInstance(NS_SAVEASCHARSET_CONTRACTID, &res);
NS_ENSURE_SUCCESS(res, res);
// First try to transliterate, if that fails use '?' for "bad" chars.
res = conv->Init(charsetName.get(),
nsISaveAsCharset::attr_FallbackQuestionMark +
nsISaveAsCharset::attr_EntityNone,
nsIEntityConverter::transliterate);
NS_ENSURE_SUCCESS(res, res);
const char16_t *input = inString;
// Convert to charset
res = conv->Convert(input, outString);
// If the converer cannot encode to the charset,
// then fallback to pref sepcified charsets.
if (NS_ERROR_UENC_NOMAPPING == res && !bTEXT_HTML && fallbackCharset) {
nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &res));
NS_ENSURE_SUCCESS(res, res);
nsAutoCString prefString("intl.fallbackCharsetList.");
prefString.Append(charset);
nsCString fallbackList;
res = prefBranch->GetCharPref(prefString.get(), getter_Copies(fallbackList));
// do the fallback only if there is a pref for the charset
if (NS_FAILED(res) || fallbackList.IsEmpty())
return NS_ERROR_UENC_NOMAPPING;
res = conv->Init(fallbackList.get(),
nsISaveAsCharset::attr_FallbackQuestionMark +
nsISaveAsCharset::attr_EntityAfterCharsetConv +
nsISaveAsCharset::attr_CharsetFallback,
nsIEntityConverter::transliterate);
NS_ENSURE_SUCCESS(res, res);
// free whatever we have now
PR_FREEIF(*outString);
res = conv->Convert(input, outString);
NS_ENSURE_SUCCESS(res, res);
// get the actual charset used for the conversion
if (NS_FAILED(conv->GetCharset(fallbackCharset)))
*fallbackCharset = nullptr;
}
// Exclude stateful charset which is 7 bit but not ASCII only.
else if (isAsciiOnly && *outString &&
!nsMsgI18Nstateful_charset(charsetName.get()))
*isAsciiOnly = NS_IsAscii(*outString);
return res;
}
示例11: NS_ASSERTION
// nsIStreamListener implementation
NS_IMETHODIMP
nsFTPDirListingConv::OnDataAvailable(nsIRequest* request, nsISupports *ctxt,
nsIInputStream *inStr, uint32_t sourceOffset, uint32_t count) {
NS_ASSERTION(request, "FTP dir listing stream converter needs a request");
nsresult rv;
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request, &rv);
NS_ENSURE_SUCCESS(rv, rv);
uint32_t read, streamLen;
uint64_t streamLen64;
rv = inStr->Available(&streamLen64);
NS_ENSURE_SUCCESS(rv, rv);
streamLen = (uint32_t)NS_MIN(streamLen64, uint64_t(PR_UINT32_MAX - 1));
nsAutoArrayPtr<char> buffer(new char[streamLen + 1]);
NS_ENSURE_TRUE(buffer, NS_ERROR_OUT_OF_MEMORY);
rv = inStr->Read(buffer, streamLen, &read);
NS_ENSURE_SUCCESS(rv, rv);
// the dir listings are ascii text, null terminate this sucker.
buffer[streamLen] = '\0';
PR_LOG(gFTPDirListConvLog, PR_LOG_DEBUG, ("nsFTPDirListingConv::OnData(request = %x, ctxt = %x, inStr = %x, sourceOffset = %d, count = %d)\n", request, ctxt, inStr, sourceOffset, count));
if (!mBuffer.IsEmpty()) {
// we have data left over from a previous OnDataAvailable() call.
// combine the buffers so we don't lose any data.
mBuffer.Append(buffer);
buffer = new char[mBuffer.Length()+1];
NS_ENSURE_TRUE(buffer, NS_ERROR_OUT_OF_MEMORY);
strncpy(buffer, mBuffer.get(), mBuffer.Length()+1);
mBuffer.Truncate();
}
#ifndef DEBUG_dougt
PR_LOG(gFTPDirListConvLog, PR_LOG_DEBUG, ("::OnData() received the following %d bytes...\n\n%s\n\n", streamLen, buffer.get()) );
#else
printf("::OnData() received the following %d bytes...\n\n%s\n\n", streamLen, buffer);
#endif // DEBUG_dougt
nsCAutoString indexFormat;
if (!mSentHeading) {
// build up the 300: line
nsCOMPtr<nsIURI> uri;
rv = channel->GetURI(getter_AddRefs(uri));
NS_ENSURE_SUCCESS(rv, rv);
rv = GetHeaders(indexFormat, uri);
NS_ENSURE_SUCCESS(rv, rv);
mSentHeading = true;
}
char *line = buffer;
line = DigestBufferLines(line, indexFormat);
#ifndef DEBUG_dougt
PR_LOG(gFTPDirListConvLog, PR_LOG_DEBUG, ("::OnData() sending the following %d bytes...\n\n%s\n\n",
indexFormat.Length(), indexFormat.get()) );
#else
char *unescData = ToNewCString(indexFormat);
NS_ENSURE_TRUE(unescData, NS_ERROR_OUT_OF_MEMORY);
nsUnescape(unescData);
printf("::OnData() sending the following %d bytes...\n\n%s\n\n", indexFormat.Length(), unescData);
nsMemory::Free(unescData);
#endif // DEBUG_dougt
// if there's any data left over, buffer it.
if (line && *line) {
mBuffer.Append(line);
PR_LOG(gFTPDirListConvLog, PR_LOG_DEBUG, ("::OnData() buffering the following %d bytes...\n\n%s\n\n",
PL_strlen(line), line) );
}
// send the converted data out.
nsCOMPtr<nsIInputStream> inputData;
rv = NS_NewCStringInputStream(getter_AddRefs(inputData), indexFormat);
NS_ENSURE_SUCCESS(rv, rv);
rv = mFinalListener->OnDataAvailable(request, ctxt, inputData, 0, indexFormat.Length());
return rv;
}
示例12: NS_ASSERTION
nsresult
nsFtpProtocolHandler::InsertConnection(nsIURI *aKey, nsFtpControlConnection *aConn)
{
NS_ASSERTION(aConn, "null pointer");
NS_ASSERTION(aKey, "null pointer");
if (aConn->mSessionId != mSessionId)
return NS_ERROR_FAILURE;
nsCAutoString spec;
aKey->GetPrePath(spec);
LOG(("FTP:inserting connection for %s\n", spec.get()));
nsresult rv;
nsCOMPtr<nsITimer> timer = do_CreateInstance("@mozilla.org/timer;1", &rv);
if (NS_FAILED(rv)) return rv;
timerStruct* ts = new timerStruct();
if (!ts)
return NS_ERROR_OUT_OF_MEMORY;
rv = timer->InitWithFuncCallback(nsFtpProtocolHandler::Timeout,
ts,
mIdleTimeout*1000,
nsITimer::TYPE_REPEATING_SLACK);
if (NS_FAILED(rv)) {
delete ts;
return rv;
}
ts->key = ToNewCString(spec);
if (!ts->key) {
delete ts;
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(aConn);
ts->conn = aConn;
ts->timer = timer;
//
// limit number of idle connections. if limit is reached, then prune
// eldest connection with matching key. if none matching, then prune
// eldest connection.
//
if (mRootConnectionList.Length() == IDLE_CONNECTION_LIMIT) {
PRUint32 i;
for (i=0;i<mRootConnectionList.Length();++i) {
timerStruct *candidate = mRootConnectionList[i];
if (strcmp(candidate->key, ts->key) == 0) {
mRootConnectionList.RemoveElementAt(i);
delete candidate;
break;
}
}
if (mRootConnectionList.Length() == IDLE_CONNECTION_LIMIT) {
timerStruct *eldest = mRootConnectionList[0];
mRootConnectionList.RemoveElementAt(0);
delete eldest;
}
}
mRootConnectionList.AppendElement(ts);
return NS_OK;
}
示例13: ToNewCString
/*
* Class: org_mozilla_webclient_impl_wrapper_0005fnative_CurrentPageImpl
* Method: nativeGetCurrentURL
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CurrentPageImpl_nativeGetCurrentURL
(JNIEnv *env, jobject obj, jint nativeBCPtr)
{
JNIEnv * pEnv = env;
jobject jobj = obj;
char * charResult = nsnull;
PRInt32 currentIndex;
jstring urlString = nsnull;
nsresult rv = NS_ERROR_NULL_POINTER;
NativeBrowserControl* nativeBrowserControl = (NativeBrowserControl *) nativeBCPtr;
if (nativeBrowserControl == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null nativeBCPtr passed to raptorWebShellGetURL");
return nsnull;
}
nsCOMPtr<nsISHistory> sHistory;
rv = nativeBrowserControl->mNavigation->GetSessionHistory(getter_AddRefs(sHistory));
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: Can't get SessionHistory");
return nsnull;
}
rv = sHistory->GetIndex(¤tIndex);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: Can't get current index from SessionHistory");
return nsnull;
}
nsIHistoryEntry * Entry;
nsIURI *URI;
rv = sHistory->GetEntryAtIndex(currentIndex, PR_FALSE, &Entry);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: Can't get history entry for current index");
return nsnull;
}
rv = Entry->GetURI(&URI);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: Can't get URI from History Entry");
return nsnull;
}
nsCString urlSpecString;
rv = URI->GetSpec(urlSpecString);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: Can't get url spec from URI");
return nsnull;
}
charResult = ToNewCString(urlSpecString);
if (charResult != nsnull) {
urlString = ::util_NewStringUTF(env, (const char *) charResult);
}
else {
::util_ThrowExceptionToJava(env, "raptorWebShellGetURL Exception: GetURL() returned NULL");
return nsnull;
}
nsMemory::Free(charResult);
return urlString;
}
示例14: sizeof
// contructor for CWAB object
//
// pszFileName - FileName of WAB file to open
// if no file name is specified, opens the default
//
CWAB::CWAB(nsILocalFile *file)
{
// Here we load the WAB Object and initialize it
m_pUniBuff = NULL;
m_uniBuffLen = 0;
m_bInitialized = PR_FALSE;
m_lpAdrBook = NULL;
m_lpWABObject = NULL;
m_hinstWAB = NULL;
{
TCHAR szWABDllPath[MAX_PATH];
DWORD dwType = 0;
ULONG cbData = sizeof(szWABDllPath);
HKEY hKey = NULL;
*szWABDllPath = '\0';
// First we look under the default WAB DLL path location in the
// Registry.
// WAB_DLL_PATH_KEY is defined in wabapi.h
//
if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, WAB_DLL_PATH_KEY, 0, KEY_READ, &hKey))
RegQueryValueEx( hKey, "", NULL, &dwType, (LPBYTE) szWABDllPath, &cbData);
if(hKey) RegCloseKey(hKey);
// if the Registry came up blank, we do a loadlibrary on the wab32.dll
// WAB_DLL_NAME is defined in wabapi.h
//
m_hinstWAB = LoadLibrary( (lstrlen(szWABDllPath)) ? szWABDllPath : WAB_DLL_NAME );
}
if(m_hinstWAB)
{
// if we loaded the dll, get the entry point
//
m_lpfnWABOpen = (LPWABOPEN) GetProcAddress(m_hinstWAB, "WABOpen");
if(m_lpfnWABOpen)
{
char fName[2] = {0, 0};
HRESULT hr = E_FAIL;
WAB_PARAM wp = {0};
wp.cbSize = sizeof(WAB_PARAM);
if (file != nsnull) {
nsCString path;
file->GetNativePath(path);
wp.szFileName = (LPTSTR) ToNewCString(path);
}
else
wp.szFileName = (LPTSTR) fName;
// if we choose not to pass in a WAB_PARAM object,
// the default WAB file will be opened up
//
hr = m_lpfnWABOpen(&m_lpAdrBook,&m_lpWABObject,&wp,0);
if(!hr)
m_bInitialized = TRUE;
}
}
}
示例15: do_GetWeakReference
void
nsXBLPrototypeHandler::ConstructPrototype(nsIContent* aKeyElement,
const PRUnichar* aEvent,
const PRUnichar* aPhase,
const PRUnichar* aAction,
const PRUnichar* aCommand,
const PRUnichar* aKeyCode,
const PRUnichar* aCharCode,
const PRUnichar* aModifiers,
const PRUnichar* aButton,
const PRUnichar* aClickCount,
const PRUnichar* aGroup,
const PRUnichar* aPreventDefault,
const PRUnichar* aAllowUntrusted)
{
mType = 0;
if (aKeyElement) {
mType |= NS_HANDLER_TYPE_XUL;
nsCOMPtr<nsIWeakReference> weak = do_GetWeakReference(aKeyElement);
if (!weak) {
return;
}
weak.swap(mHandlerElement);
}
else {
mType |= aCommand ? NS_HANDLER_TYPE_XBL_COMMAND : NS_HANDLER_TYPE_XBL_JS;
mHandlerText = nsnull;
}
mDetail = -1;
mMisc = 0;
mKeyMask = 0;
mPhase = NS_PHASE_BUBBLING;
if (aAction)
mHandlerText = ToNewUnicode(nsDependentString(aAction));
else if (aCommand)
mHandlerText = ToNewUnicode(nsDependentString(aCommand));
nsAutoString event(aEvent);
if (event.IsEmpty()) {
if (mType & NS_HANDLER_TYPE_XUL)
GetEventType(event);
if (event.IsEmpty())
return;
}
mEventName = do_GetAtom(event);
if (aPhase) {
const nsDependentString phase(aPhase);
if (phase.EqualsLiteral("capturing"))
mPhase = NS_PHASE_CAPTURING;
else if (phase.EqualsLiteral("target"))
mPhase = NS_PHASE_TARGET;
}
// Button and clickcount apply only to XBL handlers and don't apply to XUL key
// handlers.
if (aButton && *aButton)
mDetail = *aButton - '0';
if (aClickCount && *aClickCount)
mMisc = *aClickCount - '0';
// Modifiers are supported by both types of handlers (XUL and XBL).
nsAutoString modifiers(aModifiers);
if (mType & NS_HANDLER_TYPE_XUL)
aKeyElement->GetAttr(kNameSpaceID_None, nsGkAtoms::modifiers, modifiers);
if (!modifiers.IsEmpty()) {
mKeyMask = cAllModifiers;
char* str = ToNewCString(modifiers);
char* newStr;
char* token = nsCRT::strtok( str, ", \t", &newStr );
while( token != NULL ) {
if (PL_strcmp(token, "shift") == 0)
mKeyMask |= cShift | cShiftMask;
else if (PL_strcmp(token, "alt") == 0)
mKeyMask |= cAlt | cAltMask;
else if (PL_strcmp(token, "meta") == 0)
mKeyMask |= cMeta | cMetaMask;
else if (PL_strcmp(token, "control") == 0)
mKeyMask |= cControl | cControlMask;
else if (PL_strcmp(token, "accel") == 0)
mKeyMask |= KeyToMask(kAccelKey);
else if (PL_strcmp(token, "access") == 0)
mKeyMask |= KeyToMask(kMenuAccessKey);
else if (PL_strcmp(token, "any") == 0)
mKeyMask &= ~(mKeyMask << 4);
token = nsCRT::strtok( newStr, ", \t", &newStr );
}
nsMemory::Free(str);
}
nsAutoString key(aCharCode);
if (key.IsEmpty()) {
//.........这里部分代码省略.........