Esempio n. 1
0
STDMETHODIMP HostUSBDeviceFilterWrap::COMGETTER(Product)(BSTR *aProduct)
{
    LogRelFlow(("{%p} %s: enter aProduct=%p\n", this, "HostUSBDeviceFilter::getProduct", aProduct));

    VirtualBoxBase::clearError();

    HRESULT hrc;

    try
    {
        CheckComArgOutPointerValidThrow(aProduct);

        AutoCaller autoCaller(this);
        if (FAILED(autoCaller.rc()))
            throw autoCaller.rc();

        hrc = getProduct(BSTROutConverter(aProduct).str());
    }
    catch (HRESULT hrc2)
    {
        hrc = hrc2;
    }
    catch (...)
    {
        hrc = VirtualBoxBase::handleUnexpectedExceptions(this, RT_SRC_POS);
    }

    LogRelFlow(("{%p} %s: leave *aProduct=%ls hrc=%Rhrc\n", this, "HostUSBDeviceFilter::getProduct", *aProduct, hrc));
    return hrc;
}
long long projectEuler_008() {
	std::string str(
		"73167176531330624919225119674426574742355349194934"
		"96983520312774506326239578318016984801869478851843"
		"85861560789112949495459501737958331952853208805511"
		"12540698747158523863050715693290963295227443043557"
		"66896648950445244523161731856403098711121722383113"
		"62229893423380308135336276614282806444486645238749"
		"30358907296290491560440772390713810515859307960866"
		"70172427121883998797908792274921901699720888093776"
		"65727333001053367881220235421809751254540594752243"
		"52584907711670556013604839586446706324415722155397"
		"53697817977846174064955149290862569321978468622482"
		"83972241375657056057490261407972968652414535100474"
		"82166370484403199890008895243450658541227588666881"
		"16427171479924442928230863465674813919123162824586"
		"17866458359124566529476545682848912883142607690042"
		"24219022671055626321111109370544217506941658960408"
		"07198403850962455444362981230987879927244284909188"
		"84580156166097919133875499200524063689912560717606"
		"05886116467109405077541002256983155200055935729725"
		"71636269561882670428252483600823257530420752963450"
	);
	long long max = 0;
	int len = 13;
	for (size_t i = 0; i < (str.size() + 1 - len); i++) {
		std::string tempStr = str.substr(i, len);
		long long temp = getProduct(tempStr);
		if (temp > max) {
			max = temp;
		}
	}

	return max;
}
uint32 
UserLicenceKey::printValue( char* target, 
                            UserConstants::UserLicenceKeyField field ) const
{
   switch ( field ) {
      case UserConstants::USER_LICENCE_KEY_ID :
      case UserConstants::USER_LICENCE_KEY_USERUIN :
         mc2log << error << "UserLicenceKey::printValue asked to print ID "
                << "or userUIN, not supported." << endl;
         MC2_ASSERT( false );
         break;
      case UserConstants::USER_LICENCE_KEY :
         strcat( target, "'" );
         sqlString( target + 1, getLicenceKeyStr().c_str() );
         strcat( target, "'" );
         break;
      case UserConstants::USER_LICENCE_PRODUCT :
         strcat( target, "'" );
         sqlString( target + 1, getProduct() );
         strcat( target, "'" );
         break;
      case UserConstants::USER_LICENCE_KEY_TYPE :
         strcat( target, "'" );
         sqlString( target + 1, getKeyType() );
         strcat( target, "'" );
         break;
      default:
         mc2log << error << "UserLicenceKey::printValue unknown " 
                << "fieldType: " << (int)field << endl;
         break;
   }

   return strlen( target );
}
Esempio n. 4
0
	void onTransactionCompleted(const std::string &sku, const data::Value &data) {
		StoreProduct *product = getProduct(sku);
		if (product) {
			product->validated = true;
			int64_t date = data.getInteger("purchaseTime");
			product->purchased = true;
			product->available = true;
			product->purchaseDate = Time::milliseconds(date);

			if (product->isSubscription) {
				product->expiration = Time::now() + TimeInterval::seconds(2 * 24 * 3600);
			}

			auto sk = StoreKit::getInstance();
			StoreKit::onProductUpdate(sk, product->productId);
			StoreKit::onPurchaseCompleted(sk, product->productId);
			save();
#if (DEBUG)
			log::format("StoreKit", "Feature purchased: %s", product->productId.c_str());
#endif
		} else {
#if (DEBUG)
			log::format("StoreKit", "no product for id %s", sku.c_str());
#endif
		}
	}
