/***************************************************************************
 *                          Zanoza Modeler v2.x                            *
 *      This is unpublished propietary source code of Zanoza Software.     *
 *      The copyright notice does not evidence any actual or intended      *
 *                    publication of such source code.                     *
 *                                                                         *
 *                Copyright (c) 2002-2008 Zanoza Software.                 *
 *                                                                         *
 *                        All rights reserved.                             *
 ***************************************************************************
 *--------------------------------------------------------------------------
 * @author:   Oleg Melashenko
 *--------------------------------------------------------------------------
 * @purpose:  Declaration of the class ICodeLibrary
 *   hidden interface for storing code in library, patching library with regcode,
 *   verification of regcode etc.
 *--------------------------------------------------------------------------
 * @created: Saturday, January 29, 2005 23:47:13
 */

#if !defined(ICodeLibrary_h_included)
#define ICodeLibrary_h_included
//forward declaration of this class might require
namespace secure
{ class ICodeLibrary; };
#include <zmodeler.h>

#include <core/INamed.h>


namespace secure
{
    // registration code info: 16 bytes
    struct tRegCode
    {
      // bits   | meaning
      // 0-3      code evalution. Currently 0001b
      // 4-15     days since selling were stared (must not exceed a 
      //          dramatically high value (e.g. expected to be less than 2000
      //          of upto 4096 possible values)
      // 16-17    damaging selection instruction.
      // 18-19  | XOR over first two bits of m_dwReg to make it ready
      //          to decode m_dwPatch
      // 20-31  | reserved
      DWORD   m_dwInfo;
      //
      // any random seed value for encryption
      DWORD   m_dwSeed;
      //
      // verification code for a seed above;
      DWORD   m_dwReg;
      //
      // patch value encrypted with verification code above;
      DWORD   m_dwPatch;
    };
  class ICodeLibrary : public ZUnknown
  {
  public:
    virtual ZRESULT setCurrentRegCode(tRegCode& code)=0;
    virtual ZRESULT setSearchID(DWORD* pID)=0;
    virtual ZRESULT getSearchID(DWORD* pID)=0;
    virtual ZRESULT decodeString(const char* str, tRegCode& code)=0;
    virtual ZRESULT encodeString(tRegCode& code, ZString& str)=0;
    virtual ZRESULT isAllowedActivity(core::INamed* pNamed)=0;
    virtual ZRESULT getRegCodeDaysPeriod(short& nDays)=0;
    virtual ZRESULT decode(DWORD& dwCmd, DWORD& dwValue)=0;
    virtual ZRESULT encode(DWORD& dwCmd, DWORD& dwValue)=0;
    virtual ZRESULT setCodeLibLocation(LPCTSTR pszPathName)=0;
    virtual ZRESULT getCodeLibLocation(ZString& strPathName)=0;
    virtual ZRESULT getCodeBase(DWORD& dwMagic, BYTE& bSeal, BYTE& bCrc)=0;
    /* if nBit2Change==0, add supplied code to blacklist */
    virtual ZRESULT codeBlackListing(tRegCode& code, DWORD& dwIndicator, BYTE nBit2Change)=0;
  
  };//class ICodeLibrary
};//secure

#endif
