log.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /*
  2. * log.c -- handles:
  3. *
  4. * What else?!
  5. *
  6. */
  7. #include "common.h"
  8. #include "log.h"
  9. #include "tandem.h"
  10. #include "botmsg.h"
  11. #include "dcc.h"
  12. #include "dccutil.h"
  13. #include "rfc1459.h"
  14. #include "users.h"
  15. #include "misc.h"
  16. #include "main.h"
  17. extern struct userrec *userlist;
  18. extern tand_t *tandbot;
  19. extern struct dcc_t *dcc;
  20. extern int debug_output, backgrd, term_z,
  21. dcc_total, loading;
  22. extern struct dcc_t *dcc;
  23. extern time_t now;
  24. int conmask = LOG_MODES | LOG_CMDS | LOG_MISC; /* Console mask */
  25. int debug_output = 1; /* Disply output to server to LOG_SERVEROUT */
  26. int use_console_r = 1; /* Allow users to set their console +r */
  27. int logmodes(char *s)
  28. {
  29. int i;
  30. int res = 0;
  31. for (i = 0; i < strlen(s); i++)
  32. switch (s[i]) {
  33. case 'm':
  34. case 'M':
  35. res |= LOG_MSGS;
  36. break;
  37. case 'p':
  38. case 'P':
  39. res |= LOG_PUBLIC;
  40. break;
  41. case 'j':
  42. case 'J':
  43. res |= LOG_JOIN;
  44. break;
  45. case 'k':
  46. case 'K':
  47. res |= LOG_MODES;
  48. break;
  49. case 'c':
  50. case 'C':
  51. res |= LOG_CMDS;
  52. break;
  53. case 'o':
  54. case 'O':
  55. res |= LOG_MISC;
  56. break;
  57. case 'b':
  58. case 'B':
  59. res |= LOG_BOTS;
  60. break;
  61. case 'r':
  62. case 'R':
  63. res |= use_console_r ? LOG_RAW : 0;
  64. break;
  65. case 'w':
  66. case 'W':
  67. res |= LOG_WALL;
  68. break;
  69. case 'x':
  70. case 'X':
  71. res |= LOG_FILES;
  72. break;
  73. case 's':
  74. case 'S':
  75. res |= LOG_SERV;
  76. break;
  77. case 'd':
  78. case 'D':
  79. res |= LOG_DEBUG;
  80. break;
  81. case 'v':
  82. case 'V':
  83. res |= debug_output ? LOG_SRVOUT : 0;
  84. break;
  85. case 't':
  86. case 'T':
  87. res |= debug_output ? LOG_BOTNET : 0;
  88. break;
  89. case 'h':
  90. case 'H':
  91. res |= debug_output ? LOG_BOTSHARE : 0;
  92. break;
  93. case 'e':
  94. case 'E':
  95. res |= LOG_ERRORS;
  96. break;
  97. case 'g':
  98. case 'G':
  99. res |= LOG_GETIN;
  100. break;
  101. case 'u':
  102. case 'U':
  103. res |= LOG_WARN;
  104. break;
  105. case '*':
  106. res |= LOG_ALL;
  107. break;
  108. }
  109. return res;
  110. }
  111. char *masktype(int x)
  112. {
  113. static char s[24] = ""; /* Change this if you change the levels */
  114. char *p = s;
  115. if (x & LOG_MSGS)
  116. *p++ = 'm';
  117. if (x & LOG_PUBLIC)
  118. *p++ = 'p';
  119. if (x & LOG_JOIN)
  120. *p++ = 'j';
  121. if (x & LOG_MODES)
  122. *p++ = 'k';
  123. if (x & LOG_CMDS)
  124. *p++ = 'c';
  125. if (x & LOG_MISC)
  126. *p++ = 'o';
  127. if (x & LOG_BOTS)
  128. *p++ = 'b';
  129. if ((x & LOG_RAW) && use_console_r)
  130. *p++ = 'r';
  131. if (x & LOG_FILES)
  132. *p++ = 'x';
  133. if (x & LOG_SERV)
  134. *p++ = 's';
  135. if (x & LOG_DEBUG)
  136. *p++ = 'd';
  137. if (x & LOG_WALL)
  138. *p++ = 'w';
  139. if ((x & LOG_SRVOUT) && debug_output)
  140. *p++ = 'v';
  141. if ((x & LOG_BOTNET) && debug_output)
  142. *p++ = 't';
  143. if ((x & LOG_BOTSHARE) && debug_output)
  144. *p++ = 'h';
  145. if (x & LOG_ERRORS)
  146. *p++ = 'e';
  147. if (x & LOG_GETIN)
  148. *p++ = 'g';
  149. if (x & LOG_WARN)
  150. *p++ = 'u';
  151. if (p == s)
  152. *p++ = '-';
  153. *p = 0;
  154. return s;
  155. }
  156. char *maskname(int x)
  157. {
  158. static char s[207] = ""; /* Change this if you change the levels */
  159. int i = 0;
  160. s[0] = 0;
  161. if (x & LOG_MSGS)
  162. i += my_strcpy(s, "msgs, ");
  163. if (x & LOG_PUBLIC)
  164. i += my_strcpy(s + i, "public, ");
  165. if (x & LOG_JOIN)
  166. i += my_strcpy(s + i, "joins, ");
  167. if (x & LOG_MODES)
  168. i += my_strcpy(s + i, "kicks/modes, ");
  169. if (x & LOG_CMDS)
  170. i += my_strcpy(s + i, "cmds, ");
  171. if (x & LOG_MISC)
  172. i += my_strcpy(s + i, "misc, ");
  173. if (x & LOG_BOTS)
  174. i += my_strcpy(s + i, "bots, ");
  175. if ((x & LOG_RAW) && use_console_r)
  176. i += my_strcpy(s + i, "raw, ");
  177. if (x & LOG_FILES)
  178. i += my_strcpy(s + i, "files, ");
  179. if (x & LOG_SERV)
  180. i += my_strcpy(s + i, "server, ");
  181. if (x & LOG_DEBUG)
  182. i += my_strcpy(s + i, "debug, ");
  183. if (x & LOG_WALL)
  184. i += my_strcpy(s + i, "wallops, ");
  185. if ((x & LOG_SRVOUT) && debug_output)
  186. i += my_strcpy(s + i, "server output, ");
  187. if ((x & LOG_BOTNET) && debug_output)
  188. i += my_strcpy(s + i, "botnet traffic, ");
  189. if ((x & LOG_BOTSHARE) && debug_output)
  190. i += my_strcpy(s + i, "share traffic, ");
  191. if (x & LOG_ERRORS)
  192. i += my_strcpy(s + i, "errors, ");
  193. if (x & LOG_GETIN)
  194. i += my_strcpy(s + i, "getin, ");
  195. if (x & LOG_WARN)
  196. i += my_strcpy(s + i, "warnings, ");
  197. if (i)
  198. s[i - 2] = 0;
  199. else
  200. strcpy(s, "none");
  201. return s;
  202. }
  203. /*
  204. * Logging functions
  205. */
  206. /* Log something
  207. * putlog(level,channel_name,format,...);
  208. * Broadcast the log if chname is not '@'
  209. */
  210. void putlog(int type, char *chname, char *format, ...)
  211. {
  212. int idx, tsl = 0;
  213. char s[LOGLINELEN] = "", *out = NULL, stamp[34] = "";
  214. va_list va;
  215. #ifdef HUB
  216. struct tm *t = NULL;
  217. #endif /* HUB */
  218. va_start(va, format);
  219. #ifdef HUB
  220. #ifdef S_UTCTIME
  221. t = gmtime(&now);
  222. #else /* !S_UTCTIME */
  223. t = localtime(&now);
  224. #endif /* S_UTCTIME */
  225. egg_strftime(stamp, sizeof(stamp) - 2, LOG_TS, t);
  226. strcat(stamp, " ");
  227. tsl = strlen(stamp);
  228. #endif /* HUB */
  229. /* Format log entry at offset 'tsl,' then i can prepend the timestamp */
  230. out = s + tsl;
  231. /* No need to check if out should be null-terminated here,
  232. * just do it! <cybah>
  233. */
  234. egg_vsnprintf(out, LOGLINEMAX - tsl, format, va);
  235. va_end(va);
  236. out[LOGLINEMAX - tsl] = 0;
  237. /* Place the timestamp in the string to be printed */
  238. if (out[0]) {
  239. strncpy(s, stamp, tsl);
  240. out = s;
  241. }
  242. strcat(out, "\n");
  243. /* FIXME: WRITE LOG HERE */
  244. /* broadcast to hubs */
  245. if (chname[0] == '*' && conf.bot && conf.bot->nick) {
  246. char outbuf[LOGLINEMAX] = "";
  247. egg_snprintf(outbuf, sizeof outbuf, "hl %d %s", type, out);
  248. if (userlist && !loading) {
  249. tand_t *bot;
  250. struct userrec *ubot;
  251. for (bot = tandbot ; bot; bot = bot->next) {
  252. if ((ubot = get_user_by_handle(userlist, bot->bot))) {
  253. if (bot_hublevel(ubot) < 999)
  254. putbot(ubot->handle, outbuf);
  255. }
  256. }
  257. } else {
  258. putallbots(outbuf);
  259. }
  260. }
  261. for (idx = 0; idx < dcc_total; idx++) {
  262. if ((dcc[idx].type == &DCC_CHAT && !dcc[idx].simul) && (dcc[idx].u.chat->con_flags & type)) {
  263. if ((chname[0] == '@') || (chname[0] == '*') || (dcc[idx].u.chat->con_chan[0] == '*') ||
  264. (!rfc_casecmp(chname, dcc[idx].u.chat->con_chan)))
  265. dprintf(idx, "%s", out);
  266. }
  267. }
  268. if ((!backgrd) && (!term_z)) {
  269. dprintf(DP_STDOUT, "%s", out);
  270. } else if ((type & LOG_ERRORS || type & LOG_MISC) && use_stderr) {
  271. out += tsl;
  272. dprintf(DP_STDERR, "%s", s);
  273. }
  274. }