2 * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
3 * All rights reserved. The file named COPYRIGHT specifies the terms
4 * and conditions for redistribution.
14 extern struct xlog_ops __xlog_filelog_ops ;
16 extern struct xlog_ops __xlog_syslog_ops ;
21 struct xlog_ops *ops ;
25 static struct lookup_table ops_lookup_table[] =
27 { &__xlog_filelog_ops, XLOG_FILELOG },
29 { &__xlog_syslog_ops, XLOG_SYSLOG },
35 #define CALLBACK( xp, status ) \
36 if ( (xp)->xl_callback ) \
37 (*(xp)->xl_callback)( (xlog_h)(xp), status, (xp)->xl_callback_arg )
40 static void xlog_link( xlog_s *client, xlog_s *server ) ;
41 static void xlog_unlink( xlog_s *xp ) ;
44 static struct xlog_ops *xlog_ops_lookup( xlog_e type )
46 struct lookup_table *ltp ;
48 for ( ltp = &ops_lookup_table[ 0 ] ; ltp->ops ; ltp++ )
49 if ( ltp->type == type )
56 xlog_h xlog_create( xlog_e type, const char *id, int flags, ... )
60 struct xlog_ops *xops ;
63 if ( ( xp = NEW( xlog_s ) ) == NULL )
66 if ( id == NULL || ( xp->xl_id = __xlog_new_string( id ) ) == NULL )
72 xops = xlog_ops_lookup( type ) ;
76 va_start( ap, flags ) ;
78 status = XL_INIT( xp, ap ) ;
81 if ( status == XLOG_ENOERROR )
83 xp->xl_flags = flags ;
85 xp->xl_clients = XLOG_NULL ;
86 xp->xl_use = XLOG_NULL ;
87 return( (xlog_h) xp ) ;
98 static void xlog_link( xlog_s *client, xlog_s *server )
100 client->xl_use = server ;
101 if ( server == NULL )
104 if ( server->xl_clients == XLOG_NULL )
106 INIT_LINKS( client, xl_other_users ) ;
107 server->xl_clients = client ;
110 LINK( server, client, xl_other_users ) ;
114 static void xlog_unlink( xlog_s *xp )
116 xlog_s *server = xp->xl_use ;
119 * Step 1: remove from server chain
121 if ( server != XLOG_NULL )
123 if ( server->xl_clients == xp )
124 if ( NEXT( xp, xl_other_users ) == xp )
125 server->xl_clients = XLOG_NULL ;
127 server->xl_clients = NEXT( xp, xl_other_users ) ;
129 UNLINK( xp, xl_other_users ) ;
133 * Step 2: If we have users, clear their link to us.
135 if ( xp->xl_clients != NULL )
137 xlog_s *xp2 = xp->xl_clients ;
141 xp2->xl_use = XLOG_NULL ;
142 xp2 = NEXT( xp2, xl_other_users ) ;
144 while ( xp2 != xp->xl_clients ) ;
149 static void xlog_flags( xlog_s *xp, xlog_cmd_e cmd, ... )
157 flag = va_arg( ap, int );
158 old_value = ((xp->xl_flags & flag) != 0);
159 valp = va_arg( ap, int * );
161 if ( cmd == XLOG_SETFLAG ) {
163 xp->xl_flags |= flag ;
165 xp->xl_flags &= ~flag ;
171 void xlog_destroy( xlog_h pxlog )
173 xlog_s *xp = XP( pxlog ) ;
183 void xlog_write( xlog_h pxlog, const char buf[], int len, int flags, ... )
185 xlog_s *xp = XP( pxlog ) ;
189 va_start( ap, flags ) ;
190 status = XL_WRITE( xp, buf, len, flags, ap ) ;
193 if ( status != XLOG_ENOERROR )
195 CALLBACK( xp, status ) ;
201 int xlog_control( xlog_h pxlog, xlog_cmd_e cmd, ... )
204 xlog_s *xp = XP( pxlog ) ;
205 int status = XLOG_ENOERROR ;
207 va_start( ap, cmd ) ;
213 xlog_link( xp, va_arg( ap, xlog_s * ) ) ;
214 xp->xl_callback_arg = va_arg( ap, void * ) ;
218 xp->xl_callback = va_arg( ap, voidfunc ) ;
223 xlog_flags( xp, cmd, ap ) ;
227 status = XL_CONTROL( xp, cmd, ap ) ;
236 int xlog_parms( xlog_e type, ... )
241 va_start( ap, type ) ;
246 status = (*__xlog_syslog_ops.parms)( type, ap ) ;
250 status = (*__xlog_filelog_ops.parms)( type, ap ) ;
254 status = XLOG_ENOERROR ;