1 /*
2 * logtocmd.c -- plugin for log module of websh3
3 * nca-073-9
4 *
5 * Copyright (c) 1996-2000 by Netcetera AG.
6 * Copyright (c) 2001 by Apache Software Foundation.
7 * All rights reserved.
8 *
9 * See the file "license.terms" for information on usage and
10 * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11 *
12 * @(#) $Id: logtocmd.c 322201 2002-03-07 22:55:48Z ronnie $
13 *
14 */
15 #include <tcl.h>
16 #include <stdio.h>
17 #include <string.h>
18 #include "macros.h"
19 #include "logtocmd.h"
20 #include "webutl.h" /* args */
21
22 /* ----------------------------------------------------------------------------
23 * destroyLogToCmdData --
24 * ------------------------------------------------------------------------- */
destroyLogToCmdData(Tcl_Interp * interp,LogToCmdData * logToCmdData)25 int destroyLogToCmdData(Tcl_Interp * interp, LogToCmdData * logToCmdData)
26 {
27
28 WebFreeIfNotNull(logToCmdData);
29 return TCL_OK;
30 }
31
32 /* ----------------------------------------------------------------------------
33 * constructor
34 * ------------------------------------------------------------------------- */
createLogToCmd(Tcl_Interp * interp,ClientData clientData,int objc,Tcl_Obj * CONST objv[])35 ClientData createLogToCmd(Tcl_Interp * interp, ClientData clientData,
36 int objc, Tcl_Obj * CONST objv[])
37 {
38
39 LogToCmdData *logToCmdData = NULL;
40
41 /* --------------------------------------------------------------------------
42 * syntax is: [web::logbag add] command cmdName
43 * 0 1
44 * ----------------------------------------------------------------------- */
45 if (objc != 2) {
46 Tcl_WrongNumArgs(interp, 1, objv, WEB_LOGTOCMD_USAGE);
47 return NULL;
48 }
49
50 if (strcmp(Tcl_GetString(objv[0]), "command") != 0) {
51 Tcl_SetResult(interp, WEB_LOGTOCMD_USAGE, NULL);
52 return NULL;
53 }
54
55 logToCmdData = (LogToCmdData *) allocAndSet(Tcl_GetString(objv[1]));
56
57 return (ClientData) logToCmdData;
58 }
59
60
61 /* ----------------------------------------------------------------------------
62 * destructor
63 * ------------------------------------------------------------------------- */
destroyLogToCmd(Tcl_Interp * interp,ClientData clientData)64 int destroyLogToCmd(Tcl_Interp * interp, ClientData clientData)
65 {
66 return destroyLogToCmdData(interp, (LogToCmdData *) clientData);
67 }
68
69 /* ----------------------------------------------------------------------------
70 * logToCmd
71 * ------------------------------------------------------------------------- */
logToCmd(Tcl_Interp * interp,ClientData clientData,char * msg)72 int logToCmd(Tcl_Interp * interp, ClientData clientData, char *msg)
73 {
74 LogToCmdData *logToCmdData = NULL;
75 int res = TCL_ERROR;
76 Tcl_Obj *cmdlist;
77
78 if ((interp == NULL) || (clientData == NULL) || (msg == NULL))
79 return TCL_ERROR;
80
81 logToCmdData = (LogToCmdData *) clientData;
82
83 /* ----------------------------------------------------------------------
84 * gonna call cmdName msg
85 * ------------------------------------------------------------------- */
86 cmdlist = Tcl_NewObj();
87 Tcl_IncrRefCount(cmdlist);
88 Tcl_ListObjAppendElement(interp, cmdlist, Tcl_NewStringObj((char *)logToCmdData, -1));
89 Tcl_ListObjAppendElement(interp, cmdlist, Tcl_NewStringObj(msg, -1));
90
91 res = Tcl_EvalObjEx(interp, cmdlist, 0);
92
93 Tcl_DecrRefCount(cmdlist);
94
95 return res;
96 }
97