bool
UserLicenceKey::compare( const UserLicenceKey& o ) const {
   return (getLicenceLength() == o.getLicenceLength() &&
           memcmp( getLicenceKey(), o.getLicenceKey(), 
                   getLicenceLength() ) == 0) &&
      getProduct() == o.getProduct() &&
      getKeyType() == o.getKeyType();
}
Esempio n. 6
0
	void onFeatureInfoFailed(const std::string &sku) {
		auto sk = StoreKit::getInstance();
		StoreProduct *product = getProduct(sku);
		if (product) {
			product->available = false;
			StoreKit::onProductUpdate(sk, product->productId);
		}
	}
Esempio n. 7
0
	void onTransactionFailed(const std::string &sku) {
		StoreProduct *product = getProduct(sku);
		if (product) {
			StoreKit::onPurchaseFailed(StoreKit::getInstance(), product->productId);
			save();
#if (DEBUG)
			log::format("StoreKit", "Feature failed: %s", product->productId.c_str());
#endif
		} else {
#if (DEBUG)
			log::format("StoreKit", "no product for id %s", sku.c_str());
#endif
		}
	}
Esempio n. 8
0
	void onFeatureInfo(const std::string &sku, const data::Value &data) {
		if (data.isDictionary()) {
			auto sk = StoreKit::getInstance();
			StoreProduct *product = getProduct(sku);
			if (product) {
				product->price = data.getString("price");
				product->available = true;
				product->validated = true;

				StoreKit::onProductUpdate(sk, product->productId);
#if (DEBUG)
				log::format("StoreKit", "Feature: %s, Cost: %s", product->productId.c_str(), product->price.c_str());
#endif
			}
		}
	}
Esempio n. 9
0
int getProductCardType(U8_t id, char* type, int bufferLength)
{
   int returnValue=false;
	MYKI_CD_Product_t product;
	if (getProduct(id, product) == false)
	{
		CsDebug(CD_DEBUG, (CD_DEBUG, "MYKI_CD:getProductCardType: getProduct failed, returning fail"));
	}
	else
	{
		stringCopy(type, product.type, bufferLength);
		returnValue = true;
	}

    return returnValue;
}
Esempio n. 10
0
 virtual void purchase(const std::string &id) override
 {
     const avalon::payment::Product* productToPurchase = getProduct(id);
     if(!productToPurchase)
     {
         Transaction managerTransaction;
         managerTransaction.transactionState = TransactionState::Failed;
         managerTransaction.productId = id;
         _delegate->onPurchaseFail(managerTransaction, ManagerDelegateErrors::PRODUCT_UNKNOWN);
     }
     if (_delegate)
     {
         Transaction managerTransaction;
         managerTransaction.transactionState = TransactionState::Purchased;
         managerTransaction.productId = id;
         _delegate->onPurchaseSucceed(managerTransaction);
     }
 }
QString DeviceInfo::getDescription() const
{
    return getUART() + ':' + QString::number(getID()) + '(' + getVendor() + '.' + getProduct() + '.' + getVersion() + ')';
}
Esempio n. 12
0
/**
   @brief Checks if the instance of product is valid
 
   @return    True if the instance is valid, false otherwise
 */
bool ProductProxy::isValid()
{
    return (getProduct() != NULL);
}
Esempio n. 13
0
/**
   @brief Returns product category
 
   @return    An instance of class Category which the product belongs
 */
auto_ptr<Category> ProductProxy::getCategory()
{
    return getProduct()->getCategory();
}
Esempio n. 14
0
/**
   @brief Returns product description
 
   @return    The product description
   @see getProduct(), Product()
 */
string ProductProxy::getDescr()
{
    return getProduct()->valueForKey(KEY_PRD_DESCR);
}
Esempio n. 15
0
/**
   @brief Return the product availability
 
   @return How many pieces of this product are available
 */
int ProductProxy::getAvailability()
{
    return getProduct()->intForKey(KEY_PRD_AVAILABILITY);
}
Esempio n. 16
0
/**
   @brief Returns product name
 
   @return    THe name of the product
   @see getProduct(), Product() 
 */
