home *** CD-ROM | disk | FTP | other *** search
/ c't freeware shareware 1997 / CT_SW_97.ISO / mac / Software / finanzen / win95 / quotenow.exe / data.z / lombard.cpp < prev    next >
C/C++ Source or Header  |  1996-12-03  |  24KB  |  974 lines

  1. // lombard.cpp : Defines the initialization routines for the DLL.
  2. //
  3.  
  4. /*
  5. QuotesNow! is trademark and (C)opyright 1996
  6. by Federated Telecommunications Corp. and
  7. Windows Xpert Systems 
  8.  
  9. You or any entity using this code must purchase a copy of QuotesNow!
  10. (tm) for each person that will use this source code.  The purchaser/
  11. registered user may freely distribute compiled derivative
  12. (machine readable code only) versions of this code.
  13.  
  14. Registered Users (Users who have purchased the QuotesNow! (tm) program
  15. from Federated Telecommunications Corp. or Windows Xpert Systems)
  16. Once you have purchased the application, you may use one copy
  17. of the program.  The program is licensed to YOU (the purchaser/user
  18. by name), no other user may legally use the software.
  19. It is understood that you use the software at your own risk.
  20.  Registered Users may produce compiled derivative works of the
  21.  source code provided with this program as long as it's intended use
  22.  is only for use with the QuotesNow! (tm) program by Windows Xpert Systems
  23.  and Federated Telecommunications Corp.  The derivative source code
  24.  may be distributed as long as all notices in all code, including
  25.  copyright and trademark notices remain intact and the author makes it
  26.  clear that the source code may only be used to work with the
  27.  QuotesNow! (tm) program by Windows Xpert Systems and 
  28.  Federated Telecommunications, and that any user of the source code must
  29.  purchase the QuotesNow! (tm) program to use it.  The header files
  30.  (files ending in .h, such as server.h) may not be distributed
  31.  seperately from the QuotesNow! (tm) program.
  32.  The add-in .SRV/.DLL source code itself may only be distributed
  33.  as a derivative work as mentioned above 
  34.  (with all notices intact and the author notifying any potential
  35.  user of the required uses of the source code - only a Registered
  36.  QuotesNow! (tm) user may distribute/use the Source code derivative
  37.  work.)
  38.  
  39.   */
  40.  
  41. #include "stdafx.h"
  42. #include <afxdllx.h>
  43. #include "resource.h"
  44. #include "../../server.h"
  45. #include "passdlg.h"
  46.  
  47. #ifdef _DEBUG
  48. #define new DEBUG_NEW
  49. #undef THIS_FILE
  50. static char THIS_FILE[] = __FILE__;
  51. #endif
  52.  
  53.  
  54. //stock parsing callback declare
  55. __declspec(dllexport) ParseLombardSServer(char *buffer,
  56.                                            DWORD len,
  57.                                            CPUBSTOCKOBJ &pobjArray,
  58.                                            int iIgnore,CServerObject *srvo);
  59.  
  60. //option parsing callback declare
  61. __declspec(dllexport) ParseLombardOServer(char *buffer,
  62.                                            DWORD len,
  63.                                            CPUBSTOCKOBJ &pobjArray,
  64.                                            int iIgnore,CServerObject *srvo);
  65.  
  66.  
  67. //required functions when SRV_CAP_SETTINGS
  68. //names can be anything you like as the addresses
  69. //are passed back to the CServerObject structure
  70. //passed in by the client
  71. __declspec(dllexport) DWORD CreateSettings(void *buffer,DWORD len);
  72. __declspec(dllexport) BOOL DeleteSettings(DWORD dwSettings);
  73. __declspec(dllexport) DWORD EditSettings(DWORD dwSettings,int iWhichSetting);
  74. __declspec(dllexport) DWORD GetSettings(DWORD dwSettings,
  75.                                         void **lpBuf,LPDWORD lpdwSize);
  76.  
  77. //required function when SRV_CAP_REQUIRESLOGIN set
  78. //name can be anything you like as the addresses
  79. //are passed back to the CServerObject structure
  80. //passed in by the client. These are not called
  81. //directly
  82.  
  83. __declspec(dllexport) DWORD GetUserInfo(DWORD dwSettings,
  84.                                          CString &sUsername,
  85.                                          CString &sPassword);
  86.  
  87.  
  88. __declspec(dllexport) BOOL TickerBar(DWORD dwSettings,DWORD dwFlag,
  89.                                                   CPubDrawObject *dobj);
  90.  
  91.  
  92. //defines to simplify calling helper functions
  93. #define GetTagS    (*wxsinfo.lpfnGetTagS)
  94. #define GetTableItems (*wxsinfo.lpfnGetTableItems)
  95. #define SplitStringDash (*wxsinfo.lpfnSplitStringDash)
  96. #define FixupNumber    (*wxsinfo.lpfnFixupNumber)
  97. #define FindDataField (*wxsinfo.lpfnFindDataField)
  98. #define GetNumberAndFraction (*wxsinfo.lpfnGetNumberAndFraction)
  99. #define RegisterFileFormat (*wxsinfo.lpfnRegisterFileFormat)
  100. #define RegisterImportFileFormat (*wxsinfo.lpfnRegisterImportFileFormat)
  101.  
  102.  
  103. HINSTANCE g_hInstance;
  104. //globally defined structure so that our helper function
  105. //macros will work
  106. WXSINFO wxsinfo;
  107.  
  108. static AFX_EXTENSION_MODULE LombardDLL = { NULL, NULL };
  109.  
  110. extern "C" int APIENTRY
  111. DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  112. {
  113.     if (dwReason == DLL_PROCESS_ATTACH)
  114.     {
  115.         TRACE0("Lombard.DLL Initializing!\n");
  116.         g_hInstance=hInstance;
  117.         // Extension DLL one-time initialization
  118.         AfxInitExtensionModule(LombardDLL, hInstance);
  119.  
  120.         // Insert this DLL into the resource chain
  121.         new CDynLinkLibrary(LombardDLL);
  122.     }
  123.     else if (dwReason == DLL_PROCESS_DETACH)
  124.     {
  125.         TRACE0("Lombard.DLL Terminating!\n");
  126.     }
  127.     return 1;   // ok
  128. }
  129.  
  130.  
  131. //WxsGetApiVersion required function
  132. //MUST BE NAMED this way exactly
  133. extern "C" __declspec(dllexport) float WxsGetApiVersion()
  134. {
  135.     return (float)WXSSERVER_APIVERSION;
  136. }
  137.  
  138. //WxsServerInit required function
  139. //MUST BE NAMED this way exactly
  140. extern "C" __declspec(dllexport) BOOL WxsServerInit(CServerObject *srv,float fApiVersion,int iCServerObject,
  141.                                                     WXSINFO *pwxs)
  142. {
  143.  
  144.     HINSTANCE hInst=AfxGetResourceHandle();
  145.  
  146.     
  147.     //This is true only if the client exactly matches how the .DLL
  148.     //was compiled.  (This can be different when the .DLL
  149.     //version doesn't match the client version) Though it could be
  150.     //the same.  Depends on whether or not we have made changes to
  151.     //the CServerObject data strcuture for a particular version
  152.     //this test is only for our sanity test purposes.
  153.     //If possible you should handle older versions of the client
  154.     //so this ASSERT(sizeof(CServerObject)==iCServerObject);
  155.     //should not be included at runtime and you may need to remove
  156.     //it for testing purposes to test with different versions of
  157.     //the client
  158.     if (sizeof(CServerObject)!=iCServerObject)
  159.     {
  160.         //ASSERT(sizeof(CServerObject)==iCServerObject);
  161.         return FALSE;
  162.     }
  163.  
  164.     //set the resourceHandle to point to this .DLL
  165.     AfxSetResourceHandle(g_hInstance);
  166.  
  167.     //save the helper function pointers in the
  168.     //global structure.  Need to save these here as the
  169.     // pointer to the WXSINFO structure (pwxs) will be invalid
  170.     //after this function completes.
  171.     wxsinfo.lpfnGetTagS=pwxs->lpfnGetTagS;
  172.     wxsinfo.lpfnGetTableItems=pwxs->lpfnGetTableItems;
  173.     wxsinfo.lpfnSplitStringDash=pwxs->lpfnSplitStringDash;
  174.     wxsinfo.lpfnFixupNumber=pwxs->lpfnFixupNumber;
  175.     wxsinfo.lpfnFindDataField=pwxs->lpfnFindDataField;
  176.     wxsinfo.lpfnGetNumberAndFraction=pwxs->lpfnGetNumberAndFraction;
  177.     wxsinfo.lpfnRegisterFileFormat=pwxs->lpfnRegisterFileFormat;
  178.  
  179.     //store the strings and data into the server object
  180.     //so it can be returned to the client
  181.     srv->m_dwSize=sizeof(CServerObject);
  182.     
  183.     //Server name :Trade PBS
  184.     srv->m_sServerName.LoadString(IDS_NNAME_LOMBARD);    
  185.  
  186.     //Server www address : www.Lombard.com
  187.     srv->m_httpAddress.LoadString(IDS_SSERVER_LOMBARD);
  188.  
  189.     //stock quote format string
  190.     srv->m_httpSQuoteFormat.LoadString(IDS_SSERVER_LOMBARD_REQ);
  191.     
  192.     //option quot format string
  193.     srv->m_httpOQuoteFormat.LoadString(IDS_OSERVER_LOMBARD_REQ);
  194.  
  195.     srv->m_httpGraphFormat.LoadString(IDS_GSERVER_LOMBARD_REQ);
  196.     srv->m_httpNewsFormat="";
  197.     srv->m_httpHistoricalDataFormat="";
  198.     srv->m_httpSTickerLookupFormat.LoadString(IDS_SRV_LOMBARD_TLOOKUP);
  199.     
  200.     //option lookup http address
  201.     srv->m_httpOSymbolLookup.LoadString(IDS_OSRV_LOMBARD_OLOOKUP);
  202.     srv->m_httpStockHomePageFormat="";
  203.  
  204.     //stock parse callback
  205.     srv->m_lpParseCallback=(SERVERPARSE_CALLBACK)ParseLombardSServer;
  206.  
  207.     //option parse callback
  208.     srv->m_lpOParseCallback=(SERVERPARSE_CALLBACK)ParseLombardOServer;
  209.     srv->m_lpStockUpdate=NULL;
  210.  
  211.     //Add this line to enable the tickerbar sample code
  212.     //and add the line containing the SRV_CAP_TICKER and logical or |
  213.     //it with the rest of the capabilities to enable the sample
  214.     //it will display a message after every symbol and after
  215.     //all in a document have been displayed
  216.     //srv->m_lpTickerBar=(SERVERTICKERBAR_CALLBACK)TickerBar;
  217.  
  218.     //server can handle options and stock quotes
  219.     srv->m_srvCaps=CServerObject::SRV_CAP_SQUOTE|
  220.                     CServerObject::SRV_CAP_OQUOTE|
  221.                     CServerObject::SRV_CAP_GRAPH|
  222.                     CServerObject::SRV_CAP_STICKERLOOKUP|
  223.                     CServerObject::SRV_CAP_SETTINGS|
  224.                     CServerObject::SRV_CAP_REQUIRESLOGIN;
  225.     
  226.     //Can add this capability in to enable
  227.     //the ticker bar sample code
  228.     //CServerObject::SRV_CAP_TICKERBAR;
  229.  
  230.  
  231.     srv->m_dwBufferSize=0;    //use default buffer
  232.  
  233.     //if we know we can handle older versions of API with this
  234.     //.DLL we can assign m_fApiVersion=fApiVersion passed in
  235.     //so that the client won't complain about an inproper version
  236.     srv->m_fApiVersion=(float)WXSSERVER_APIVERSION;
  237.  
  238.  
  239.     //DEBUGGING - REMOVE this and add code to handle settings
  240.     srv->m_sUserId="thedoctor";
  241.     srv->m_sPassword="knight";
  242.  
  243.     
  244.     //set the required callbacks
  245.     //these are required when SRV_CAP_SETTINGS flag is set
  246.     srv->m_lpCreateSettings=(SRV_SETTINGSCREATE_CALLBACK)CreateSettings; //CreateSettings
  247.     srv->m_lpDeleteSettings=(SRV_SETTINGSDELETE_CALLBACK)DeleteSettings;    //DeleteSettings
  248.     srv->m_lpEditSettings=(SRV_SETTINGSEDIT_CALLBACK)EditSettings;        //EditSettings
  249.     srv->m_lpGetSettings=(SRV_SETTINGSGET_CALLBACK)GetSettings;        //GetSettings
  250.     
  251.     //must be defined if SRV_CAP_REQUIRESLOGIN flag is
  252.     //set
  253.     srv->m_lpGetUserInfo=(SRV_GETUSERPWD_CALLBACK)GetUserInfo;    //GetUserInfo
  254.  
  255.  
  256.     //restore the resource handle back to the client .DLL
  257.     AfxSetResourceHandle(hInst);
  258.  
  259.     return TRUE;
  260. }
  261.  
  262.  
  263. #define TABLE_ROW    6
  264. #define TABLE_ITEMS 11
  265.  
  266. #define DTABLE_NAME            0
  267. #define    DTABLE_PRICE        1
  268. #define DTABLE_DCHANGE        2
  269. #define    DTABLE_HIGH            3
  270. #define    DTABLE_LOW            4
  271. #define    DTABLE_VOLUME        5
  272. #define    DTABLE_BID            6
  273. #define    DTABLE_ASK            7
  274. #define    DTABLE_52HIGH        8
  275. #define    DTABLE_52LOW        9
  276. #define    DTABLE_LASTUPDATED    10
  277.  
  278.  
  279.  
  280.  
  281. const UINT aTradeItems[TABLE_ITEMS][TABLE_ROW]= {
  282.  
  283.     //object,table,level,subtable,row,column
  284.  
  285.     {DTABLE_NAME,3,0,0,1,1},
  286.     {DTABLE_LASTUPDATED,3,0,0,4,2},
  287.     {DTABLE_PRICE,3,0,0,2,1},
  288.     {DTABLE_DCHANGE,3,0,0,2,2},
  289.     {DTABLE_BID,3,0,0,3,1},        
  290.     {DTABLE_ASK,3,0,0,3,2},        
  291.     {DTABLE_VOLUME,3,0,0,4,1},
  292.     {DTABLE_HIGH,3,0,0,10,2}, 
  293.     {DTABLE_LOW,3,0,0,10,1},
  294.     {DTABLE_52HIGH,10,0,0,2,7}, //no 52high invalid server doesn't support
  295.     {DTABLE_52LOW,10,0,0,2,8}    //no 52low invalid server doesn't support
  296.     
  297. };
  298.  
  299.  
  300. #define TITEM    0
  301. #define TMTABLE    1
  302. #define TLEVEL    2
  303. #define TTABLE    3
  304. #define TROW    4
  305. #define TCOLUMN    5
  306.  
  307.  
  308. struct TRADETABLEDATA {
  309.     CPubSrvStockObj *sobj;
  310.     int iIgnore;
  311.     BOOL bNoBidAsk;
  312. };
  313.  
  314.  
  315. BOOL GetTradeTableCallback(UINT uMTable,UINT uLevel,UINT uSubTable,
  316.                             UINT uRow,UINT uColumn,
  317.                             char *pStart,char *pEnd,LONG lData)
  318. {
  319.  
  320.     int x;
  321.     BOOL bFound=FALSE;
  322.     int bRet=TRUE;
  323.     int iRet=0;
  324.     TRADETABLEDATA *tdp=(TRADETABLEDATA *)lData;
  325.     
  326. #ifdef _DEBUG
  327.     TRACE("Table: %d, Level:%d, SubTable:%d, Row:%d, Column:%d\n",uMTable,uLevel,uSubTable,uRow,uColumn);
  328. #endif
  329.  
  330.     
  331.         
  332.     for (x=0; x<TABLE_ITEMS; x++)
  333.     {
  334.         if (tdp->bNoBidAsk && (DTABLE_BID==aTradeItems[x][TITEM] ||
  335.             DTABLE_ASK==aTradeItems[x][TITEM]))
  336.             continue;
  337.  
  338.         UINT row=aTradeItems[x][TROW];
  339.  
  340.         if (tdp->bNoBidAsk && row>3)
  341.             row--;
  342.  
  343.         if (tdp->bNoBidAsk && row>6)
  344.             row--;
  345.  
  346.         if (aTradeItems[x][TMTABLE]==uMTable &&    //table
  347.             aTradeItems[x][TLEVEL]==uLevel &&    //level
  348.             aTradeItems[x][TTABLE]==uSubTable &&    //subtable
  349.             row==uRow &&        //row
  350.             aTradeItems[x][TCOLUMN]==uColumn)    //column
  351.         {
  352.  
  353.             bFound=TRUE;
  354.             break;
  355.         }
  356.     }
  357.         
  358.     if (!bFound)
  359.         return TRUE;
  360.     
  361.  
  362.     
  363.  
  364.     
  365.     char szTemp[256];
  366.     char szData[256];
  367.     CString sData;
  368.     char *end;
  369.     char *p=pStart;
  370.     float fValue=(float)0.0;
  371.     
  372.     CPubSrvStockObj *sobj=(CPubSrvStockObj *)tdp->sobj;
  373.     int iIgnore=tdp->iIgnore;
  374.  
  375.     sData="";
  376.  
  377.     
  378.  
  379.         
  380.     
  381.     while (NULL!=*p && p<pEnd)
  382.         if (NULL==(p=FindDataField(p,&end)))
  383.         {
  384.         //error getting the number and fraction
  385.         TRACE("Error FindDataField file: %s. FindAndGetNumber Line:%d\n",__FILE__,__LINE__);
  386.         //exit out of switch, no data in field
  387.         } else {
  388.             UINT len=end-p;
  389.             if (end<=pEnd)
  390.             {
  391.                 lstrcpyn(szTemp,p,((len+1) > sizeof(szTemp)) ? sizeof(szTemp) : (len+1));
  392.             sData=sData+szTemp;
  393.             sData=sData+" ";
  394.             }
  395.             p=end;
  396.         }
  397.  
  398.     sData.TrimLeft();
  399.     sData.TrimRight();
  400.  
  401.     lstrcpy(szData,(LPCTSTR)sData);
  402.  
  403.     
  404.     switch (aTradeItems[x][TITEM])
  405.     {
  406.         case    DTABLE_NAME:
  407.             sobj->m_sName.Format("%s",szData);
  408.             break;
  409.  
  410.         case     DTABLE_PRICE:
  411.             fValue=(float)0.0;
  412.             FixupNumber(sData);
  413.             lstrcpy(szData,(LPCTSTR)sData);
  414.             iRet=GetNumberAndFraction(szData,NULL,fValue);
  415.             sobj->m_fPrice=(-1==iRet) ? (float)0.0 : fValue;
  416.             break;
  417.  
  418.         case    DTABLE_DCHANGE:
  419.             {
  420.             CString s;
  421.             s=szData;
  422.  
  423.             fValue=(float)0.0;
  424.             FixupNumber(s);
  425.             lstrcpy(szData,(LPCTSTR)s);
  426.             iRet=GetNumberAndFraction(szData,NULL,fValue);
  427.             sobj->m_fChange=(-1==iRet) ? (float)0.0 : fValue;
  428.             }
  429.             break;
  430.  
  431.         case     DTABLE_HIGH:
  432.             {
  433.             
  434.                 
  435.             fValue=(float)0.0;
  436.             FixupNumber(sData);
  437.  
  438.             lstrcpy(szData,(LPCTSTR)sData);
  439.             iRet=GetNumberAndFraction(szData,NULL,fValue);
  440.             sobj->m_fHigh=(-1==iRet) ? (float)0.0 : fValue;
  441.  
  442.             }
  443.             break;
  444.  
  445.         case     DTABLE_LOW:
  446.             fValue=(float)0.0;
  447.             FixupNumber(sData);
  448.             lstrcpy(szData,(LPCTSTR)sData);
  449.             iRet=GetNumberAndFraction(szData,NULL,fValue);
  450.             sobj->m_fLow=(-1==iRet) ? 0 : fValue;
  451.             break;
  452.  
  453.         case     DTABLE_VOLUME:
  454.             fValue=(float)0.0;
  455.             iRet=GetNumberAndFraction(szData,NULL,fValue);
  456.             sobj->m_nVolume=(-1==iRet) ? 0 : (UINT)fValue;
  457.             break;
  458.  
  459.         case     DTABLE_BID:
  460.             fValue=(float)0.0;
  461.             FixupNumber(sData);
  462.             lstrcpy(szData,(LPCTSTR)sData);
  463.             iRet=GetNumberAndFraction(szData,NULL,fValue);
  464.             sobj->m_fBid=(-1==iRet) ? (float)0.0 : fValue;
  465.             break;
  466.  
  467.         case     DTABLE_ASK:
  468.             fValue=(float)0.0;
  469.             FixupNumber(sData);
  470.             lstrcpy(szData,(LPCTSTR)sData);
  471.             iRet=GetNumberAndFraction(szData,NULL,fValue);
  472.             sobj->m_fAsk=(-1==iRet) ? (float)0.0 : fValue;
  473.             break;
  474.  
  475.         case     DTABLE_52HIGH:
  476.             {
  477.             
  478.                 
  479.             fValue=(float)0.0;
  480.             FixupNumber(sData);
  481.  
  482.             lstrcpy(szData,(LPCTSTR)sData);
  483.             iRet=GetNumberAndFraction(szData,NULL,fValue);
  484.             sobj->m_fYearHigh=(-1==iRet) ? (float)0.0 : fValue;
  485.  
  486.             
  487.             }
  488.             break;
  489.  
  490.         case     DTABLE_52LOW:
  491.             iRet=GetNumberAndFraction(szData,NULL,fValue);
  492.             sobj->m_fYearLow=(-1==iRet) ? (float)0.0 : fValue;
  493.             break;
  494.  
  495.         case     DTABLE_LASTUPDATED:
  496.             //hande time here
  497.             break;
  498.  
  499.     }
  500.     
  501.  
  502.  
  503.     if (-1==iRet)
  504.     {
  505. #ifdef _DEBUG
  506.         TRACE("iRet=-1: item:%d, File: %s, Line:%d\n",aTradeItems[x][TITEM],
  507.             __FILE__,__LINE__);
  508. #endif
  509.         return FALSE; //stop callback and return error
  510.     }
  511.  
  512.     return TRUE;
  513.  
  514. }
  515.  
  516. #define CHECK_NASDAQ    "NASDAQ"
  517.  
  518.  
  519. //handles stock quote parsing
  520. __declspec(dllexport) ParseLombardSServer(char *buffer,
  521.                                            DWORD len,
  522.                                            CPUBSTOCKOBJ &pobjArray,
  523.                                            int iIgnore,CServerObject *srvo)
  524. {
  525.  
  526.  
  527.     CString sTest,sTest2;
  528.     TRADETABLEDATA td;
  529.  
  530.     
  531.     CPubSrvStockObj *sobj=(CPubSrvStockObj *)&pobjArray[0];
  532.     sTest2=sTest=sobj->m_sSymbol;
  533.     sTest.MakeUpper();
  534.     sTest2.MakeLower();
  535.     if (!strstr(buffer,(LPCTSTR)sTest) &&
  536.         !strstr(buffer,(LPCTSTR)sTest2))
  537.     {
  538.         //Probably an error -- could not find the symbol anywhere
  539.         // in the HTML page as upper or lowercase
  540.         TRACE("Initial symbol check. Lombard: File: %s, Line:%d\n",__FILE__,__LINE__);
  541.         return PARSERET_ERROR;
  542.     }
  543.  
  544.     if (!strstr(buffer,CHECK_NASDAQ))
  545.         td.bNoBidAsk=TRUE;
  546.     else
  547.         td.bNoBidAsk=FALSE;
  548.     
  549.     td.sobj=sobj;
  550.     td.iIgnore=iIgnore;
  551.     if (FALSE==GetTableItems(buffer,(GTI_CALLBACK)GetTradeTableCallback,(LONG)&td))
  552.         return PARSERET_ERROR;
  553.  
  554.  
  555.     return PARSERET_OK;
  556.  
  557. }
  558.  
  559.  
  560. //option table format
  561. const UINT aOTradeItems[TABLE_ITEMS][TABLE_ROW]= {
  562.  
  563.     //object,table,level,subtable,row,column
  564.  
  565.     {DTABLE_NAME,3,0,0,1,1},
  566.     {DTABLE_LASTUPDATED,3,0,0,4,2},
  567.     {DTABLE_PRICE,3,0,0,2,1},
  568.     {DTABLE_DCHANGE,3,0,0,2,2},
  569.     {DTABLE_BID,3,0,0,3,1},        
  570.     {DTABLE_ASK,3,0,0,3,2},        
  571.     {DTABLE_VOLUME,3,0,0,4,1},
  572.     {DTABLE_HIGH,3,0,0,10,2}, 
  573.     {DTABLE_LOW,3,0,0,10,1},
  574.     {DTABLE_52HIGH,10,0,0,2,7}, //no 52high invalid server doesn't support
  575.     {DTABLE_52LOW,10,0,0,2,8}    //no 52low invalid server doesn't support
  576.     
  577. };
  578.  
  579.  
  580.  
  581. //Option table callback
  582.  
  583. BOOL GetTradeOTableCallback(UINT uMTable,UINT uLevel,UINT uSubTable,
  584.                             UINT uRow,UINT uColumn,
  585.                             char *pStart,char *pEnd,LONG lData)
  586. {
  587.  
  588.  
  589.         int x;
  590.     BOOL bFound=FALSE;
  591.     int bRet=TRUE;
  592.     int iRet=0;
  593.  
  594.     
  595. #ifdef _DEBUG
  596.     TRACE("Table: %d, Level:%d, SubTable:%d, Row:%d, Column:%d\n",uMTable,uLevel,uSubTable,uRow,uColumn);
  597. #endif
  598.  
  599.     
  600.         
  601.     for (x=0; x<TABLE_ITEMS; x++)
  602.         if (aOTradeItems[x][TMTABLE]==uMTable &&    //table
  603.             aOTradeItems[x][TLEVEL]==uLevel &&    //level
  604.             aOTradeItems[x][TTABLE]==uSubTable &&    //subtable
  605.             aOTradeItems[x][TROW]==uRow &&        //row
  606.             aOTradeItems[x][TCOLUMN]==uColumn)    //column
  607.         {
  608.  
  609.             bFound=TRUE;
  610.             break;
  611.         }
  612.         
  613.     if (!bFound)
  614.         return TRUE;
  615.     
  616.  
  617.     
  618.  
  619.     
  620.     char szTemp[256];
  621.     char szData[256];
  622.     CString sData;
  623.     char *end;
  624.     char *p=pStart;
  625.     float fValue=(float)0.0;
  626.     TRADETABLEDATA *tdp=(TRADETABLEDATA *)lData;
  627.     CPubSrvStockObj *sobj=(CPubSrvStockObj *)tdp->sobj;
  628.     int iIgnore=tdp->iIgnore;
  629.  
  630.     sData="";
  631.  
  632.     
  633.  
  634.         
  635.     
  636.     while (NULL!=*p && p<pEnd)
  637.         if (NULL==(p=FindDataField(p,&end)))
  638.         {
  639.         //error getting the number and fraction
  640.         TRACE("Error FindDataField file: %s. FindAndGetNumber Line:%d\n",__FILE__,__LINE__);
  641.         //exit out of switch, no data in field
  642.         } else {
  643.             UINT len=end-p;
  644.             if (end<=pEnd)
  645.             {
  646.                 lstrcpyn(szTemp,p,((len+1) > sizeof(szTemp)) ? sizeof(szTemp) : (len+1));
  647.             sData=sData+szTemp;
  648.             sData=sData+" ";
  649.             }
  650.             p=end;
  651.         }
  652.  
  653.     sData.TrimLeft();
  654.     sData.TrimRight();
  655.  
  656.     lstrcpy(szData,(LPCTSTR)sData);
  657.  
  658.     
  659.     switch (aTradeItems[x][TITEM])
  660.     {
  661.         case    DTABLE_NAME:
  662.             sobj->m_sName.Format("%s",szData);
  663.             break;
  664.  
  665.         case     DTABLE_PRICE:
  666.             fValue=(float)0.0;
  667.             FixupNumber(sData);
  668.             lstrcpy(szData,(LPCTSTR)sData);
  669.             iRet=GetNumberAndFraction(szData,NULL,fValue);
  670.             sobj->m_fPrice=(-1==iRet) ? (float)0.0 : fValue;
  671.             break;
  672.  
  673.         case    DTABLE_DCHANGE:
  674.             {
  675.             CString s;
  676.             s=szData;
  677.  
  678.             fValue=(float)0.0;
  679.             FixupNumber(s);
  680.             lstrcpy(szData,(LPCTSTR)s);
  681.             iRet=GetNumberAndFraction(szData,NULL,fValue);
  682.             sobj->m_fChange=(-1==iRet) ? (float)0.0 : fValue;
  683.             }
  684.             break;
  685.  
  686.         case     DTABLE_HIGH:
  687.             {
  688.             
  689.                 
  690.             fValue=(float)0.0;
  691.             FixupNumber(sData);
  692.  
  693.             lstrcpy(szData,(LPCTSTR)sData);
  694.             iRet=GetNumberAndFraction(szData,NULL,fValue);
  695.             sobj->m_fHigh=(-1==iRet) ? (float)0.0 : fValue;
  696.  
  697.             }
  698.             break;
  699.  
  700.         case     DTABLE_LOW:
  701.             fValue=(float)0.0;
  702.             FixupNumber(sData);
  703.             lstrcpy(szData,(LPCTSTR)sData);
  704.             iRet=GetNumberAndFraction(szData,NULL,fValue);
  705.             sobj->m_fLow=(-1==iRet) ? 0 : fValue;
  706.             break;
  707.  
  708.         case     DTABLE_VOLUME:
  709.             fValue=(float)0.0;
  710.             iRet=GetNumberAndFraction(szData,NULL,fValue);
  711.             sobj->m_nVolume=(-1==iRet) ? 0 : (UINT)fValue;
  712.             break;
  713.  
  714.         case     DTABLE_BID:
  715.             fValue=(float)0.0;
  716.             FixupNumber(sData);
  717.             lstrcpy(szData,(LPCTSTR)sData);
  718.             iRet=GetNumberAndFraction(szData,NULL,fValue);
  719.             sobj->m_fBid=(-1==iRet) ? (float)0.0 : fValue;
  720.             break;
  721.  
  722.         case     DTABLE_ASK:
  723.             fValue=(float)0.0;
  724.             FixupNumber(sData);
  725.             lstrcpy(szData,(LPCTSTR)sData);
  726.             iRet=GetNumberAndFraction(szData,NULL,fValue);
  727.             sobj->m_fAsk=(-1==iRet) ? (float)0.0 : fValue;
  728.             break;
  729.  
  730.         case     DTABLE_52HIGH:
  731.             {
  732.             
  733.                 
  734.             fValue=(float)0.0;
  735.             FixupNumber(sData);
  736.  
  737.             lstrcpy(szData,(LPCTSTR)sData);
  738.             iRet=GetNumberAndFraction(szData,NULL,fValue);
  739.             sobj->m_fYearHigh=(-1==iRet) ? (float)0.0 : fValue;
  740.  
  741.             
  742.             }
  743.             break;
  744.  
  745.         case     DTABLE_52LOW:
  746.             iRet=GetNumberAndFraction(szData,NULL,fValue);
  747.             sobj->m_fYearLow=(-1==iRet) ? (float)0.0 : fValue;
  748.             break;
  749.  
  750.         case     DTABLE_LASTUPDATED:
  751.             //hande time here
  752.             break;
  753.  
  754.     }
  755.     
  756.  
  757.  
  758.     if (-1==iRet)
  759.     {
  760. #ifdef _DEBUG
  761.         TRACE("iRet=-1: item:%d, File: %s, Line:%d\n",aTradeItems[x][TITEM],
  762.             __FILE__,__LINE__);
  763. #endif
  764.         return FALSE; //stop callback and return error
  765.     }
  766.  
  767.     return TRUE;
  768.  
  769.  
  770.  
  771.  
  772. }
  773.  
  774.  
  775. //Handles Option Parsing
  776. __declspec(dllexport) ParseLombardOServer(char *buffer,
  777.                                            DWORD len,
  778.                                            CPUBSTOCKOBJ &pobjArray,
  779.                                            int iIgnore,CServerObject *srvo)
  780. {
  781.  
  782.         CString sTest,sTest2;
  783.     TRADETABLEDATA td;
  784.  
  785.     
  786.     CPubSrvStockObj *sobj=(CPubSrvStockObj *)&pobjArray[0];
  787.     sTest2=sTest=sobj->m_sSymbol;
  788.     sTest.MakeUpper();
  789.     sTest2.MakeLower();
  790.     if (!strstr(buffer,(LPCTSTR)sTest) &&
  791.         !strstr(buffer,(LPCTSTR)sTest2))
  792.     {
  793.         //Probably an error -- could not find the symbol anywhere
  794.         // in the HTML page as upper or lowercase
  795.         TRACE("Initial symbol check. Lombard: File: %s, Line:%d\n",__FILE__,__LINE__);
  796.         return PARSERET_ERROR;
  797.     }
  798.     
  799.     td.sobj=sobj;
  800.     td.iIgnore=iIgnore;
  801.     if (FALSE==GetTableItems(buffer,(GTI_CALLBACK)GetTradeOTableCallback,(LONG)&td))
  802.         return PARSERET_ERROR;
  803.  
  804.  
  805.     return PARSERET_OK;
  806.  
  807.  
  808.  
  809. }
  810.  
  811.  
  812. #define SIZE_STRINGID    10
  813. #define LOMBARDID_STRINGID    "LOMBARD"
  814.  
  815. #define SIZE_CHARARRAYS    128
  816.  
  817.  
  818. typedef struct {
  819.     char szID[SIZE_STRINGID];
  820.  
  821.     char szUser[SIZE_CHARARRAYS];
  822.     char szPassword[SIZE_CHARARRAYS];
  823.  
  824. } LOMBARDSETTINGS; 
  825.  
  826. //settings functions
  827. __declspec(dllexport) DWORD CreateSettings(void *buffer,DWORD len)
  828. {
  829.     LOMBARDSETTINGS *pls;
  830.     DWORD dwRet=0;
  831.  
  832.     if (NULL==buffer)
  833.     {
  834.         pls=new LOMBARDSETTINGS;
  835.         lstrcpy(pls->szID,LOMBARDID_STRINGID);
  836.         pls->szUser[0]=NULL;
  837.         pls->szPassword[0]=NULL;
  838.  
  839.         dwRet=(DWORD)pls;
  840.  
  841.     } else {
  842.         if (sizeof(LOMBARDSETTINGS)!=len)
  843.         {
  844.             //probably an error, or wrong version
  845.             return 0;
  846.         }
  847.  
  848.         //can compare szID here with LOMBARDID_STRINGID
  849.  
  850.         pls=(LOMBARDSETTINGS *)buffer;
  851.         
  852.         dwRet=(DWORD)pls;
  853.  
  854.     }
  855.  
  856.     return dwRet;
  857. }
  858.  
  859. __declspec(dllexport) BOOL DeleteSettings(DWORD dwSettings)
  860. {
  861.  
  862.     LOMBARDSETTINGS *pls;
  863.  
  864.     if (0==dwSettings)
  865.         return FALSE;
  866.  
  867.     pls=(LOMBARDSETTINGS *)dwSettings;
  868.  
  869.     delete pls;
  870.  
  871.     return TRUE;
  872. }
  873.  
  874. __declspec(dllexport) DWORD EditSettings(DWORD dwSettings,int iWhichSetting)
  875. {
  876.     DWORD dwRet=0;
  877.  
  878.     if (0==dwSettings)
  879.     {
  880.         dwRet=CreateSettings(NULL,0);    
  881.         dwSettings=dwRet;
  882.     }
  883.  
  884.     LOMBARDSETTINGS *pls=(LOMBARDSETTINGS *)dwSettings;
  885.     
  886.     //NOTE: we are ignore iWhichSetting
  887.     //since the only setting supported is a password
  888.     CPasswordDlg dlg;
  889.  
  890.     dlg.m_sUser=pls->szUser;
  891.     dlg.m_sPass=dlg.m_sPass2=pls->szPassword;
  892.  
  893.     if (IDOK==dlg.DoModal())
  894.     {
  895.         lstrcpy(pls->szUser,(LPCTSTR)dlg.m_sUser);
  896.         lstrcpy(pls->szPassword,(LPCTSTR)dlg.m_sPass);
  897.     }
  898.  
  899.  
  900.     
  901.     return dwSettings;
  902.  
  903. }
  904.  
  905.  
  906. __declspec(dllexport) DWORD GetSettings(DWORD dwSettings,
  907.                                         void **lpBuf,LPDWORD lpdwSize)
  908. {
  909.  
  910.     if (0==dwSettings)
  911.     {
  912.         *lpBuf=NULL;
  913.         *lpdwSize=0;
  914.         return 0;
  915.     }
  916.  
  917.     LOMBARDSETTINGS *pls=(LOMBARDSETTINGS *)dwSettings;
  918.  
  919.     //point to the buffer containing the information
  920.     *lpBuf=pls;
  921.  
  922.     *lpdwSize=sizeof(LOMBARDSETTINGS);
  923.  
  924.     return dwSettings;
  925. }
  926.  
  927.  
  928. __declspec(dllexport) DWORD GetUserInfo(DWORD dwSettings,
  929.                                          CString &sUsername,
  930.                                          CString &sPassword)
  931. {
  932.     if (0==dwSettings)
  933.     {
  934.         //no settings
  935.         //return
  936.         sUsername="";
  937.         sPassword="";
  938.         
  939.         return dwSettings;
  940.     }
  941.  
  942.     LOMBARDSETTINGS *pls=(LOMBARDSETTINGS *)dwSettings;
  943.  
  944.     sUsername=pls->szUser;
  945.     sPassword=pls->szPassword;
  946.  
  947.     return dwSettings;
  948. }
  949.  
  950.  
  951. //tickerbar callback.  Return TRUE if we wanted to add an item
  952. __declspec(dllexport) BOOL TickerBar(DWORD dwSettings,DWORD dwFlag,
  953.                                                   CPubDrawObject *dobj)
  954. {
  955.     if (TICKERBAR_FLAG_SYMBOL==dwFlag)
  956.     {
  957.         dobj->m_str="Found Symbol:"+dobj->m_sSymbol;
  958.         return TRUE;
  959.  
  960.  
  961.     } else 
  962.         if (TICKERBAR_FLAG_ENDALL==dwFlag)
  963.         {
  964.             dobj->m_str="End of all items";
  965.             return TRUE;
  966.  
  967.  
  968.         }
  969.  
  970.  
  971.     return FALSE;
  972. }
  973.  
  974.