Debian Codegraph @

modules/memoserv/list.c

raw
1 /*
2 * Copyright (c) 2005 Atheme Development Group
3 * Rights to this code are as documented in doc/LICENSE.
4 *
5 * This file contains code for the Memoserv LIST function
6 *
7 */
8
9 #include "atheme.h"
10
11 DECLARE_MODULE_V1
12 (
13 "memoserv/list", false, _modinit, _moddeinit,
14 PACKAGE_STRING,
15 VENDOR_STRING
16 );
17
18 static void ms_cmd_list(sourceinfo_t *si, int parc, char *parv[]);
19
20 command_t ms_list = { "LIST", N_(N_("Lists all of your memos.")),
21 AC_AUTHENTICATED, 0, ms_cmd_list, { .path = "memoserv/list" } };
22
23 void _modinit(module_t *m)
24 {
25 service_named_bind_command("memoserv", &ms_list);
26 }
27
28 void _moddeinit(module_unload_intent_t intent)
29 {
30 service_named_unbind_command("memoserv", &ms_list);
31 }
32
33 static void ms_cmd_list(sourceinfo_t *si, int parc, char *parv[])
34 {
35 /* Misc structs etc */
36 mymemo_t *memo;
37 mowgli_node_t *n;
38 unsigned int i = 0;
39 char strfbuf[BUFSIZE];
40 struct tm tm;
41 char line[512];
42 char chan[CHANNELLEN];
43 char *p;
44
45 command_success_nodata(si, ngettext(N_("You have %zu memo (%d new)."),
46 N_("You have %zu memos (%d new)."),
47 si->smu->memos.count), si->smu->memos.count, si->smu->memoct_new);
48
49 /* Check to see if any memos */
50 if (!si->smu->memos.count)
51 return;
52
53 /* Go to listing memos */
54 command_success_nodata(si, " ");
55
56 MOWGLI_ITER_FOREACH(n, si->smu->memos.head)
57 {
58 i++;
59 memo = (mymemo_t *)n->data;
60 tm = *localtime(&memo->sent);
61
62 strftime(strfbuf, sizeof strfbuf,
63 TIME_FORMAT, &tm);
64
65 snprintf(line, sizeof line, _("- %d From: %s Sent: %s"),
66 i, memo->sender, strfbuf);
67 if (memo->status & MEMO_CHANNEL && *memo->text == '#')
68 {
69 mowgli_strlcat(line, " ", sizeof line);
70 mowgli_strlcat(line, _("To:"), sizeof line);
71 mowgli_strlcat(line, " ", sizeof line);
72 mowgli_strlcpy(chan, memo->text, sizeof chan);
73 p = strchr(chan, ' ');
74 if (p != NULL)
75 *p = '\0';
76 mowgli_strlcat(line, chan, sizeof line);
77 }
78 if (!(memo->status & MEMO_READ))
79 {
80 mowgli_strlcat(line, " ", sizeof line);
81 mowgli_strlcat(line, _("[unread]"), sizeof line);
82 }
83 command_success_nodata(si, "%s", line);
84 }
85
86 return;
87 }
88
89 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
90 * vim:ts=8
91 * vim:sw=8
92 * vim:noexpandtab
93 */