Main Page | Modules | File List | Globals

ppc_access_log.c

00001 /*
00002  * Copyright (c) 2005, 2006 by KoanLogic s.r.l. <http://www.koanlogic.com>
00003  * All rights reserved.
00004  *
00005  * This file is part of KLone, and as such it is subject to the license stated
00006  * in the LICENSE file which you have received as part of this distribution.
00007  *
00008  * $Id: ppc_access_log.c,v 1.1 2007/11/09 22:06:26 tat Exp $
00009  */
00010 
00011 #include "klone_conf.h"
00012 #include <string.h>
00013 #include <klone/klog.h>
00014 #include <klone/context.h>
00015 #include <klone/server.h>
00016 #include <klone/ppc.h>
00017 #include <klone/ppc_cmd.h>
00018 #include <klone/vhost.h>
00019 #include <klone/server_ppc_cmd.h>
00020 #include "server_s.h"
00021 
00022 /* struct used for ppc command PPC_CMD_LOG_ADD */
00023 struct ppc_access_log_s
00024 {
00025     int bid;                        /* calling backend ID       */
00026     int vhostid;                    /* vhost ID                 */
00027     char log[U_MAX_LOG_LENGTH];     /* log line                 */
00028 };
00029 
00030 typedef struct ppc_access_log_s ppc_access_log_t;
00031 
00032 /* client function */
00033 int server_ppc_cmd_access_log(server_t *s, int bid, int vhostid,
00034         const char *str)
00035 {
00036     ppc_access_log_t la;
00037 
00038     nop_err_if (s == NULL);
00039     nop_err_if (s->ppc == NULL);
00040     nop_err_if (str == NULL);
00041 
00042     memset(&la, 0, sizeof(ppc_access_log_t));
00043 
00044     la.bid = ctx->backend->id;
00045     la.vhostid = vhostid;
00046     strncpy(la.log, str, U_MAX_LOG_LENGTH);
00047     la.log[U_MAX_LOG_LENGTH -1] = 0;
00048 
00049     /* send the command request */
00050     nop_err_if(ppc_write(s->ppc, ctx->pipc, PPC_CMD_ACCESS_LOG, (char*)&la, 
00051         sizeof(la)) < 0);
00052 
00053     return 0;
00054 err:
00055     return ~0;
00056 }
00057 
00058 /* [parent] log a new message */
00059 int server_ppc_cb_access_log(ppc_t *ppc, int fd, unsigned char cmd, char *data, 
00060     size_t size, void *vso)
00061 {
00062     server_t *s;
00063     ppc_access_log_t *pla;
00064     backend_t *be;
00065     vhost_t *vhost;
00066     vhost_list_t *vhost_list;
00067     http_t *http;
00068 
00069     u_unused_args(ppc, fd, cmd, size);
00070 
00071     nop_err_if (vso == NULL);
00072     nop_err_if (data == NULL);
00073 
00074     pla = (ppc_access_log_t*) data;
00075     s = (server_t *) vso;
00076 
00077     /* get the http object */
00078     if(!server_get_backend_by_id(s, pla->bid, &be) && be->arg)
00079         http = (http_t*)be->arg;
00080 
00081     dbg_err_if((vhost_list = http_get_vhost_list(http)) == NULL);
00082 
00083     dbg_err_if((vhost = vhost_list_get_n(vhost_list, pla->vhostid)) == NULL);
00084 
00085     /* log the line */
00086     if(vhost->klog)
00087         nop_err_if(klog(vhost->klog, KLOG_INFO, "%s", pla->log));
00088 
00089     return 0;
00090 err:
00091     return ~0;
00092 }
00093