remove more crud

git-svn-id: svn+ssh://svn.corp.yahoo.com/yahoo/yrl/labs/pnuts/code/logstore@525 8dad8b1f-cf64-0410-95b6-bcf113ffbcfe
This commit is contained in:
sears 2010-01-26 00:54:38 +00:00
parent b820aaa3fb
commit 2fcfafb589
2 changed files with 0 additions and 510 deletions

165
FwCode.h
View file

@ -1,165 +0,0 @@
/* Copyright (C) 2008 Yahoo! Inc. All Rights Reserved. */
#ifndef __FW_CODE__H
#define __FW_CODE__H
#include <string>
/**
* Global framework response codes.
*/
class FwCode {
public:
typedef int ResponseCode;
static const std::string unknownCodeStr;
/**
* The convention here is to keep related codes grouped together, so
* that it is easier to find all existing codes for a particular
* module. Each section is given a range of 50 codes, so that adding
* a new code to an existing section won't invalidate all of the codes
* following it in the enum (causing binary incompatibility).
*/
//----------- Generic section -------------
static const ResponseCode FwOk = 0; //!< All successes
static const ResponseCode FwError = 1; //!< General error code
static const ResponseCode FwCrit = 2; //!< General critical error. could be originated by low level library to indicate some nasty error has occurred.
static const ResponseCode MdbmOpenFailed = 3; //!< Any kind of mdbm open failure
static const ResponseCode MdbmOperationFailed = 4; //!< Any store/fetch/lock from mdbm failed
static const ResponseCode NoMem = 5; //!< Out Of Memory
static const ResponseCode InvalidParam = 6; //!< Invalid parameter
static const ResponseCode NotFound = 7; //!< Fail to find the specified info; usuall returned by access methods
static const ResponseCode InvalidState = 8; //!< Invalid state
static const ResponseCode ConnReset = 9; //!< connection reset
static const ResponseCode Timeout = 10; //!< operation timed out
static const ResponseCode InvalidData = 11; //!< buffer data is invalid
static const ResponseCode BufTooSmall = 12; //!< Buffer size is smaller than required
static const ResponseCode MalformedRequest = 13; //!< Request data (like the URI) is malformed
static const ResponseCode RequestTooLarge = 14; //!< Request data (like the body) is too big
static const ResponseCode ConvertToDhtDataFailed = 15; // !< Failed convert json string to DHT::Data
static const ResponseCode ConvertFromDhtDataFailed = 16; // !< Failed to convert DHT::Data to json string
static const ResponseCode BadHexString = 17; //!< Failed to parse a hex string
static const ResponseCode ShmemCorrupted = 18; //!< A shared mem corruption has been detected.
static const ResponseCode ParseError = 19; //!< Generic parsing problem
/// If mdbm unlock fails, most of the time we want to shut off the
/// system automatically, without letting the caller know that we did
/// so. On specific instances where the caller is the FaultHandler, or
/// Oversight Fault counter (there may be other examples), we don't want
/// to do this because we want to avoid cross-dependency.
static const ResponseCode MdbmUnlockFailed = 20;
//----------- Generic section -------------
// Config
static const ResponseCode ConfigFailure = 50; //!< Failure to find or parse a config entry
//----------- UChar section -------------
// UCharUtils
static const ResponseCode UcnvOpenFailed = 100; //!< Failed to open ucnv converter for utf-8
static const ResponseCode DataNotUtf8 = 101; //!< Data is not in utf-8 format
static const ResponseCode ConvertToUCharFailed = 102; //!< Failed to convert utf-8 string to UChar string
static const ResponseCode CompileRegExFailed = 103; //!< Failed to compile the regular expression
//----------- Yca section -------------
// YcaClient
static const ResponseCode YcaOpenFailed = 150; //!< Failed to open the yca database
static const ResponseCode YcaCertInvalid = 151; //!< Validation of presented cert failed
static const ResponseCode YcaCertNotFound = 152; //!< certificate for the requested appID was not found
//----------- Broker section -------------
static const ResponseCode BrokerClientOpenFailed = 200; //!< Failed to connect to broker
static const ResponseCode UncertainPublish = 201; //!< Publish was uncertain - unknown if it happened
static const ResponseCode PublishFailed = 202; //!< Publish failed (for certain :))
static const ResponseCode SubscribeFailed = 203; //!< Failed to subscribe to a topic
static const ResponseCode NoSubscriptionFound = 204; //!< Operation on a sub failed because we (locally)
// don't know about it
static const ResponseCode RegisterFailed = 205; //!< Failed to register handler for subscription
static const ResponseCode UnsubscribeFailed = 206; //!< Failed to unsubscribe from sub
static const ResponseCode ListTopicsFailed = 207; //!< Failed to list subscribed topics
static const ResponseCode ConsumeFailed = 208; //!< Failed to consume messages for a topic
static const ResponseCode TopicInvalid = 209; //!< Topic is invalid (was usurped or ymb 'lost' it)
static const ResponseCode NoMessageDelivered = 210; //!< Call to deliver() found no messages ready
static const ResponseCode ConsumeFailedBadTopic = 211; //!< The topic is bad - our handle is bad,
// or it got usurped
static const ResponseCode ConsumeFailedBadHandle = 212; //!< Our ymb handle is bad - not usable anymore
static const ResponseCode ConsumeFailedConnectionError = 213; //!< a recoverable connection error
static const ResponseCode ConsumeFailedServerBusy = 214; //!< ymb server is having a temporary issue,
// not a failure per se
// second argument to messageProcessed()
static const ResponseCode ConsumeMessage = 215; //!< consume this message
static const ResponseCode ConsumeAndUnsubscribe = 216; //!< end this channel
// Internal to ymb implementation
static const ResponseCode YmbSubscribeTempFailure = 217; //!< A failure that might be resolved on a retry
static const ResponseCode YmbSubscribeTimedout = 218; //!< A timeout failure
static const ResponseCode YmbSubscriptionExists = 219; //!< Attempt to create a sub that already exists
static const ResponseCode NoSuchSubscription = 220; //!< Attempt to attach to a sub that does not exist
static const ResponseCode AttachNoSuchSubscription = 221; //!< Specific to attach, no subscription to attach to (not necessarily an error)
static const ResponseCode BrokerInitFailed = 222; //!< Config or allocation failed
static const ResponseCode BrokerConnectionLost = 223; //!< Lost connection to broker
static const ResponseCode BrokerFatalError = 224; //!< Generally shared mem corruption
//----------- Daemon section -------------
// Daemon
static const ResponseCode NoImpl = 250; //!< No op
static const ResponseCode Restart = 251; //!< Exit the daemon so that it is restarted right away.
// request that the daemon do a soft restart
static const ResponseCode Exit = 252; //!< Exit the daemon so that it is NOT restarted right away. A monitoring process may restart the entire system later.
static const ResponseCode StopDelivery = 253; //!< Stop delivery on the topic, returned by Broker handlers only.
static const ResponseCode RetryDelivery = 254; //!< Stop delivery on the topic but retry after sometime, returned by Broker handlers only.
//----------- Lock section -------------
// LockManager
//ALL these lock errors are handled in SuFaulHandler.cc
//Any addition to these error codes requires update to the SuFaultHandler
static const ResponseCode LockSyserr = 301; //!< System error during lock/unlock op
static const ResponseCode LockInconsis = 302; //!< Inconsistency detected in LockManager.
static const ResponseCode LockNested = 303; //!< Nested locking of same key not allowed.
static const ResponseCode LockNosuchpid = 304; //!< This pid does not hold the lock.
static const ResponseCode LockUnavail = 305; //!< Outa lock
static const ResponseCode LockInitfail = 306; //!< Initialization failure of the lock subsystem
static const ResponseCode LockInvalidarg = 307; //!< Invalid arguments to lock subsystem.
//----------- Message section -------------
//Message and Message serialization
static const ResponseCode SerializeFailed = 350; //!< Message Serialization Failed
static const ResponseCode DeserializeFailed = 351; //!< Message Deserialization failed
static const ResponseCode NoResponseCodeInMessage = 352;
//----------- Transport Errors -------------
static const ResponseCode TransportSendError = 400; //!< Curl error in communicating with other server
static const ResponseCode TransportSetHeaderFailed = 401; //!< Error in setting header in curl request
static const ResponseCode TransportCurlInitError = 402; // !< Error initializing curl handle -- should be curl specific
static const ResponseCode TransportUncertain = 403; //!< Send came back uncertain (timeout, usually)
static const ResponseCode TransportInvalidResponseBody = 404; //!< Send came back unparsable body
//----------- Apache/Web section -------------
static const ResponseCode EndOfBody = 450; //!< Normal end of incoming request body
static const ResponseCode BodyReadFailed = 451; //!< Failed reading incoming request body
static const ResponseCode BodyWriteFailed = 452; //!< Failed writing outgoing request body
static const ResponseCode EncryptionFailed = 453; //!< Failed to encrypt body or header
static const ResponseCode DecryptionFailed = 454; //!< Failed to decrypt body or header
/**
* Give back a basic, generic string description of the response code.
*
* @param rc The response code to convert.
* @return The string describing it.
*/
static std::string toString(ResponseCode rc);
};
/* For customized vim control
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: sw=4:ts=4:et
* vim<600: sw=4:ts=4:et
*/
#endif

