Microsoft Chat Server Development Guide

MessageFilter.h

// CHATSDK:
// This  class implements the interfaces required to be 
// a chat extension.  It also supports an
// interface IChatMsgFilter for the administration property page 
//
// MessageFilter.h : Declaration of the CMessageFilter

#ifndef __MESSAGEFILTER_H_
#define __MESSAGEFILTER_H_

#include "resource.h"       // main symbols

// include the STL library for vectors into our current namespace
#include "vector"
#include "algorithm"
using namespace std;

// hide the 'identifier names are too long' warning
#pragma warning(disable:4786)


/////////////////////////////////////////////////////////////////////////////
// CMessageFilter
class ATL_NO_VTABLE CMessageFilter : 
    public CComObjectRootEx<CComSingleThreadModel>,
    public CComCoClass<CMessageFilter, &CLSID_MessageFilter>,
    public IDispatchImpl<IChatMsgFilter, &IID_IChatMsgFilter, &LIBID_MSGFILTERLib>,

    // CHATSDK: Add support for the chat callbacks 
    public IDispatchImpl<IChatExtensionCallBack, &IID_IChatExtensionCallBack, &LIBID_CHATSVCLib>,
    public IDispatchImpl<IChatServerCallBack, &IID_IChatServerCallBack, &LIBID_CHATSVCLib>,
    public IDispatchImpl<IChatUserCallBack, &IID_IChatServerCallBack, &LIBID_CHATSVCLib>,
    public IDispatchImpl<IChatChannelCallBack, &IID_IChatServerCallBack, &LIBID_CHATSVCLib>,

    // CHATSDK: To keep things simple, this object also supports the ISpecifyPropertyPages
    // as required to get to the property page for this extension
    public ISpecifyPropertyPagesImpl<CMessageFilter>
{
public:
    CMessageFilter() {
        m_pRegistrar = NULL;
    }

    // CHATSDK: Add to the .RGS file the chat CATID registration
    DECLARE_REGISTRY_RESOURCEID(IDR_MESSAGEFILTER)

    DECLARE_NOT_AGGREGATABLE(CMessageFilter)

    BEGIN_COM_MAP(CMessageFilter)
        // Keep the default interfaces to allow the property page 
        // to access it and the configuration data.
        // Promote it's IDispatch using ENTRY2 
        COM_INTERFACE_ENTRY2(IDispatch, IChatMsgFilter)
        COM_INTERFACE_ENTRY(IChatMsgFilter)

        // CHATSDK: Add entries for the chat callbacks
        COM_INTERFACE_ENTRY(IChatExtensionCallBack)
        COM_INTERFACE_ENTRY(IChatServerCallBack)
        COM_INTERFACE_ENTRY(IChatUserCallBack)
        COM_INTERFACE_ENTRY(IChatChannelCallBack)

        // CHATSDK: add entry to support the ISpecifyPropertyPages
        COM_INTERFACE_ENTRY_IMPL(ISpecifyPropertyPages)
    END_COM_MAP()


    // CHATSDK: Add the PropertyPage Map for our property pages
    BEGIN_PROPERTY_MAP(CMessageFilter)
        PROP_PAGE(CLSID_MsgFilterPP)
    END_PROPERTY_MAP()


public:
    // CHATTSDK: Override default implementation for GetPages
    HRESULT ISpecifyPropertyPages_GetPages(CAUUID* pPages, ATL_PROPMAP_ENTRY* pMap);

    // CHATSDK: IChatMsgFilter - allow the property page acces to our configuration data
    STDMETHOD(Add)(BSTR Message);
    STDMETHOD(get_Count)(/*[out, retval]*/ int *pVal);
    STDMETHOD(get_Item)(int Index, /*[out, retval]*/ BSTR *pVal);

    // CHATSDK: IChatExtensionCallback methods
    STDMETHOD(OnInstall)(void) 
        { return E_NOTIMPL; }
    STDMETHOD(OnUninstall)(void) 
        { return E_NOTIMPL; }
    STDMETHOD(OnConfigureExtension)(IChatUser *pUser,BSTR bstrCommand) 
        { return E_NOTIMPL; }
    STDMETHOD(OnGetPropertyPageClass)(PPAGE Class, BSTR *pbstrCLSID);
        // This extension implements this method
    STDMETHOD(get_Name)(BSTR *pbstrName);
        // This extension implements this method
    STDMETHOD(Init)(IChatServer *pServer, IChatRegistrar* pRegistrar, long *Result);
        // This extension implements this method
    STDMETHOD(Term)(long *Result) 
        { return E_NOTIMPL; }


    // CHATSDK: IChatServerCallback methods
    STDMETHOD(OnNewUser)(IChatUser *pUser, VARIANT_BOOL varbPostUpdate, long *pfCancel)
        { return E_NOTIMPL; }
    STDMETHOD(OnCloseUser)(IChatUser *pUser) 
        { return E_NOTIMPL; }
    STDMETHOD(OnNewChannel)(IChatChannel *pChannel, VARIANT_BOOL PostUpdate, long *pfCancel);
        // This extension implements this method
    STDMETHOD(OnCloseChannel)(IChatChannel *pChannel) 
        { return E_NOTIMPL; }
    STDMETHOD(OnAddAccess)(IChatServer *pServer, IChatAccessEntry *paeNewEntry, VARIANT_BOOL varbPostUpdate, long *plCancel) 
        { return E_NOTIMPL; }
    STDMETHOD(OnRemoveAccess)(IChatServer *pServer, IChatAccessEntry *paeRemovedEntry) 
        { return E_NOTIMPL; }


    // CHATSDK: IChatChannelCallback methods
    STDMETHOD(OnChannelPropertyChanged)(IChatChannel  *pChannel, CHANPROP chanProp, VARIANT  *pvarValue, VARIANT_BOOL varbPostUpdate, long  *pfCancel) 
        { return E_NOTIMPL; }
    STDMETHOD(OnChannelText)(IChatChannel *Channel, IChatUser *User, IRCCMDTYPE Type, BSTR *Message, VARIANT_BOOL varbPostUpdate, long *Cancel);
        // This extension implements this method 
    STDMETHOD(OnAddMember)(IChatChannel *pChannel, IChatUser *pUser, VARIANT_BOOL varbPostUpdate, long *pfCancel) 
        { return E_NOTIMPL; }
    STDMETHOD(OnChangedMember)(IChatChannel *pChannel, IChatUser *pUser, CHATUSERMODE  Mode, VARIANT *pvarValue, VARIANT_BOOL varbPostUpdate, long *pfCancel) 
        { return E_NOTIMPL; }
    STDMETHOD(OnRemoveMember)(IChatChannel *pChannel, IChatUser *pUser) 
        { return E_NOTIMPL; }
    STDMETHOD(OnAddAccess)(IChatChannel *pChannel, IChatAccessEntry *pAccess, VARIANT_BOOL varbPostUpdate, long *pfCancel) 
        { return E_NOTIMPL; }
    STDMETHOD(OnRemoveAccess)(IChatChannel *pChannel, IChatAccessEntry *pAccess) 
        { return E_NOTIMPL; }


    // CHATSDK: IChatUserCallback methods
    STDMETHOD(OnNickChanged)(IChatUser *User, BSTR *Nick, VARIANT_BOOL PostUpdate, long *Cancel) 
        { return E_NOTIMPL; }
    STDMETHOD(OnAwayChanged)(IChatUser *User, BSTR *Away, VARIANT_BOOL PostUpdate, long *Cancel) 
        { return E_NOTIMPL; }
    STDMETHOD(OnProtocolMessageIn)(IChatUser *User, BSTR *Message, VARIANT_BOOL PostUpdate, long *Cancel)
        { return E_NOTIMPL; }
    STDMETHOD(OnProtocolMessageOut)(IChatUser *User, BSTR *Message, VARIANT_BOOL PostUpdate, long *Cancel) 
        { return E_NOTIMPL; }
    STDMETHOD(OnPrivateText)(IChatUser *UserFrom, IChatUser *UserTo, IRCCMDTYPE Type, BSTR *Message, VARIANT_BOOL PostUpdate, long *Cancel) 
        { return E_NOTIMPL; }
    STDMETHOD(OnUserPropertyChanged)(IChatUser  *pUser, USERPROP userProp, VARIANT  *pvarValue, VARIANT_BOOL varbPostUpdate, long *pfCancel) 
        { return E_NOTIMPL; }
    STDMETHOD(OnAddChannel)(IChatUser *pUser, IChatChannel *pChannel, VARIANT_BOOL varbPostUpdate, long *pfCancel) 
        { return E_NOTIMPL; }
    STDMETHOD(OnRemoveChannel)(IChatUser  *pUser, IChatChannel *pChannel) 
        { return E_NOTIMPL; }
    STDMETHOD(OnAddAccess)(IChatUser *pUser, IChatAccessEntry  *pAccess, VARIANT_BOOL varbPostUpdate, long  *pfCancel) 
        { return E_NOTIMPL; }
    STDMETHOD(OnRemoveAccess)(IChatUser  *pUser, IChatAccessEntry  *pAccess) 
        { return E_NOTIMPL; }

private:
    // Array of filtered words
    typedef vector<CComBSTR> WORDLIST;
    WORDLIST m_FilteredWords;

    // Keep a reference to the Chat Registrar object
    CComPtr<IChatRegistrar> m_pRegistrar;        
};

#endif //__MESSAGEFILTER_H_

© 1998 Microsoft Corporation. All rights reserved.