ppc_access_log.c

00001 /*
00002  * Copyright (c) 2005-2012 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 = bid;
00045     la.vhostid = vhostid;
00046     (void) u_strlcpy(la.log, str, sizeof la.log);
00047 
00048     /* send the command request */
00049     nop_err_if(ppc_write(s->ppc, ctx->pipc, PPC_CMD_ACCESS_LOG, (char*)&la, 
00050         sizeof(la)) < 0);
00051 
00052     return 0;
00053 err:
00054     return ~0;
00055 }
00056 
00057 /* [parent] log a new message */
00058 int server_ppc_cb_access_log(ppc_t *ppc, int fd, unsigned char cmd, char *data, 
00059     size_t size, void *vso)
00060 {
00061     server_t *s;
00062     ppc_access_log_t *pla;
00063     backend_t *be;
00064     vhost_t *vhost;
00065     vhost_list_t *vhost_list;
00066     http_t *http;
00067 
00068     u_unused_args(ppc, fd, cmd, size);
00069 
00070     nop_err_if (vso == NULL);
00071     nop_err_if (data == NULL);
00072 
00073     pla = (ppc_access_log_t*) data;
00074     s = (server_t *) vso;
00075 
00076     /* get the http object */
00077     if(!server_get_backend_by_id(s, pla->bid, &be) && be->arg)
00078         http = (http_t*)be->arg;
00079 
00080     dbg_err_if((vhost_list = http_get_vhost_list(http)) == NULL);
00081 
00082     dbg_err_if((vhost = vhost_list_get_n(vhost_list, pla->vhostid)) == NULL);
00083 
00084     /* log the line */
00085     if(vhost->klog)
00086         nop_err_if(klog(vhost->klog, KLOG_INFO, "%s", pla->log));
00087 
00088     return 0;
00089 err:
00090     return ~0;
00091 }
00092 

←Products
Copyright © 2005-2012 - KoanLogic S.r.l. - All rights reserved