[srvx-commits] CVS: services/src helpserv.c,1.47,1.48 helpserv.help,1.14,1.15
Brought to you by:
entrope
|
From: Adrian D. <sai...@us...> - 2002-11-09 03:46:42
|
Update of /cvsroot/srvx/services/src
In directory usw-pr-cvs1:/tmp/cvs-serv1963
Modified Files:
helpserv.c helpserv.help
Log Message:
Implement request logging
Allow cmd_close use extra arguments for an optional close reason. Document.
Include an "assigned" time in the request information.
Index: helpserv.c
===================================================================
RCS file: /cvsroot/srvx/services/src/helpserv.c,v
retrieving revision 1.47
retrieving revision 1.48
diff -C2 -r1.47 -r1.48
*** helpserv.c 7 Nov 2002 02:05:47 -0000 1.47
--- helpserv.c 9 Nov 2002 03:46:38 -0000 1.48
***************
*** 20,27 ****
/* TODO List for helpserv.c
- * - Request logging. Saxdb should make this fairly painless.
- * - cmd_close should optionally take another argument (a reason/comment)
- * - Statistical analysis of time
* Wishlist for helpserv.c
* - Make HelpServ send unassigned request count to helpers as they join the
* channel
--- 20,25 ----
/* TODO List for helpserv.c
* Wishlist for helpserv.c
+ * - Statistical analysis of time (define what this means first)
* - Make HelpServ send unassigned request count to helpers as they join the
* channel
***************
*** 58,61 ****
--- 56,60 ----
#define KEY_DESC "description"
#define KEY_DB_BACKUP_FREQ "db_backup_freq"
+ #define KEY_REQLOGFILE "reqlogfile"
/* db entries */
***************
*** 84,90 ****
--- 83,94 ----
#define KEY_REQUESTS "requests"
#define KEY_REQUEST_HELPER "helper"
+ #define KEY_REQUEST_ASSIGNED "assigned"
#define KEY_REQUEST_HANDLE "handle"
#define KEY_REQUEST_TEXT "text"
#define KEY_REQUEST_OPENED "opened"
+ #define KEY_REQUEST_NICK "nick"
+ #define KEY_REQUEST_USERHOST "userhost"
+ #define KEY_REQUEST_CLOSED "closed"
+ #define KEY_REQUEST_CLOSEREASON "closereason"
#define KEY_NOTIFICATION "notification"
#define KEY_PRIVMSG_ONLY "privmsg_only"
***************
*** 373,381 ****
const char *description;
unsigned long db_backup_frequency;
} helpserv_conf;
! static int helpserv_enabled=0;
static time_t last_stats_update;
#define CMD_NEED_BOT 0x001
#define CMD_NOT_OVERRIDE 0x002
--- 377,390 ----
const char *description;
unsigned long db_backup_frequency;
+ const char *reqlogfile;
} helpserv_conf;
! static int helpserv_enabled;
static time_t last_stats_update;
+ static int shutting_down;
+ static FILE *reqlog_f;
+ static struct saxdb_context *reqlog_ctx;
+
#define CMD_NEED_BOT 0x001
#define CMD_NOT_OVERRIDE 0x002
***************
*** 453,456 ****
--- 462,466 ----
unsigned long id;
time_t opened;
+ time_t assigned;
time_t updated;
};
***************
*** 562,565 ****
--- 572,603 ----
}
+ static void helpserv_log_request(struct helpserv_request *req, const char *reason) {
+ char key[27+NICKLEN];
+ char userhost[USERLEN+HOSTLEN+2];
+
+ if (!reqlog_ctx || !req) return;
+ if (!reason) reason = "";
+
+ sprintf(key, "%s-%lu-%lu", req->hs->helpserv->nick, req->opened, req->id);
+ saxdb_start_record(reqlog_ctx, key, 1);
+ if (req->helper) {
+ saxdb_write_string(reqlog_ctx, KEY_REQUEST_HELPER, req->helper->handle->handle);
+ saxdb_write_int(reqlog_ctx, KEY_REQUEST_ASSIGNED, req->assigned);
+ }
+ if (req->handle) saxdb_write_string(reqlog_ctx, KEY_REQUEST_HANDLE, req->handle->handle);
+ if (req->user) {
+ saxdb_write_string(reqlog_ctx, KEY_REQUEST_NICK, req->user->nick);
+ sprintf(userhost, "%s@%s", req->user->ident, req->user->hostname);
+ saxdb_write_string(reqlog_ctx, KEY_REQUEST_USERHOST, userhost);
+ }
+ saxdb_write_int(reqlog_ctx, KEY_REQUEST_OPENED, req->opened);
+ saxdb_write_int(reqlog_ctx, KEY_REQUEST_CLOSED, now);
+ saxdb_write_string(reqlog_ctx, KEY_REQUEST_CLOSEREASON, reason);
+ saxdb_write_string_list(reqlog_ctx, KEY_REQUEST_TEXT, req->text);
+ saxdb_end_record(reqlog_ctx);
+
+ fflush(reqlog_f);
+ }
+
/* Searches for a request by number, nick, or account (num|nick|*account).
* As there can potentially be >1 match, it takes a reqlist. The return
***************
*** 1309,1312 ****
--- 1347,1355 ----
struct helpserv_request *req = data;
+ /* Logging */
+ if (shutting_down && (req->hs->persist_types[PERSIST_T_REQUEST] != PERSIST_CLOSE || !req->handle)) {
+ helpserv_log_request(req, "srvx shutdown");
+ }
+
/* Clean up from the unhandled queue */
if (req->hs->unhandled) {
***************
*** 1346,1349 ****
--- 1389,1393 ----
struct helpserv_reqlist *nick_list, *hand_list;
struct helpserv_user *hs_user=GetHSUser(hs, user->handle_info);
+ char close_reason[MAXLEN];
unsigned long old_req;
unsigned int i;
***************
*** 1381,1384 ****
--- 1425,1434 ----
old_req = req->id;
+ if (argc >= 3) {
+ snprintf(close_reason, MAXLEN, "Closed by %s: %s", user->handle_info->handle, unsplit_string(argv+2, argc-2, NULL));
+ } else {
+ sprintf(close_reason, "Closed by %s", user->handle_info->handle);
+ }
+ helpserv_log_request(req, close_reason);
dict_remove(hs->requests, argv[1]);
***************
*** 1549,1557 ****
req->next_unhandled = NULL;
! if (!(req->helper = GetHSUser(hs, user->handle_info))) {
! helpserv_notice(user, HSMSG_WTF_WHO_ARE_YOU, hs->helpserv->nick);
! log(HS_LOG, LOG_ERROR, "%s(): Unable to locate %s[%s] on the %s userlist.\n", __FUNCTION__, user->nick, user->handle_info->handle, hs->helpserv->nick);
! return 0;
! }
if (old_helper) {
--- 1599,1605 ----
req->next_unhandled = NULL;
! req->helper = GetHSUser(hs, user->handle_info);
! assert(req->helper);
! req->assigned = now;
if (old_helper) {
***************
*** 2871,2875 ****
saxdb_start_record(ctx, key, 0);
! if (request->helper) saxdb_write_string(ctx, KEY_REQUEST_HELPER, request->helper->handle->handle);
saxdb_write_string(ctx, KEY_REQUEST_HANDLE, request->handle->handle);
saxdb_write_int(ctx, KEY_REQUEST_OPENED, request->opened);
--- 2919,2926 ----
saxdb_start_record(ctx, key, 0);
! if (request->helper) {
! saxdb_write_string(ctx, KEY_REQUEST_HELPER, request->helper->handle->handle);
! saxdb_write_int(ctx, KEY_REQUEST_ASSIGNED, request->assigned);
! }
saxdb_write_string(ctx, KEY_REQUEST_HANDLE, request->handle->handle);
saxdb_write_int(ctx, KEY_REQUEST_OPENED, request->opened);
***************
*** 2918,2921 ****
--- 2969,2975 ----
}
+ str = database_get_data(rd->d.object, KEY_REQUEST_ASSIGNED, RECDB_QSTRING);
+ if (str) request->assigned = TIME_T_CAST strtoul(str, NULL, 0);
+
str = database_get_data(rd->d.object, KEY_REQUEST_HELPER, RECDB_QSTRING);
if (str) {
***************
*** 3152,3155 ****
--- 3206,3232 ----
str = database_get_data(conf_node, KEY_DESC, RECDB_QSTRING);
helpserv_conf.description = str;
+
+ str = database_get_data(conf_node, KEY_REQLOGFILE, RECDB_QSTRING);
+ if (str && strlen(str)) {
+ helpserv_conf.reqlogfile = str;
+ } else {
+ helpserv_conf.reqlogfile = NULL;
+ }
+
+ if (reqlog_ctx) {
+ saxdb_close_context(reqlog_ctx);
+ reqlog_ctx = NULL;
+ }
+ if (reqlog_f) {
+ fclose(reqlog_f);
+ reqlog_f = NULL;
+ }
+ if (helpserv_conf.reqlogfile) {
+ if (!(reqlog_f = fopen(helpserv_conf.reqlogfile, "a"))) {
+ log(HS_LOG, LOG_ERROR, "Unable to open request logfile (%s): %s", helpserv_conf.reqlogfile, strerror(errno));
+ } else {
+ reqlog_ctx = saxdb_open_context(reqlog_f);
+ }
+ }
}
***************
*** 3199,3202 ****
--- 3276,3280 ----
if (req->helper && (hs->notify >= NOTIFY_DROP)) helpserv_notify(req->helper, HSMSG_NOTIFY_REQ_DROP, req->id, "they have left the help channel");
}
+ helpserv_log_request(req, "Dropped");
dict_remove(hs->requests, iter_key(it));
break;
***************
*** 3284,3287 ****
--- 3362,3366 ----
if (req->helper && (req->hs->notify >= NOTIFY_DROP)) helpserv_notify(req->helper, HSMSG_NOTIFY_REQ_DROP, req->id, "the user has quit");
+ helpserv_log_request(req, "Dropped");
dict_remove(req->hs->requests, buf);
} else {
***************
*** 3757,3760 ****
--- 3836,3840 ----
if (req->helper && (hs->notify >= NOTIFY_DROP)) helpserv_notify(req->helper, HSMSG_NOTIFY_REQ_DROP, req->id, "their account has been unregistered and no online users were authenticated to it");
sprintf(buf, "%lu", req->id);
+ helpserv_log_request(req, "Account unregistered");
dict_remove(req->hs->requests, buf);
} else if (user->handle_info == handle) {
***************
*** 3788,3791 ****
--- 3868,3872 ----
sprintf(buf, "%lu", req->id);
+ helpserv_log_request(req, "Account unregistered");
dict_remove(req->hs->requests, buf);
}
***************
*** 3865,3868 ****
--- 3946,3950 ----
static void helpserv_db_cleanup(void) {
+ shutting_down=1;
unreg_part_func(handle_part);
unreg_del_user_func(handle_quit);
***************
*** 3875,3878 ****
--- 3957,3963 ----
dict_delete(helpserv_reqs_byhand_dict);
dict_delete(helpserv_users_byhand_dict);
+
+ if (reqlog_ctx) saxdb_close_context(reqlog_ctx);
+ if (reqlog_f) fclose(reqlog_f);
}
Index: helpserv.help
===================================================================
RCS file: /cvsroot/srvx/services/src/helpserv.help,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -r1.14 -r1.15
*** helpserv.help 7 Nov 2002 02:05:47 -0000 1.14
--- helpserv.help 9 Nov 2002 03:46:39 -0000 1.15
***************
*** 60,65 ****
"Lists the currently defined HelpServ bots (along with their channels and owners' accounts).");
"CLOSE" ("$bCLOSE$b",
! "/msg $S CLOSE <reqid|nick|*account>",
! "Closes out the specified request.");
"CLVL" ("$bCLVL$b",
"/msg $S CLVL <user|*nick> <new-level>",
--- 60,65 ----
"Lists the currently defined HelpServ bots (along with their channels and owners' accounts).");
"CLOSE" ("$bCLOSE$b",
! "/msg $S CLOSE <reqid|nick|*account> [reason]",
! "Closes out the specified request. The optional [reason] is included in the request log file.");
"CLVL" ("$bCLVL$b",
"/msg $S CLVL <user|*nick> <new-level>",
|