Annotation of embedaddon/coova-chilli/src/session.c, revision 1.1
1.1 ! misho 1: /*
! 2: * Chilli sessions
! 3: * Copyright (C) 2004, 2005 Mondru AB.
! 4: * Copyright (c) 2006-2007 David Bird <david@cova.com>
! 5: *
! 6: * The contents of this file may be used under the terms of the GNU
! 7: * General Public License Version 2, provided that the above copyright
! 8: * notice and this permission notice is included in all copies or
! 9: * substantial portions of the software.
! 10: *
! 11: */
! 12: #include "system.h"
! 13: #include "session.h"
! 14:
! 15: extern time_t mainclock;
! 16:
! 17: int session_redir_json_fmt(bstring json, char *userurl, char *redirurl, uint8_t *hismac) {
! 18: bcatcstr(json,",\"redir\":{\"originalURL\":\"");
! 19: bcatcstr(json, userurl?userurl:"");
! 20: bcatcstr(json,"\",\"redirectionURL\":\"");
! 21: bcatcstr(json, redirurl?redirurl:"");
! 22: bcatcstr(json,"\",\"macAddress\":\"");
! 23: if (hismac) {
! 24: char mac[REDIR_MACSTRLEN+2];
! 25: snprintf(mac, REDIR_MACSTRLEN+1, "%.2X-%.2X-%.2X-%.2X-%.2X-%.2X",
! 26: hismac[0], hismac[1],
! 27: hismac[2], hismac[3],
! 28: hismac[4], hismac[5]);
! 29: bcatcstr(json, mac);
! 30: }
! 31: bcatcstr(json,"\"}");
! 32: return 0;
! 33: }
! 34:
! 35: int session_json_fmt(struct session_state *state,
! 36: struct session_params *params,
! 37: bstring json, int init) {
! 38: bstring tmp = bfromcstr("");
! 39: time_t starttime = state->start_time;
! 40: uint32_t inoctets = state->input_octets;
! 41: uint32_t outoctets = state->output_octets;
! 42: uint32_t ingigawords = (state->input_octets >> 32);
! 43: uint32_t outgigawords = (state->output_octets >> 32);
! 44: time_t timenow = mainclock;
! 45: uint32_t sessiontime;
! 46: uint32_t idletime;
! 47:
! 48: sessiontime = timenow - state->start_time;
! 49: idletime = timenow - state->last_time;
! 50:
! 51: bcatcstr(json,",\"session\":{\"sessionId\":\"");
! 52: bcatcstr(json,state->sessionid);
! 53: bcatcstr(json,"\",\"userName\":\"");
! 54: bcatcstr(json,state->redir.username);
! 55: bcatcstr(json, "\",\"startTime\":");
! 56: bassignformat(tmp, "%ld", init ? mainclock : starttime);
! 57: bconcat(json, tmp);
! 58: bcatcstr(json,",\"sessionTimeout\":");
! 59: bassignformat(tmp, "%ld", params->sessiontimeout);
! 60: bconcat(json, tmp);
! 61: bcatcstr(json,",\"idleTimeout\":");
! 62: bassignformat(tmp, "%ld", params->idletimeout);
! 63: bconcat(json, tmp);
! 64: if (params->maxinputoctets) {
! 65: bcatcstr(json,",\"maxInputOctets\":");
! 66: bassignformat(tmp, "%ld", params->maxinputoctets);
! 67: bconcat(json, tmp);
! 68: }
! 69: if (params->maxoutputoctets) {
! 70: bcatcstr(json,",\"maxOutputOctets\":");
! 71: bassignformat(tmp, "%ld", params->maxoutputoctets);
! 72: bconcat(json, tmp);
! 73: }
! 74: if (params->maxtotaloctets) {
! 75: bcatcstr(json,",\"maxTotalOctets\":");
! 76: bassignformat(tmp, "%ld", params->maxtotaloctets);
! 77: bconcat(json, tmp);
! 78: }
! 79: bcatcstr(json,"}");
! 80:
! 81: bcatcstr(json,",\"accounting\":{\"sessionTime\":");
! 82: bassignformat(tmp, "%ld", init ? 0 : sessiontime);
! 83: bconcat(json, tmp);
! 84: bcatcstr(json,",\"idleTime\":");
! 85: bassignformat(tmp, "%ld", init ? 0 : idletime);
! 86: bconcat(json, tmp);
! 87: bcatcstr(json,",\"inputOctets\":");
! 88: bassignformat(tmp, "%ld",init ? 0 : inoctets);
! 89: bconcat(json, tmp);
! 90: bcatcstr(json,",\"outputOctets\":");
! 91: bassignformat(tmp, "%ld", init ? 0 : outoctets);
! 92: bconcat(json, tmp);
! 93: bcatcstr(json,",\"inputGigawords\":");
! 94: bassignformat(tmp, "%ld", init ? 0 : ingigawords);
! 95: bconcat(json, tmp);
! 96: bcatcstr(json,",\"outputGigawords\":");
! 97: bassignformat(tmp, "%ld", init ? 0 : outgigawords);
! 98: bconcat(json, tmp);
! 99: bcatcstr(json,"}");
! 100:
! 101: bdestroy(tmp);
! 102: return 0;
! 103: }
! 104:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>