open-source-search-engine/DataFeed.h

147 lines
3.4 KiB
C
Raw Normal View History

2013-08-03 00:12:24 +04:00
// Gigablast, copyright Dec 2004
// Author: Javier Olivares
//
// . Contains Data Feed information for customers
// Has passcode and pricing table for this feed
#ifndef _DATAFEED_H_
#define _DATAFEED_H_
#include "MetaContainer.h"
//#include "Customer.h"
//#include "CollectionRec.h" // for MAX_PRICE
2013-08-03 00:12:24 +04:00
#define DATAFEEDCOUNT_REQUESTS 1
#define DATAFEEDCOUNT_CURRENTBILL 2
#define MAX_USERNAMELEN 48
#define MAX_DATAFEEDPAGELEN (32*1024)
#define MAX_PASSCODELEN 8
#define MAX_PRICE_TIERS 6
#define MAX_PRICE_RESULTLEVELS 16
#define MAX_PRICE_LEVELCOSTS (MAX_PRICE_TIERS*MAX_PRICE_RESULTLEVELS*2)
class PriceTable {
public:
PriceTable() {
m_numTiers = 0;
m_numResultLevels = 0;
m_monthlyFee = 0;
}
~PriceTable() {
}
void reset ( ) {
m_numTiers = 0;
m_numResultLevels = 0;
m_monthlyFee = 0;
}
// . Get the cost of this query (in micro cents)
// given the total number of requests made for
// this feed this month and the number of results
// requested.
2014-11-11 01:45:11 +03:00
int32_t getCost ( uint32_t totalRequests,
uint32_t numResults,
2013-08-03 00:12:24 +04:00
bool hasGigabits ) {
if (m_numTiers == 0 || m_numResultLevels == 0)
return 0;
// get the tier
2014-11-11 01:45:11 +03:00
int32_t tier;
2013-08-03 00:12:24 +04:00
for (tier = 0; tier < m_numTiers-1; tier++)
if (totalRequests <= m_tierMax[tier])
break;
// get the level
2014-11-11 01:45:11 +03:00
int32_t level;
2013-08-03 00:12:24 +04:00
for (level = 0; level < m_numResultLevels-1; level++)
if (numResults <= m_resultLevels[level])
break;
// return the cost
if (hasGigabits)
return m_levelCosts[ (tier * (m_numResultLevels*2))
+ (level*2+1) ];
else
return m_levelCosts[ (tier * (m_numResultLevels*2))
+ (level*2) ];
}
2014-11-11 01:45:11 +03:00
int32_t getIndex ( uint32_t numResults,
2013-08-03 00:12:24 +04:00
bool hasGigabits ) {
// Check if we have result levels
if (m_numResultLevels == 0) return 0;
// Find the result level the query meets
2014-11-11 01:45:11 +03:00
int32_t i;
2013-08-03 00:12:24 +04:00
for(i = 0; i < m_numResultLevels-1; i++)
if(numResults <= m_resultLevels[i])
break;
// Calculate any other changes to index
2014-11-11 01:45:11 +03:00
int32_t opt = 0;
2013-08-03 00:12:24 +04:00
if(hasGigabits) opt |= 1;
// Return the proper Countdb index
return (m_resultLevels[i]/10 | opt);
}
/*
// clone the price table
void clone ( PriceTable *pt ) {
m_numTiers = pt->m_numTiers;
m_numResultLevels = pt->m_numResultLevels;
m_monthlyFee = pt->m_monthlyFee;
gbmemcpy(m_tierMax, pt->m_tierMax, sizeof(int32_t)*m_numTiers);
gbmemcpy(m_resultLevels, pt->m_resultLevels, sizeof(int32_t)*m_numResultLevels);
2014-11-11 01:45:11 +03:00
int32_t numCosts = m_numTiers*m_numResultLevels*2;
gbmemcpy(m_levelCosts, pt->m_levelCosts, sizeof(int32_t)*numCosts);
2013-08-03 00:12:24 +04:00
}
*/
// locals
2014-11-11 01:45:11 +03:00
int32_t m_numTiers;
uint32_t m_tierMax[MAX_PRICE_TIERS];
int32_t m_numResultLevels;
uint32_t m_resultLevels[MAX_PRICE_RESULTLEVELS];
uint32_t m_levelCosts[MAX_PRICE_LEVELCOSTS];
int32_t m_monthlyFee;
2013-08-03 00:12:24 +04:00
};
class DataFeed : public MetaContainer {
public:
DataFeed();
~DataFeed();
void setUrl ( char *name,
2014-11-11 01:45:11 +03:00
int32_t nameLen );
2013-08-03 00:12:24 +04:00
2014-11-11 01:45:11 +03:00
void set ( int32_t creationTime,
2013-08-03 00:12:24 +04:00
char *dataFeedUrl,
2014-11-11 01:45:11 +03:00
int32_t dataFeedUrlLen,
2013-08-03 00:12:24 +04:00
char *passcode,
2014-11-11 01:45:11 +03:00
int32_t passcodeLen,
2013-08-03 00:12:24 +04:00
bool isActive,
bool isLocked = false );
void parse ( char *dataFeedPage,
2014-11-11 01:45:11 +03:00
int32_t dataFeedPageLen );
2013-08-03 00:12:24 +04:00
2014-11-11 01:45:11 +03:00
int32_t buildPage ( char *page );
2013-08-03 00:12:24 +04:00
void buildPage ( SafeBuf *sb );
// locals
char m_passcode[MAX_PASSCODELEN+1];
2014-11-11 01:45:11 +03:00
int32_t m_passcodeLen;
2013-08-03 00:12:24 +04:00
bool m_isActive;
bool m_isLocked;
// ID
2014-10-30 22:36:39 +03:00
int64_t m_customerId;
2013-08-03 00:12:24 +04:00
// Price Table
PriceTable m_priceTable;
// creation time
2014-11-11 01:45:11 +03:00
int32_t m_creationTime;
2013-08-03 00:12:24 +04:00
};
#endif