string ProductProxy::getName() 
{ 
    return getProduct()->valueForKey(KEY_PRD_NAME);
}
Esempio n. 17
0
/**
   @brief Returns the price of this product
 
   @return    The price of the product
   @see getProduct(), Product() 
 */
float ProductProxy::getPrice()
{
    return getProduct()->getPrice();
}
Esempio n. 18
0
/****************************************************************************
 * Loads all data into the system.
 ****************************************************************************/
int loadData(VendingMachineType *vm, char *stockfile, char *coinsFile)
{
   FILE *stock;
   FILE *coins;
   char tempString[PRODUCT_NAME_MAX + PRODUCT_BRAND_MAX + PRODUCT_PRICE_MAX + PRODUCT_QTY_MAX + EXTRA_SPACES] = "";
   
   char *name;
   char *brand;
   unsigned quantity;
   unsigned price;
   
   unsigned coinValue, coinQuantity;
   
   ProductNodeType *node = NULL;
   CoinType coin;
   int i=0;
   
   if((stock=fopen(stockfile, "r")) == NULL) {
      printf("Cannot open stock file.\n");
      return FAILURE;
   } else if((coins=fopen(coinsFile, "r")) == NULL) {
      printf("Cannot open coins file.\n");
      return FAILURE;
   } else {      
      /*copying data from files to lists*/
      while(fgets(tempString, sizeof(tempString), stock) != NULL){
         name = strtok(tempString,",");
         brand = strtok('\0',",");
         price = (unsigned) atof(strtok('\0',","));
         quantity = (unsigned) atof(strtok('\0',"\0"));
         
         node = getProduct(name, vm);
         
         if(node != NULL && node->price == price){
            node->qty += quantity;
         } else {
            node = malloc(sizeof(ProductNodeType));
            strcpy(node->name, name);
            strcpy(node->brand, brand);
            node->price = price;
            node->qty = quantity;
            
            vm->headProduct = insertNode(vm->headProduct, node);
            vm->totalProducts++;
         }
      }
      
      fclose(stock);
         
      vm->totalCoins = 0;
      while(fgets(tempString, sizeof(tempString), coins) != NULL){
         coinValue = (unsigned) atof(strtok(tempString,","));
         coinQuantity = (unsigned) atof(strtok('\0',"\0"));
         
         coin.value = coinValue;
         coin.qty = coinQuantity;
         vm->coins[i] = coin;
         i++;
         vm->totalCoins++;
      }

      fclose(coins);
      
      return SUCCESS;
   }
}
Esempio n. 19
0
ImageReader::ImageHandle ImageReader::getImage(text::string_hash id)
{
	if (hasProduct(id))
		return getProduct(id);

	// Image is not in cache, load it.

	const std::string& url = text::get(id);

	INFO_OUT(TAG, "Loading image %s", url.c_str());

	FILE* fp = fopen(url.c_str(), "rb");

	if (fp == NULL)
		throw ResourceException("Cannot open file.");

	if ( !isPNGFile(fp) )
	{
		fclose(fp);
		throw ResourceException("File is not PNG.");
	}

	png_structp pngStruct = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
	if (!pngStruct)
	{
		fclose(fp);
		throw ResourceException("[LIBPNG] Error creating read struct.");
	}

	png_infop pngInfo = png_create_info_struct(pngStruct);
	if (!pngInfo)
	{
		png_destroy_read_struct(&pngStruct, nullptr, nullptr);
		fclose(fp);
		throw ResourceException("[LIBPNG] Error creating info struct.");
	}

	if ( setjmp(png_jmpbuf(pngStruct)) )
	{
		png_destroy_read_struct(&pngStruct, &pngInfo, nullptr);
		fclose(fp);
		throw ResourceException("Error while reading file.");
	}

	png_init_io(pngStruct, fp);

	png_set_sig_bytes(pngStruct, pngHeaderCheckSize);

	// FIXME Write directly to buffer, don't copy.

	png_read_png(pngStruct,
	             pngInfo,
	             PNG_TRANSFORM_STRIP_16 | PNG_TRANSFORM_PACKING | PNG_TRANSFORM_EXPAND,
	             NULL);

	struct
	{
		png_uint_32 width;
		png_uint_32 height;
		png_byte bitsPerPixel;
		png_byte colorType;
		png_size_t rowSize;
	} imageData;

	imageData.width 		= png_get_image_width(pngStruct, pngInfo);
	imageData.height 		= png_get_image_height(pngStruct, pngInfo);
	imageData.bitsPerPixel 	= png_get_bit_depth(pngStruct, pngInfo);
	imageData.colorType 	= png_get_color_type(pngStruct, pngInfo);
	imageData.rowSize		= png_get_rowbytes(pngStruct, pngInfo);

	// FIXME Let PixelFormat decide what format is suitable.

	gr::PixelFormat fmt;
	if (imageData.colorType == PNG_COLOR_TYPE_RGBA)
		fmt = gr::PixelFormat::R8G8B8A8;
	else
		fmt = gr::PixelFormat::R8G8B8;

	unsigned char* pixels = new unsigned char[imageData.rowSize * imageData.height];
	png_bytepp rowPointers = png_get_rows(pngStruct, pngInfo);

	for (unsigned int i = 0; i < imageData.height; i++)
		memcpy(pixels + (imageData.rowSize * (imageData.height - 1 - i)),
		       rowPointers[i],
		       imageData.rowSize);

	png_destroy_read_struct(&pngStruct, &pngInfo, NULL);
	fclose(fp);

	return addProduct(id, gr::Image((unsigned int) imageData.width,
	                                (unsigned int) imageData.height,
	                                fmt,
	                                1u,
	                                pixels));
}
Esempio n. 20
0
/**
 * Creates a new CD-key decoder object, using the specified key.
 * keyLength should be the length of the key, NOT INCLUDING the
 * null-terminator.  Applications should use isKeyValid after using
 * this constructor to check the validity of the provided key.
 */
