home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / cxnet1.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.7 KB  |  170 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "cxstubs.h"
  20.  
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CNetworkCX command target
  23.  
  24. class CNetworkCX : public CCmdTarget, public CStubsCX
  25. {
  26.     DECLARE_DYNCREATE(CNetworkCX)
  27. protected:
  28.     CNetworkCX();           // protected constructor used by dynamic creation
  29.  
  30. // Attributes
  31. private:
  32.     URL_Struct *m_pUrlData;    //    The url to load.
  33.     BOOL m_bStreamComplete;    //    Wether or not the load is completed.
  34.  
  35.     BOOL m_bShowAllNews;    //    Wether or not to show all news articles.
  36.     BOOL m_bFancyNews;        //    Wether or not to use Fancy News.
  37.     BOOL m_bFancyFTP;        //    Wether or not to use Fancy FTP.
  38.     CString m_csUsername;    //    The registered user name.
  39.     CString m_csPassword;    //    The registered password.
  40.  
  41.     enum    {
  42.         m_OK = 0x0000,        //    Data is loaded ok
  43.         m_USER = 0x0001,    //    User name requested, may have still loaded if supplied
  44.         m_PASS = 0x0002,    //    User password requested, may have still loaded if supplied
  45.         m_BUSY = 0x0100,    //    Busy, try back later
  46.         m_SRVR = 0x0200,    //    Server reported an irregular status, probably an error.
  47.         m_INTL = 0x0400,    //    Internal loading error, never got to server.
  48.         m_ERRS = 0x0800        //    A helpful error string is available provided by Netscape.
  49.     };
  50.     long m_lFlags;    //    Some status flags, to mark what happened, to help caller figure out what went wrong.
  51.     CString m_csErrorMessage;
  52.  
  53. //    Read buffers to store data as it comes in.
  54. private:
  55.     CPtrList m_cplBuffers;
  56.  
  57. public:
  58.     char *AllocUsername();
  59.     char *AllocPassword();
  60.     void SetPasswordRequested()    {
  61.         m_lFlags |= m_PASS;
  62.     }
  63.     void SetUsernameRequested()    {
  64.         m_lFlags |= m_USER;
  65.     }
  66.  
  67. // Operations
  68. public:
  69.     int StreamWrite(const char *pWriteData, int32 lLength);
  70.     void StreamComplete();
  71.     void StreamAbort(int iStatus);
  72.     unsigned int StreamReady();
  73.  
  74. //    Context overrides
  75. public:
  76.     virtual void Alert(MWContext *pContext, const char *pMessage);
  77.     virtual XP_Bool Confirm(MWContext *pContext, const char *pConfirmMessage);
  78.     virtual char *Prompt(MWContext *pContext, const char *pPrompt, const char *pDefault);
  79.     virtual char *PromptPassword(MWContext *pContext, const char *pMessage);
  80.     virtual XP_Bool PromptUsernameAndPassword(MWContext *pContext, const char *pMessage, char **ppUsername, char **ppPassword);
  81.     virtual XP_Bool ShowAllNewsArticles(MWContext *pContext);
  82.     virtual XP_Bool UseFancyFTP(MWContext *pContext);
  83.     virtual XP_Bool UseFancyNewsgroupListing(MWContext *pContext);
  84.  
  85.     virtual void GetUrlExitRoutine(URL_Struct *pUrl, int iStatus, MWContext *pContext);
  86.  
  87. // Overrides
  88.     // ClassWizard generated virtual function overrides
  89.     //{{AFX_VIRTUAL(CNetworkCX)
  90.     public:
  91.     virtual void OnFinalRelease();
  92.     //}}AFX_VIRTUAL
  93.  
  94. // Implementation
  95. protected:
  96.     virtual ~CNetworkCX();
  97.  
  98.     // Generated message map functions
  99.     //{{AFX_MSG(CNetworkCX)
  100.         // NOTE - the ClassWizard will add and remove member functions here.
  101.     //}}AFX_MSG
  102.  
  103.     DECLARE_MESSAGE_MAP()
  104.     DECLARE_OLECREATE(CNetworkCX)
  105.  
  106.     // Generated OLE dispatch map functions
  107.     //{{AFX_DISPATCH(CNetworkCX)
  108.     afx_msg BSTR GetUsername();
  109.     afx_msg void SetUsername(LPCTSTR lpszNewValue);
  110.     afx_msg BSTR GetPassword();
  111.     afx_msg void SetPassword(LPCTSTR lpszNewValue);
  112.     afx_msg BOOL GetFlagShowAllNews();
  113.     afx_msg void SetFlagShowAllNews(BOOL bNewValue);
  114.     afx_msg BOOL GetFlagFancyFTP();
  115.     afx_msg void SetFlagFancyFTP(BOOL bNewValue);
  116.     afx_msg BOOL GetFlagFancyNews();
  117.     afx_msg void SetFlagFancyNews(BOOL bNewValue);
  118.     afx_msg void Close();
  119.     afx_msg short Read(BSTR FAR* pBuffer, short iAmount);
  120.     afx_msg long GetStatus();
  121.     afx_msg BOOL Open(LPCTSTR pURL, short iMethod, LPCTSTR pPostData, long lPostDataSize, LPCTSTR pPostHeaders);
  122.     afx_msg BSTR GetErrorMessage();
  123.     afx_msg short GetServerStatus();
  124.     afx_msg long GetContentLength();
  125.     afx_msg BSTR GetContentType();
  126.     afx_msg BSTR GetContentEncoding();
  127.     afx_msg BSTR GetExpires();
  128.     afx_msg BSTR GetLastModified();
  129.     afx_msg BSTR Resolve(LPCTSTR pBase, LPCTSTR pRelative);
  130.     afx_msg BOOL IsFinished();
  131.     afx_msg short BytesReady();
  132.     //}}AFX_DISPATCH
  133.     DECLARE_DISPATCH_MAP()
  134. };
  135.  
  136. /////////////////////////////////////////////////////////////////////////////
  137. //    Miscellaneous Functions
  138. extern "C"    {
  139. NET_StreamClass *nfe_OleStream(int iFormatOut, void *pDataObj, URL_Struct *pUrlData, MWContext *pContext);
  140. int nfe_StreamWrite(NET_StreamClass *stream, const char *pWriteData, int32 lLength);
  141. void nfe_StreamComplete(NET_StreamClass *stream);
  142. void nfe_StreamAbort(NET_StreamClass *stream, int iStatus);
  143. unsigned int nfe_StreamReady(NET_StreamClass *stream);
  144. };
  145.  
  146.  
  147. //    Max amount of data to store in each CNetBuffer.
  148. #define NETBUFSIZE (30 * 1024)
  149.  
  150. //    Structure to store read data.
  151. struct CNetBuffer    {
  152.     int m_iHead;
  153.     int m_iSize;
  154.     char *m_pData;
  155.  
  156.     CNetBuffer(int iSize)    {
  157.         ASSERT(iSize);
  158.         m_iHead = 0;
  159.         m_iSize = iSize;
  160.         m_pData = new char[iSize];
  161.     }
  162.     ~CNetBuffer()    {
  163.         if(m_pData)    {
  164.             delete m_pData;
  165.         }
  166.     }
  167. };
  168.  
  169. /////////////////////////////////////////////////////////////////////////////
  170.