TA_RetCode TA_YAHOO_CloseSource( TA_DataSourceHandle *handle ) { TA_PROLOG TA_TRACE_BEGIN( TA_YAHOO_CloseSource ); /* Free all ressource used by this handle. */ if( handle ) TA_YAHOO_DataSourceHandleFree( handle ); TA_TRACE_RETURN( TA_SUCCESS ); }
TA_RetCode TA_YAHOO_OpenSource( const TA_AddDataSourceParamPriv *param, TA_DataSourceHandle **handle ) { TA_PROLOG TA_DataSourceHandle *tmpHandle; TA_PrivateYahooHandle *privData; TA_RetCode retCode; TA_StringCache *stringCache; TA_CountryId countryId; TA_CountryId countryIdTemp; TA_Timestamp now; const char *locationPtr; char locationBuffer[3]; int timeout_set; /* boolean */ int i, again; unsigned int strLength, strServerLength; const char *strTemp; *handle = NULL; TA_TRACE_BEGIN( TA_YAHOO_OpenSource ); stringCache = TA_GetGlobalStringCache(); /* Verify that the requested functionality is supported or not. */ if( param->flags & TA_REPLACE_ZERO_PRICE_BAR ) { TA_TRACE_RETURN( TA_NOT_SUPPORTED ); } /* Allocate and initialize the handle. This function will also allocate the * private handle (opaque data). */ tmpHandle = TA_YAHOO_DataSourceHandleAlloc(); if( tmpHandle == NULL ) { TA_TRACE_RETURN( TA_ALLOC_ERR ); } privData = (TA_PrivateYahooHandle *)(tmpHandle->opaqueData); /* Copy some parameters in the private handle. */ privData->param = param; /* Indentify the country and replace with the default as needed. * At the same time, identify optional "server=" modifier. */ countryId = TA_Country_ID_INVALID; if( privData->param->location ) { locationPtr = TA_StringToChar(privData->param->location); /* Split into token (seperator is ';'). Check for a 2 character country * string and the optional "server=" modifier. */ i = -1; strTemp = &locationPtr[0]; strLength = 0; strServerLength = strlen(TA_SERVER_STR); again = 1; while( (++i < 1024) && again ) { if( strLength == 0 ) strTemp = &locationPtr[i]; if( locationPtr[i] == '\0' ) again = 0; if( locationPtr[i] == ';' || !again ) { if( strLength == 2 ) { locationBuffer[0] = locationPtr[i-2]; locationBuffer[1] = locationPtr[i-1]; locationBuffer[2] = '\0'; countryIdTemp = TA_CountryAbbrevToId(locationBuffer); if( countryIdTemp == TA_Country_ID_INVALID ) TA_TRACE_RETURN( TA_UNSUPPORTED_COUNTRY ); if( countryId != TA_Country_ID_INVALID ) TA_TRACE_RETURN( TA_LIMIT_OF_ONE_COUNTRY_ID_EXCEEDED ); countryId = countryIdTemp; } else if( strLength>strServerLength && (strncmp(strTemp,TA_SERVER_STR,strServerLength)==0) ) { if( privData->userSpecifiedServer ) TA_TRACE_RETURN( TA_LIMIT_OF_ONE_SERVER_EXCEEDED ); privData->userSpecifiedServer = TA_StringAllocN( stringCache, &strTemp[strServerLength], strLength-strServerLength ); TA_ASSERT( privData->userSpecifiedServer != NULL ); } else TA_TRACE_RETURN( TA_LOCATION_PARAM_INVALID ); strLength = 0; } else strLength++; } } if( countryId == TA_Country_ID_INVALID ) { /* Default is United States. */ countryId = TA_Country_ID_US; } if( privData->param->id == TA_YAHOO_ONE_SYMBOL ) { privData->index = NULL; privData->webSiteCountry = countryId; privData->webSiteSymbol = TA_StringDup(stringCache,privData->param->info); tmpHandle->nbCategory = 1; } else { /* Build the index using .dat files */ switch( countryId ) { case TA_Country_ID_US: /* United States */ case TA_Country_ID_CA: /* Canada */ case TA_Country_ID_UK: /* United Kingdom */ case TA_Country_ID_DE: /* Germany */ case TA_Country_ID_DK: /* Denmark */ case TA_Country_ID_ES: /* Spain */ case TA_Country_ID_FR: /* France */ case TA_Country_ID_IT: /* Italy */ case TA_Country_ID_SE: /* Sweden */ case TA_Country_ID_NO: /* Norway */ /* These country are currently supported. */ break; default: TA_YAHOO_DataSourceHandleFree( tmpHandle ); TA_TRACE_RETURN( TA_UNSUPPORTED_COUNTRY ); } /* Establish the timeout for local cache of the index. * Let's make it 4 business days. */ timeout_set = 0; TA_SetDefault( &now ); retCode = TA_SetDateNow( &now ); for( i=0; (i < 4) && (retCode == TA_SUCCESS); i++ ) retCode = TA_PrevWeekday( &now ); if( (i == 4) && (retCode == TA_SUCCESS) ) timeout_set = 1; /* At this point, we got all the information we * need in the handle. * Now build the TA_YahooIdx. */ retCode = TA_YahooIdxAlloc( countryId, &privData->index, TA_USE_LOCAL_CACHE|TA_USE_REMOTE_CACHE, NULL, timeout_set?&now:NULL, NULL ); if( retCode != TA_SUCCESS ) { TA_YAHOO_DataSourceHandleFree( tmpHandle ); TA_TRACE_RETURN( retCode ); } /* Set the total number of distinct category. */ tmpHandle->nbCategory = privData->index->nbCategory; } *handle = tmpHandle; TA_TRACE_RETURN( TA_SUCCESS ); }
TA_RetCode TA_YAHOO_OpenSource( const TA_AddDataSourceParamPriv *param, TA_DataSourceHandle **handle ) { TA_PROLOG TA_DataSourceHandle *tmpHandle; TA_PrivateYahooHandle *privData; TA_RetCode retCode; TA_StringCache *stringCache; TA_CountryId countryId; TA_Timestamp now; const char *locationPtr; int timeout_set; /* boolean */ int i; *handle = NULL; TA_TRACE_BEGIN( TA_YAHOO_OpenSource ); stringCache = TA_GetGlobalStringCache(); /* Verify that the requested functionality is supported or not. */ if( param->flags & TA_REPLACE_ZERO_PRICE_BAR ) { TA_TRACE_RETURN( TA_NOT_SUPPORTED ); } /* Allocate and initialize the handle. This function will also allocate the * private handle (opaque data). */ tmpHandle = TA_YAHOO_DataSourceHandleAlloc(); if( tmpHandle == NULL ) { TA_TRACE_RETURN( TA_ALLOC_ERR ); } privData = (TA_PrivateYahooHandle *)(tmpHandle->opaqueData); /* Copy some parameters in the private handle. */ privData->param = param; /* Validate if this is a supported country. */ if( !privData->param->location ) { countryId = TA_Country_ID_US; } else { locationPtr = TA_StringToChar(privData->param->location); countryId = TA_CountryAbbrevToId(locationPtr); switch( countryId ) { case TA_Country_ID_US: /* United States */ case TA_Country_ID_CA: /* Canada */ case TA_Country_ID_UK: /* United Kingdom */ case TA_Country_ID_DE: /* Germany */ case TA_Country_ID_DK: /* Denmark */ case TA_Country_ID_ES: /* Spain */ case TA_Country_ID_FR: /* France */ case TA_Country_ID_IT: /* Italy */ case TA_Country_ID_SE: /* Sweden */ case TA_Country_ID_NO: /* Norway */ /* These country are currently supported. */ break; default: TA_YAHOO_DataSourceHandleFree( tmpHandle ); TA_TRACE_RETURN( TA_UNSUPPORTED_COUNTRY ); } } /* Establish the timeout for local cache of the index. * Let's make it 3 business days. */ timeout_set = 0; TA_SetDefault( &now ); retCode = TA_SetDateNow( &now ); for( i=0; (i < 3) && (retCode == TA_SUCCESS); i++ ) retCode = TA_PrevWeekday( &now ); if( (i == 3) && (retCode == TA_SUCCESS) ) timeout_set = 1; /* At this point, we got all the information we * need in the handle. * Now build the TA_YahooIdx. */ retCode = TA_YahooIdxAlloc( countryId, &privData->index, TA_USE_LOCAL_CACHE|TA_USE_REMOTE_CACHE, NULL, timeout_set?&now:NULL, NULL ); if( retCode != TA_SUCCESS ) { TA_YAHOO_DataSourceHandleFree( tmpHandle ); TA_TRACE_RETURN( retCode ); } /* Set the total number of distinct category. */ tmpHandle->nbCategory = privData->index->nbCategory; *handle = tmpHandle; TA_TRACE_RETURN( TA_SUCCESS ); }