############################################################################
##
## Copyright (c) 2000-2001 BalaBit IT Ltd, Budapest, Hungary
## All rights reserved.
##
## $Id: Zorp.py,v 1.27.2.5.2.2 2001/09/04 09:42:56 bazsi Exp $
##
## Author  : Bazsi
## Auditor : kisza
## Last version: 1.8
## Notes:
##   - comments in English
##
############################################################################

"""Module defining global constants, and interface entry points to the Zorp core.

This module defines some global constants used by other Zorp components like
'TRUE' and 'FALSE', and interface entry points to the Zorp core.
"""

firewall_name = "zorp" # should be unique, proposed name format: zorp@domain
settings = {}          # configuration is stored in this hash

CORE_SESSION = "core.session"
CORE_DEBUG = "core.debug"
CORE_ERROR = "core.error"
CORE_POLICY = "core.policy"
CORE_MESSAGE = "core.message"
CORE_AUTH = "core.auth"

# return values returned by event handlers
Z_UNSPEC	 = 0
Z_ACCEPT	 = 1
Z_DENY		 = 2
Z_REJECT	 = 3
Z_ABORT          = 4
Z_DROP		 = 5
Z_POLICY         = 6

# log levels
Z_ERROR		 = 4
Z_CRITICAL 	 = 8
Z_WARNING 	 = 16
Z_MESSAGE 	 = 32
Z_INFO 		 = 64
Z_DEBUG          = 128

# boolean values
FALSE = 0
TRUE = 1

# address families
AF_UNSPEC = 0
AF_INET = 2

ZoneException = "Zone not found"
ServiceException = "Service"
DACException = "DAC policy violation"
MACException = "MAC policy violation"
AuthException = "Authenticated failed"
LimitException = "Limit error"
InternalError = "Internal error occured"


def error(level, msg):
	"""Logs an error message

	Sends the given message to the low level Zorp provided
	log function.
	
	  Note 
	  
	    This function is obsolete and should not be used.
		
	Arguments

	  level	 -- log level
	  
	  msg    -- message

	
	"""
	log(CORE_ERROR, level, msg)

def message(level, msg):
	"""Logs an informational message

	Sends the given message to the low level Zorp provided
	log function.

	  Note 
	    
	    This function is obsolete and should not be used.

	Arguments
	
	  level -- log level
	  
	  msg   -- message
	"""
	log(CORE_MESSAGE, level, msg)

def debug(level, msg):
	"""Logs a debug message.

	Sends the given message to the low level Zorp provided
	log function.

	  Note 
	  
	    this function is obsolete and should not be used.

	Arguments
	
	  level  -- log level
	  
	  msg    -- message
	  
	"""
	log(CORE_DEBUG, level, msg)
	
def init(name):
	"""Default init() function provided by Zorp
	
	This function is a default init() calling the init function
	identified by name. This way several Zorp instances can easily
	use the same policy file.

	Arguments
	
	  name -- name of this instance
	"""
	import __main__
	try:
		func = getattr(__main__, name)
	except AttributeError:
		log(CORE_ERROR, 0, "Instance definition not found in policy.")
	func()

		
def log(logclass, verbosity, msg):
	"""Entry point of Zorp logging subsystem.
	
	This function is implemented in C, and can be used to inject
	messages into Zorp logging subsystem.

	Arguments

	  logclass -- hierarchical log class as described in zorp(8)
	  
	  verbosity -- verbosity of this message

	  msg -- message
	"""
	pass

class ZorpProxy:
	"""Builtin interface for proxies implemented in C.
	
	Builtin class for proxies implemented as an ExtensionClass in C
	
	This class should not be used directly, derive classes
	from Proxy.Proxy.
	  
	"""
	def __init__(self, name, session_id, client_stream):
		"""Initialize a low level proxy instance.

		This function is implemented in C, and is responsible
		of loading the needed proxy module from a shared object
		if it has not yet been loaded, and starting a new
		instance with parameters passed here.
		
		Arguments

		  self          -- this instance
		
		  name          -- proxy module name ('http', 'plug' etc.)
		  
		  session_id    -- session id to use in log messages
		  
		  client_stream -- client stream
		  
		"""
		pass
