Esempio n. 1
0
void DatabaseManager::deleteRecordRange(const StringPimpl &key,
										const StringPimpl &range)
{
	Dbc *cursor = NULL;

	try 
	{
		Dbt dbKey((void *)key.c_str(), key.size() + 1);
		Dbt dbData((void *) range.c_str(), range.size() + 1);

		m_pimpl->checkTSSInit();
		m_pimpl->m_database->cursor(&(**m_pimpl->m_transaction), &cursor, m_pimpl->m_cursorFlags);
		int ret = cursor->get(&dbKey, &dbData, DB_GET_BOTH_RANGE);
		
		while(ret != DB_NOTFOUND)
		{
			cursor->del(0);
			ret = cursor->get(&dbKey, &dbData, DB_NEXT);
		}
		cursor->close();
	}
	catch (DbException &e) 
	{
            std::cerr << "Error in addRecord: "
                       << e.what() << e.get_errno() << std::endl;
			if(cursor != NULL)
			{
				cursor->close();
			}
    }
}
Esempio n. 2
0
bool DatabaseManager::recordRangeExists(const StringPimpl &key)
{
	//Go through the range of the existence keys and 
	//add them to the list
	Dbc *cursor = NULL;
	try 
	{
		Dbt dbKey((void *)key.c_str(), key.size() + 1);
		Dbt dbData;

		m_pimpl->checkTSSInit();
		m_pimpl->m_database->cursor(&(**m_pimpl->m_transaction), &cursor, m_pimpl->m_cursorFlags);
		int ret = cursor->get(&dbKey, &dbData, DB_SET_RANGE);
		while(ret != DB_NOTFOUND)
		{
			StringPimpl dataString = StringPimpl((char *) dbData.get_data());
			StringPimpl keyString = StringPimpl((char *) dbKey.get_data());
			if(!keyString.startsWith(key) || keyString == key) {
				//We are at the end of the range
				break;
			}
			else 
			{
				cursor->close();
				return true;
			}
		}
		cursor->close();
		return false;
	}
	catch (DbException &e) 
	{
		std::cerr << "Error in deleteRecordRange: "
				   << e.what() << e.get_errno() << std::endl;
		if(cursor != NULL)
		{
			cursor->close();
		}
		return false;
	}
}
NS_IMETHODIMP 
nsCRLManager::UpdateCRLFromURL( const PRUnichar *url, const PRUnichar* key, bool *res)
{
  nsresult rv;
  nsAutoString downloadUrl(url);
  nsAutoString dbKey(key);
  nsCOMPtr<nsINSSComponent> nssComponent(do_GetService(kNSSComponentCID, &rv));
  if(NS_FAILED(rv)){
    *res = false;
    return rv;
  }

  rv = nssComponent->DownloadCRLDirectly(downloadUrl, dbKey);
  if(NS_FAILED(rv)){
    *res = false;
  } else {
    *res = true;
  }
  return NS_OK;

}
Esempio n. 4
0
void DatabaseManager::deleteRecordRange(const StringPimpl &key)
{
	Dbc *cursor = NULL;

	try 
	{
		Dbt dbKey((void *)key.c_str(), key.size() + 1);
		Dbt dbData;

		m_pimpl->checkTSSInit();
		m_pimpl->m_database->cursor(&(**m_pimpl->m_transaction), &cursor, m_pimpl->m_cursorFlags);
		int ret = cursor->get(&dbKey, &dbData, DB_SET_RANGE);
		
		while(ret != DB_NOTFOUND)
		{
			StringPimpl dataString = StringPimpl((char *) dbData.get_data());
			StringPimpl keyString = StringPimpl((char *) dbKey.get_data());
			if(!keyString.startsWith(key)) {
				//We are at the end of the range
				break;
			} 
			cursor->del(0);
			ret = cursor->get(&dbKey, &dbData, DB_NEXT);
		}
		cursor->close();
	}
	catch (DbException &e) 
	{
        std::cerr << "Error in deleteRecordRange: "
                   << e.what() << e.get_errno() << std::endl;
		if(cursor != NULL)
		{
			cursor->close();
		}
    }
}