View file

@ -1,345 +0,0 @@
/* $Id: StringUtils.h,v 1.17 2009/03/25 20:32:51 dlomax Exp $ */
/* Copyright (C) 2008 Yahoo! Inc. All Rights Reserved. */
#ifndef __STRING_UTIL_H
#define __STRING_UTIL_H
#include <iostream>
#include <iomanip>
#include <sstream>
#include "FwCode.h"
/**
* Container for static string manipulation utilities.
*/
class StringUtils
{
public:
/**
* Our replacement for yax_getroot(). Allows our code to have a different
* root than components we use or link with. Is nice for unit testing.
* @return Copy of the value in a std::string
*/
static std::string getDhtRoot();
/**
* Parse a tablet name into left and right limits.
* @return true if parsing successful, false if incorrect format
*/
static bool parseTabletName(const std::string& tablet, std::string& leftLimit,
std::string& rightLimit);
/**
* Construct a tablet name from left and right limits.
*/
static void buildTabletName(const std::string& leftLimit,
const std::string& rightLimit,
std::string& tablet);
/**
* General purpose method to assemble a full path name, using
* getDhtRoot() so that
* the root will be configurable. DO NOT supply "/home/y" in path1.
*/
static std::string makePath(const std::string& path1 = "",
const std::string& path2 = "",
const std::string& path3 = "",
const std::string& path4 = "",
const std::string& path5 = "",
const std::string& path6 = "");
/**
* Append additional paths to an existing one - does not prepend ROOT.
*/
static void appendPath(std::string& base_path, const std::string& path2 = "",
const std::string& path3 = "",
const std::string& path4 = "");
/**
* Construct a topic name from a table/tablet.
*
* @return the topic name
*/
static std::string buildTopicName(const std::string& table,
const std::string& tablet);
/**
* Construct a topic name from a table/tablet.
* @param topic Is filled with the topic name.
*/
static void buildTopicName(const std::string& table,
const std::string& tablet,
std::string &topic);
/**
* Parses <code>topic</code> into table and tablet portions.
*
* @param table Filled with the table name.
* @param tablet Filled with the tablet name.
* @param true if the parsing succeeded, false if not.
*/
static bool parseTopicName(const std::string& topic,
std::string& table,
std::string &tablet);
/**
* Only for use in log statements - this is slow. Produce a printable
* string where binary (<32) characters are hex encoded, but all others
* are left alone.
*
* @param str string to encode
* @param len length of string
* @return encoded string.
*/
static std::string toPrintable(const char *str, size_t len);
/**
* Convert a formatted hex string back into its original
* 64-bit value
*
* @param value the hex-encoded string
* @param out the value
* @return FwCode::FwOk on success, FwCode::BadHexString on parse failure
*/
static FwCode::ResponseCode
convertHexStringToUI64(const std::string& value, uint64_t& out);
/**
* Convert a formatted hex string back into its original
* 32-bit value
*
* @param value the hex-encoded string
* @param out the value
* @return FwCode::FwOk on success, FwCode::BadHexString on parse failure
*/
static FwCode::ResponseCode
convertHexStringToUI32(const std::string& value, uint32_t& out);
/**
* Standard means for formatting a 0x prefixed hex string from a
* 64-bit unsigned value. Will produce upper-case letters. Will
* pad with zeros at the beginning to fill out 16 hex chars.
*
* @param the value to format
* @return the formatted value, like "0xDEADBEEF00000000"
*/
static std::string convertUI64ToHexString( uint64_t val );
/**
* Standard means for formatting a 0x prefixed hex string from a
* 32-bit unsigned value. Will produce upper-case letters. Will
* pad with zeros at the beginning to fill out 8 hex chars.
*
* @param the value to format
* @return the formatted value, like "0xDEADBEEF"
*/
static std::string convertUI32ToHexString( unsigned int val );
/**
* Standard means for formatting a small hex string from a
* 32-bit unsigned value. The "0x" will NOT be included.
* Will produce upper-case letters. Will NOT pad with zeros
* at the beginning.
*
* @param the value to format
* @return the formatted value, like "DEADBEEF"
*/
static std::string convertUI32ToMinimalHexString( unsigned int val );
/**
* Assemble the fields of ENCRYPTED_BODY_HEADER and encrypt it for
* sending to the remote side.
* @param result is the out parameter having the resulting string.
* @param encKeyName is the name of the key in keydb whose value will be
* used as the encryption key
* @param bodyEncVersion is the version of the encryption scheme used to
* encrypt the body (not the encryption scheme of this header itself).
* @param expireTime is the time (in usecs) after which the request
* should not be processed by the receiver of this header.
*/
static FwCode::ResponseCode makeEncryptedBodyHdr(std::string & result,
const char *encKeyName, uint32_t bodyEncVersion, uint64_t expireTime);
/**
* Parse the incoming ENCRYPTED_BODY_HEADER, decrypting it, and
* separating the fields in it.
* @param inval is the incoming encrypted string.
* @param encKeyName is the name of the key in keydb whose value will be
* used as the decryption key
* @param bodyEncVersion is the version of the encryption scheme to be
* used to * decrypt the body (not for the decryption of this header
* itself).
* @param expireTime is the time (in usecs) after which the response
* should not be processed by the receiver of this header.
*/
static FwCode::ResponseCode parseEncryptedBodyHdr(const std::string & inval,
const char *encKeyName, uint32_t & bodyEncVersion, uint64_t & expireTime);
/**
* Get the hash for an un-normalized record name.
*
* @param unnormalizedRecordName a raw record name from user input
* @param (output) hashResult the hex string of the hash value.
* @return FwCode::FwOk on success, else an error relating to normalization
*/
static FwCode::ResponseCode normalizeAndHashRecordName
( const std::string& unnormalizedRecordName,
std::string & hashResult /* out */ );
/**
* Get the hash for a normalized record name.
*
* @param recordName the record name. MUST be previously normalized.
* @return hashResult the uint32_t of the hash value.
*/
static uint32_t hashRecordName(const std::string& recordName);
/**
* Get the hash for a normalized record name.
*
* @param recordName the record name. MUST be previously normalized.
* @param (output) hashResult the hex string of the hash value.
*/
static void hashRecordName( const std::string& recordName,
std::string & hashResult /* out */ );
/**
* Get the hash for a normalized record name in string and int form
*
* @param recordName the record name. MUST be previously normalized.
* @param (output) hashResult the hex string of the hash value.
* @param (output) hexNum numerical value of hash
*/
static void hashRecordName( const std::string& recordName,
std::string & hashResult /* out */,
uint32_t& hexNum);
/**
* Method to hash a string using crc32.
*
* @param buf data to hash
* @param len length of buf
* @return hash value
*/
static uint32_t crcHash(const char * buf, uint32_t len);
/**
* util function to convert any type to a string
*/
template<typename T> static inline std::string toString(T item);
/**
* convert string to any type of value
* @param strValue string value to parse
* @param value(out) value to read from strValue
* @return FwCode::FwOk on success
* FwCode::FwError on failure (error is *not* logged)
*/
template<typename T> static inline
FwCode::ResponseCode fromString(const std::string& strValue,
T& value);
/**
* convert a hexadecimal number to string representation
* of fixed width ( 2 * sizeof(T) )
* @param value number to convert to string
* @return string representation of value
*/
template<typename T> static inline
std::string numberToHexString(T value);
/**
* convert a hexadecimal number to minimal string representation
* @param value number to convert to string
* @return string representation of value
*/
template<typename T> static inline
std::string numberToMinimalHexString(T value);
/**
* convert a hexadecimal string to a number
* @param strvalue input string to read from
* @param value(out) output number
* @return FwCode::FwOk on successful conversion
* FwCode::FwError on failure to convert strvalue
* to number
*/
template<typename T> static inline
FwCode::ResponseCode hexStringToNumber(const std::string& strvalue,
T& value);
static const std::string EMPTY_STRING;
};
template<typename T>
std::string StringUtils::
toString(T item)
{
std::ostringstream buf;
buf << item;
return buf.str();
}
template<typename T>
FwCode::ResponseCode StringUtils::
fromString(const std::string& strValue,
T& value)
{
std::istringstream buf(strValue);
buf >> value;
if(buf.fail()||
(strValue.length() != buf.tellg() ))
{
return FwCode::FwError;
}
return FwCode::FwOk;
}
template<typename T>
std::string StringUtils::
numberToHexString(T value)
{
std::ostringstream buf;
buf << "0x" << std::hex
<< std::setw(sizeof(T) * 2) << std::setfill('0')
<< std::uppercase << value;
return buf.str();
}
template<typename T>
std::string StringUtils::
numberToMinimalHexString(T value)
{
std::ostringstream buf;
buf << std::hex << std::uppercase << value;
return buf.str();
}
template<typename T>
FwCode::ResponseCode StringUtils::
hexStringToNumber(const std::string& strvalue,
T& value)
{
std::istringstream buf(strvalue);
buf >> std::hex >> value;
if(buf.fail() ||
(strvalue.length() != buf.tellg() ))
{
return FwCode::FwError;
}
return FwCode::FwOk;
}
/*
* For customized vim control
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: sw=4:ts=4:et
* vim<600: sw=4:ts=4:et
*/
#endif