CDKeyDecoder::CDKeyDecoder(const char* cdKey, size_t keyLength) {
    unsigned int i;
    
    initialized = 0;
	product = 0;
	value1 = 0;
	value2 = 0;
    keyOK = 0;
    hashLen = 0;
	cdkey = (char*) 0;
	w3value2 = (char*) 0;
	keyHash = (char*) 0;
    
    if (keyLength <= 0) return;
    
    // Initial sanity check
    if (keyLength == 13) {
        // StarCraft key
        for (i = 0; i < keyLength; i++) {
            if (!isdigit(cdKey[i])) return;
        }
        keyType = KEY_STARCRAFT;
#if DEBUG
				bncsutil_debug_message_a(
					"Created CD key decoder with STAR key %s.", cdKey
				);
#endif
    } else {
        // D2/W2/W3 key
        for (i = 0; i < keyLength; i++) {
            if (!isalnum(cdKey[i])) return;
        }
        switch (keyLength) {
            case 16:
                keyType = KEY_WARCRAFT2;
#if DEBUG
				bncsutil_debug_message_a(
					"Created CD key decoder with W2/D2 key %s.", cdKey
				);
#endif
                break;
            case 26:
                keyType = KEY_WARCRAFT3;
#if DEBUG
				bncsutil_debug_message_a(
					"Created CD key decoder with WAR3 key %s.", cdKey
				);
#endif
                break;
            default:
#if DEBUG
				bncsutil_debug_message_a(
					"Created CD key decoder with unrecognized key %s.", cdKey
				);
#endif
                return;
        }
    }
    
    cdkey = new char[keyLength + 1];
    initialized = 1;
    keyLen = keyLength;
    strcpy(cdkey, cdKey);
    
    switch (keyType) {
        case KEY_STARCRAFT:
            keyOK = processStarCraftKey();
#if DEBUG
			bncsutil_debug_message_a("%s: ok=%d; product=%d; public=%d; "
				"private=%d", cdkey, keyOK, getProduct(), getVal1(), getVal2());
#endif
            break;
        case KEY_WARCRAFT2:
            keyOK = processWarCraft2Key();
#if DEBUG
			bncsutil_debug_message_a("%s: ok=%d; product=%d; public=%d; "
				"private=%d", cdkey, keyOK, getProduct(), getVal1(), getVal2());
#endif
            break;
        case KEY_WARCRAFT3:
            keyOK = processWarCraft3Key();
#if DEBUG
			bncsutil_debug_message_a("%s: ok=%d; product=%d; public=%d; ",
				cdkey, keyOK, getProduct(), getVal1());
#endif
            break;
        default:
            return;
    }
}