ppc_access_log.c
00001
00002
00003
00004
00005
00006
00007
00008
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
00023 struct ppc_access_log_s
00024 {
00025 int bid;
00026 int vhostid;
00027 char log[U_MAX_LOG_LENGTH];
00028 };
00029
00030 typedef struct ppc_access_log_s ppc_access_log_t;
00031
00032
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
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
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
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
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