示例#1
0
/* parses LocalMessageURI
 * mailbox-message://folder1/folder2#123?header=none or
 * mailbox-message://folder1/folder2#1234&part=1.2
 *
 * puts folder URI in folderURI (mailbox://folder1/folder2)
 * message key number in key
 */
nsresult nsParseLocalMessageURI(const char* uri,
                                nsCString& folderURI,
                                PRUint32 *key)
{
  if(!key)
    return NS_ERROR_NULL_POINTER;

  nsCAutoString uriStr(uri);
  PRInt32 keySeparator = uriStr.FindChar('#');
  if(keySeparator != -1)
  {
    PRInt32 keyEndSeparator = MsgFindCharInSet(uriStr, "?&", keySeparator);
    folderURI = StringHead(uriStr, keySeparator);
    folderURI.Cut(7, 8);    // cut out the -message part of mailbox-message:

    nsCAutoString keyStr;
    if (keyEndSeparator != -1)
      keyStr = Substring(uriStr, keySeparator + 1,
                         keyEndSeparator - (keySeparator + 1));
    else
      keyStr = StringTail(uriStr, uriStr.Length() - (keySeparator + 1));

    *key = (PRUint32) ParseUint64Str(keyStr.get());
    return NS_OK;
  }
  return NS_ERROR_FAILURE;

}
/* parses NewsMessageURI */
nsresult
nsParseNewsMessageURI(const char* uri, nsCString& folderURI, PRUint32 *key)
{
    NS_ENSURE_ARG_POINTER(uri);
    NS_ENSURE_ARG_POINTER(key);

  nsCAutoString uriStr(uri);
  PRInt32 keySeparator = uriStr.FindChar('#');
  if(keySeparator != -1)
  {
    PRInt32 keyEndSeparator = uriStr.FindCharInSet("?&",
                                                   keySeparator);

    uriStr.Left(folderURI, keySeparator);
        folderURI.Cut(4, 8);    // cut out the -message part of news-message:

    nsCAutoString keyStr;
    if (keyEndSeparator != -1)
        uriStr.Mid(keyStr, keySeparator+1,
                   keyEndSeparator-(keySeparator+1));
    else
        uriStr.Right(keyStr, uriStr.Length() - (keySeparator + 1));
    PRInt32 errorCode;
    *key = keyStr.ToInteger(&errorCode);

    return errorCode;
  }
  return NS_ERROR_FAILURE;
}
示例#3
0
/* parses ImapMessageURI */
nsresult nsParseImapMessageURI(const char* uri, nsCString& folderURI, PRUint32 *key, char **part)
{
    if(!key)
        return NS_ERROR_NULL_POINTER;

    nsCAutoString uriStr(uri);
    PRInt32 folderEnd = -1;
    // imap-message uri's can have imap:// url strings tacked on the end,
    // e.g., when opening/saving attachments. We don't want to look for '#'
    // in that part of the uri, if the attachment name contains '#',
    // so check for that here.
    if (StringBeginsWith(uriStr, NS_LITERAL_CSTRING("imap-message")))
        folderEnd = uriStr.Find("imap://");

    PRInt32 keySeparator = MsgRFindChar(uriStr, '#', folderEnd);
    if(keySeparator != -1)
    {
        PRInt32 keyEndSeparator = MsgFindCharInSet(uriStr, "/?&", keySeparator);
        nsAutoString folderPath;
        folderURI = StringHead(uriStr, keySeparator);
        folderURI.Cut(4, 8); // cut out the _message part of imap-message:
        // folder uri's don't have fully escaped usernames.
        PRInt32 atPos = folderURI.FindChar('@');
        if (atPos != -1)
        {
            nsCString unescapedName, escapedName;
            PRInt32 userNamePos = folderURI.Find("//") + 2;
            PRUint32 origUserNameLen = atPos - userNamePos;
            if (NS_SUCCEEDED(MsgUnescapeString(Substring(folderURI, userNamePos,
                                               origUserNameLen),
                                               0, unescapedName)))
            {
                // Re-escape the username, matching the way we do it in uris, not the
                // way necko escapes urls. See nsMsgIncomingServer::GetServerURI.
                MsgEscapeString(unescapedName, nsINetUtil::ESCAPE_XALPHAS, escapedName);
                folderURI.Replace(userNamePos, origUserNameLen, escapedName);
            }
        }
        nsCAutoString keyStr;
        if (keyEndSeparator != -1)
            keyStr = Substring(uriStr, keySeparator + 1, keyEndSeparator - (keySeparator + 1));
        else
            keyStr = Substring(uriStr, keySeparator + 1);

        *key = strtoul(keyStr.get(), nsnull, 10);

        if (part && keyEndSeparator != -1)
        {
            PRInt32 partPos = MsgFind(uriStr, "part=", PR_FALSE, keyEndSeparator);
            if (partPos != -1)
            {
                *part = ToNewCString(Substring(uriStr, keyEndSeparator));
            }
        }
    }
    return NS_OK;
}
示例#4
0
/// FIXME: this should not use _uri, but rather take a URL argument.
/// Validation should probably be done on connect() only and return a 
/// bool indicating validity. That can be used to return a failure
/// for invalid or blocked URLs.
std::string
NetConnection_as::validateURL() const
{

    URL uri(_uri, getRunResources(owner()).baseURL());

    std::string uriStr(uri.str());
    assert(uriStr.find("://") != std::string::npos);

    // Check if we're allowed to open url
    if (!URLAccessManager::allow(uri)) {
        log_security(_("Gnash is not allowed to open this url: %s"), uriStr);
        return "";
    }

    log_debug(_("Connection to movie: %s"), uriStr);

    return uriStr;
}
/* void CreateDelegate (in nsIRDFResource aOuter, in string aKey, in nsIIDRef aIID, [iid_is (aIID), retval] out nsQIResult aResult); */
NS_IMETHODIMP nsMsgFilterDelegateFactory::CreateDelegate(nsIRDFResource *aOuter, const char *aKey, const nsIID & aIID, void * *aResult)
{
    nsresult rv;
    *aResult = nsnull;
    
    // if it's a folder, then we return a filter list..
    // otherwise make sure it's in the form
    // mailbox://userid@server/foldername;filterName=foo
    

    const char* uri;
    aOuter->GetValueConst(&uri);

    // if it has ';filter' then it's a filter, otherwise we'll assume
    // that it's a folder.
    nsCAutoString uriStr(uri);

    nsCOMPtr<nsISupports> resultSupports;
    
    if (uriStr.Find("filterName=") != -1) {
        nsCOMPtr<nsIMsgFilter> filter;
        rv = getFilterDelegate(aOuter, getter_AddRefs(filter));
        if (NS_SUCCEEDED(rv))
            resultSupports = filter;
        
    }
    else {
        // probably a folder, get the filter list
        nsCOMPtr<nsIMsgFilterList> filterList;
        rv = getFilterListDelegate(aOuter, getter_AddRefs(filterList));
        if (NS_SUCCEEDED(rv))
            resultSupports = filterList;
        
    }

    if (resultSupports)
        return resultSupports->QueryInterface(aIID, aResult);

    return NS_ERROR_FAILURE;
}
/* parses ImapMessageURI */
nsresult nsParseImapMessageURI(const char* uri, nsCString& folderURI, PRUint32 *key, char **part)
{
  if(!key)
    return NS_ERROR_NULL_POINTER;
  
  nsCAutoString uriStr(uri);
  PRInt32 keySeparator = uriStr.RFindChar('#');
  if(keySeparator != -1)
  {
    PRInt32 keyEndSeparator = uriStr.FindCharInSet("/?&", 
      keySeparator); 
    nsAutoString folderPath;
    uriStr.Left(folderURI, keySeparator);
    folderURI.Cut(4, 8);	// cut out the _message part of imap-message:
    nsCAutoString keyStr;
    if (keyEndSeparator != -1)
      uriStr.Mid(keyStr, keySeparator+1, 
      keyEndSeparator-(keySeparator+1));
    else
      uriStr.Right(keyStr, uriStr.Length() - (keySeparator + 1));
    PRInt32 errorCode;
    *key = keyStr.ToInteger(&errorCode);
    
    if (part && keyEndSeparator != -1)
    {
      PRInt32 partPos = uriStr.Find("part=", PR_FALSE, keyEndSeparator);
      if (partPos != -1)
      {
        nsCString partSubStr;
        uriStr.Right(partSubStr, uriStr.Length() - keyEndSeparator);
        *part = ToNewCString(partSubStr);
        
      }
    }
  }
  return NS_OK;
  
}
/* parses NewsMessageURI */
nsresult
nsParseNewsMessageURI(const char* uri, nsCString& group, nsMsgKey *key)
{
  NS_ENSURE_ARG_POINTER(uri);
  NS_ENSURE_ARG_POINTER(key);

  nsAutoCString uriStr(uri);
  int32_t keySeparator = uriStr.FindChar('#');
  if(keySeparator != -1)
  {
    int32_t keyEndSeparator = MsgFindCharInSet(uriStr, "?&", keySeparator);

    // Grab between the last '/' and the '#' for the key
    group = StringHead(uriStr, keySeparator);
    int32_t groupSeparator = group.RFind("/");
    if (groupSeparator == -1)
      return NS_ERROR_FAILURE;

    // Our string APIs don't let us unescape into the same buffer from earlier,
    // so escape into a temporary
    nsAutoCString unescapedGroup;
    MsgUnescapeString(Substring(group, groupSeparator + 1), 0, unescapedGroup);
    group = unescapedGroup;

    nsAutoCString keyStr;
    if (keyEndSeparator != -1)
      keyStr = Substring(uriStr, keySeparator + 1, keyEndSeparator - (keySeparator + 1));
    else
      keyStr = Substring(uriStr, keySeparator + 1);
    nsresult errorCode;
    *key = keyStr.ToInteger(&errorCode);

    return errorCode;
  }
  return NS_ERROR_FAILURE;
}