Ejemplo n.º 1
0
nsresult
nsDOMStorage::GetItem(const nsACString& aKey, nsACString &aData)
{
  nsresult rv;

  // IMPORTANT:
  // CacheStoragePermissions() is called inside of
  // GetItem(nsACString, nsIDOMStorageItem)
  // To call it particularly in this method would just duplicate
  // the call. If the code changes, make sure that call to
  // CacheStoragePermissions() is put here!

  nsCOMPtr<nsIDOMStorageItem> item;
  rv = GetItem(aKey, getter_AddRefs(item));
  if (NS_FAILED(rv))
    return rv;

  if (item) {
    nsDOMStorageItem* itemConcrete = static_cast<nsDOMStorageItem*>(item.get());
    rv = itemConcrete->GetValueNoConvert(aData);
    NS_ENSURE_SUCCESS(rv, rv);
  }
  else
    aData.SetIsVoid(true);

  return NS_OK;
}
NS_IMETHODIMP
calIcalProperty::GetParameter(const nsACString &param, nsACString &value)
{
    // More ridiculous parameter/X-PARAMETER handling.
    icalparameter_kind paramkind =
        icalparameter_string_to_kind(PromiseFlatCString(param).get());

    if (paramkind == ICAL_NO_PARAMETER)
        return NS_ERROR_INVALID_ARG;

    const char *icalstr = nullptr;
    if (paramkind == ICAL_X_PARAMETER) {
        icalparameter *icalparam = FindParameter(mProperty, param, ICAL_X_PARAMETER);
        if (icalparam)
            icalstr = icalparameter_get_xvalue(icalparam);
    } else if (paramkind == ICAL_IANA_PARAMETER) {
        icalparameter *icalparam = FindParameter(mProperty, param, ICAL_IANA_PARAMETER);
        if (icalparam)
            icalstr = icalparameter_get_iana_value(icalparam);
    } else {
        icalstr = icalproperty_get_parameter_as_string(mProperty,
                                                       PromiseFlatCString(param).get());
    }

    if (!icalstr) {
        value.Truncate();
        value.SetIsVoid(true);
    } else {
        value.Assign(icalstr);
    }
    return NS_OK;
}
Ejemplo n.º 3
0
nsresult
BlobImplBase::GetSendInfo(nsIInputStream** aBody, uint64_t* aContentLength,
                          nsACString& aContentType, nsACString& aCharset)
{
  MOZ_ASSERT(aContentLength);

  ErrorResult rv;

  nsCOMPtr<nsIInputStream> stream;
  GetInternalStream(getter_AddRefs(stream), rv);
  if (NS_WARN_IF(rv.Failed())) {
    return rv.StealNSResult();
  }

  *aContentLength = GetSize(rv);
  if (NS_WARN_IF(rv.Failed())) {
    return rv.StealNSResult();
  }

  nsAutoString contentType;
  GetType(contentType);

  if (contentType.IsEmpty()) {
    aContentType.SetIsVoid(true);
  } else {
    CopyUTF16toUTF8(contentType, aContentType);
  }

  aCharset.Truncate();

  stream.forget(aBody);
  return NS_OK;
}
Ejemplo n.º 4
0
nsresult
DOMStorageImpl::GetDBValue(const nsACString& aKey, nsACString& aValue,
                           bool* aSecure)
{
  aValue.Truncate();

  if (!UseDB())
    return NS_OK;

  nsresult rv = InitDB();
  NS_ENSURE_SUCCESS(rv, rv);

  nsAutoCString value;
  rv = gStorageDB->GetKeyValue(this, aKey, value, aSecure);

  if (rv == NS_ERROR_DOM_NOT_FOUND_ERR) {
    aValue.SetIsVoid(true);
  }

  if (NS_FAILED(rv))
    return rv;

  aValue.Assign(value);

  return NS_OK;
}
Ejemplo n.º 5
0
NS_IMETHODIMP
jxMySQL50Statement::GetUTF8String(PRUint32 aIndex, nsACString &_retval)
{
    if (mConnection == nsnull)
    {
        SET_ERROR_RETURN (JX_MYSQL50_ERROR_NOT_CONNECTED);
    }

    if (mSTMT == nsnull)
    {
        SET_ERROR_RETURN (JX_MYSQL50_ERROR_STMT_NULL);
    }

    if (aIndex < 0 || aIndex >= mOut.mCount)
    {
        SET_ERROR_RETURN (JX_MYSQL50_ERROR_ILLEGAL_VALUE);
    }
    
    if (mOut.mBindArrayIsNull[aIndex]) {
        // null columns get IsVoid set to distinguish them from empty strings
        _retval.Truncate(0);
        _retval.SetIsVoid(PR_TRUE);
    } else {
        PRUint32 slen = mOut.mBindArrayBufferTYPE_STRING_LEN_OUT[aIndex];
        const char* cstr = mOut.mBindArrayBufferTYPE_STRING[aIndex];
        _retval.Assign(cstr, slen);
    }

    
    return NS_OK;
}
Ejemplo n.º 6
0
NS_IMETHODIMP
jxMySQL50Statement::GetUTF8Text(PRUint32 aIndex, nsACString &aData)
{
    if (mConnection == nsnull)
    {
        SET_ERROR_RETURN (JX_MYSQL50_ERROR_NOT_CONNECTED);
    }

    if (mSTMT == nsnull)
    {
        SET_ERROR_RETURN (JX_MYSQL50_ERROR_STMT_NULL);
    }

    if (aIndex < 0 || aIndex >= mOut.mCount)
    {
        SET_ERROR_RETURN (JX_MYSQL50_ERROR_ILLEGAL_VALUE);
    }
    
    if (mOut.mBindArrayIsNull[aIndex]) {
        // null columns get IsVoid set to distinguish them from empty strings
        aData.Truncate(0);
        aData.SetIsVoid(PR_TRUE);
    }else
    {
        int nsize = mOut.mBindArrayBufferTYPE_STRING_LEN_OUT[aIndex];

        char *data = static_cast<char*>(nsMemory::Alloc(nsize+1));
        //extra for the null
        if (data == NULL)
        {
            SET_ERROR_RETURN (JX_MYSQL50_ERROR_OUT_OF_MEMORY);
        }

        my_bool is_null;
        my_bool error;
        unsigned long length;
    
        MYSQL_BIND bind;
        memset(&bind, 0, sizeof(bind));

        bind.buffer= (void*)data;
        bind.buffer_length= nsize;
        bind.buffer_type = MYSQL_TYPE_STRING;
        bind.is_null= &is_null;
        bind.length= &length;
        bind.error= &error;

        if (mysql_stmt_fetch_column(mSTMT, &bind, aIndex, 0))
        {
            SET_ERROR_RETURN (JX_MYSQL50_MYSQL_ERROR);
        }

        data[nsize] = 0;

        aData = nsDependentCString(data, nsize);
    }

    return NS_OK;
}
Ejemplo n.º 7
0
static void
ConvertString(const nsAString& aUTF16String, nsACString& aUTF8String)
{
  if (aUTF16String.IsVoid()) {
    aUTF8String.SetIsVoid(true);
  } else {
    CopyUTF16toUTF8(aUTF16String, aUTF8String);
  }
}
nsresult calIcalComponent::GetStringProperty(icalproperty_kind kind, nsACString &str)
{
    icalproperty *prop = icalcomponent_get_first_property(mComponent, kind);
    if (!prop) {
        str.Truncate();
        str.SetIsVoid(true);
    } else {
        str.Assign(icalvalue_get_string(icalproperty_get_value(prop)));
    }
    return NS_OK;
}
Ejemplo n.º 9
0
NS_IMETHODIMP
nsPKCS11Module::GetLibName(/*out*/ nsACString& libName)
{
  nsNSSShutDownPreventionLock locker;
  if (isAlreadyShutDown())
    return NS_ERROR_NOT_AVAILABLE;

  if (mModule->dllName) {
    libName = mModule->dllName;
  } else {
    libName.SetIsVoid(true);
  }
  return NS_OK;
}
Ejemplo n.º 10
0
NS_IMETHODIMP
ArgValueArray::GetUTF8String(uint32_t aIndex,
                             nsACString &_value)
{
  ENSURE_INDEX_VALUE(aIndex, mArgc);

  if (::sqlite3_value_type(mArgv[aIndex]) == SQLITE_NULL) {
    // NULL columns should have IsVoid set to distinguish them from an empty
    // string.
    _value.Truncate(0);
    _value.SetIsVoid(true);
  }
  else {
    _value.Assign(reinterpret_cast<const char *>(::sqlite3_value_text(mArgv[aIndex])),
                  ::sqlite3_value_bytes(mArgv[aIndex]));
  }
  return NS_OK;
}
Ejemplo n.º 11
0
static nsresult
GetBufferDataAsStream(const uint8_t* aData, uint32_t aDataLength,
                      nsIInputStream** aResult, uint64_t* aContentLength,
                      nsACString& aContentType, nsACString& aCharset)
{
  aContentType.SetIsVoid(true);
  aCharset.Truncate();

  *aContentLength = aDataLength;
  const char* data = reinterpret_cast<const char*>(aData);

  nsCOMPtr<nsIInputStream> stream;
  nsresult rv = NS_NewByteInputStream(getter_AddRefs(stream), data, aDataLength,
                                      NS_ASSIGNMENT_COPY);
  NS_ENSURE_SUCCESS(rv, rv);

  stream.forget(aResult);

  return NS_OK;
}
Ejemplo n.º 12
0
NS_IMETHODIMP
calIcalProperty::GetValue(nsACString &str)
{
    icalvalue *value = icalproperty_get_value(mProperty);
    icalvalue_kind valuekind = icalvalue_isa(value);

    const char *icalstr;
    if (valuekind == ICAL_TEXT_VALUE) {
        icalstr = icalvalue_get_text(value);
    } else if (valuekind == ICAL_X_VALUE) {
        icalstr = icalvalue_get_x(value);
    } else if (valuekind == ICAL_ATTACH_VALUE) {
        icalattach *attach = icalvalue_get_attach(value);
        if (icalattach_get_is_url(attach)) {
            icalstr = icalattach_get_url(attach);
        } else {
            icalstr = (const char *)icalattach_get_data(attach);
        }
    } else {
        icalstr = icalproperty_get_value_as_string(mProperty);
    }

    if (!icalstr) {
        if (icalerrno == ICAL_BADARG_ERROR) {
            str.Truncate();
            // Set string to null, because we don't have a value
            // (which is something different then an empty value)
            str.SetIsVoid(true);
            return NS_OK;
        }

#ifdef DEBUG
        fprintf(stderr, "Error getting string value: %d (%s)\n",
                icalerrno, icalerror_strerror(icalerrno));
#endif
        return NS_ERROR_FAILURE;
    }

    str.Assign(icalstr);
    return NS_OK;
}
NS_IMETHODIMP
Statement::GetUTF8String(uint32_t aIndex,
                         nsACString &_value)
{
  // Get type of Index will check aIndex for us, so we don't have to.
  int32_t type;
  nsresult rv = GetTypeOfIndex(aIndex, &type);
  NS_ENSURE_SUCCESS(rv, rv);
  if (type == mozIStorageStatement::VALUE_TYPE_NULL) {
    // NULL columns should have IsVoid set to distinguish them from the empty
    // string.
    _value.Truncate(0);
    _value.SetIsVoid(true);
  }
  else {
    const char *value =
      reinterpret_cast<const char *>(::sqlite3_column_text(mDBStatement,
                                                           aIndex));
    _value.Assign(value, ::sqlite3_column_bytes(mDBStatement, aIndex));
  }
  return NS_OK;
}
Ejemplo n.º 14
0
NS_IMETHODIMP
nsPKCS11Slot::GetTokenName(/*out*/ nsACString& tokenName)
{
  nsNSSShutDownPreventionLock locker;
  if (isAlreadyShutDown())
    return NS_ERROR_NOT_AVAILABLE;

  if (!PK11_IsPresent(mSlot.get())) {
    tokenName.SetIsVoid(true);
    return NS_OK;
  }

  if (PK11_GetSlotSeries(mSlot.get()) != mSeries) {
    nsresult rv = refreshSlotInfo(locker);
    if (NS_FAILED(rv)) {
      return rv;
    }
  }

  tokenName = PK11_GetTokenName(mSlot.get());
  return NS_OK;
}
Ejemplo n.º 15
0
NS_IMETHODIMP
calIcalProperty::GetValueAsIcalString(nsACString &str)
{
    const char *icalstr = icalproperty_get_value_as_string(mProperty);
    if (!icalstr) {
        if (icalerrno == ICAL_BADARG_ERROR) {
            str.Truncate();
            // Set string to null, because we don't have a value
            // (which is something different then an empty value)
            str.SetIsVoid(true);
            return NS_OK;
        }

#ifdef DEBUG
        fprintf(stderr, "Error getting string value: %d (%s)\n",
                icalerrno, icalerror_strerror(icalerrno));
#endif
        return NS_ERROR_FAILURE;
    }

    str.Assign(icalstr);
    return NS_OK;
}
Ejemplo n.º 16
0
static nsresult
FillParameterName(icalparameter *icalparam, nsACString &name)
{
    const char *propname = nullptr;
    if (icalparam) {
        icalparameter_kind paramkind = icalparameter_isa(icalparam);
        if (paramkind == ICAL_X_PARAMETER)
            propname = icalparameter_get_xname(icalparam);
        else if (paramkind == ICAL_IANA_PARAMETER)
            propname = icalparameter_get_iana_name(icalparam);
        else if (paramkind != ICAL_NO_PARAMETER)
            propname = icalparameter_kind_to_string(paramkind);
    }

    if (propname) {
        name.Assign(propname);
    } else {
        name.Truncate();
        name.SetIsVoid(true);
    }

    return NS_OK;
}
Ejemplo n.º 17
0
nsresult
DOMStorageImpl::GetKey(bool aCallerSecure, uint32_t aIndex, nsACString& aKey)
{
  // XXX: This does a linear search for the key at index, which would
  // suck if there's a large numer of indexes. Do we care? If so,
  // maybe we need to have a lazily populated key array here or
  // something?

  if (UseDB()) {
    CacheKeysFromDB();
  }

  IndexFinderData data(aCallerSecure, aIndex);
  mItems.EnumerateEntries(IndexFinder, &data);

  if (!data.mItem) {
    // aIndex was larger than the number of accessible keys. Return null.
    aKey.SetIsVoid(true);
    return NS_OK;
  }

  aKey = data.mItem->GetKey();
  return NS_OK;
}
Ejemplo n.º 18
0
NS_IMETHODIMP
calTimezone::GetLongitude(nsACString & _retval) {
    _retval.SetIsVoid(true);
    return NS_OK;
}
Ejemplo n.º 19
0
NS_CStringSetIsVoid(nsACString& aStr, const bool aIsVoid)
{
  aStr.SetIsVoid(aIsVoid);
}