1 /*
2 * -------------------------------------------------------
3 * Copyright (C) 2003-2007 Tommi Saviranta <wnd@iki.fi>
4 * -------------------------------------------------------
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16 #ifdef HAVE_CONFIG_H
17 #include <config.h>
18 #endif /* ifdef HAVE_CONFIG_H */
19
20 #include "etc.h"
21
22 #ifdef NEED_CMDPASSWD
23
24 #include "remote.h"
25 #include "error.h"
26 #include "common.h"
27 #include "miau.h"
28 #include "irc.h"
29 #include "messages.h"
30
31 #include <string.h>
32
33
34
35 /*
36 * Process remote sent (thru IRC-network) commands.
37 */
38 int
remote_cmd(const char * command,const char * params,const char * nick)39 remote_cmd(const char *command, const char *params, const char *nick)
40 {
41 /* Each command consists of up to four parameters. */
42 char **param = (char **) xmalloc((sizeof(char *)) * MAXCMDPARAMS);
43 int paramno = 0;
44 char *splitted = xstrdup(params);
45 char *p;
46 int i = 0;
47 int pass = 1;
48
49
50 /* We know there's at least one word, so no need to check this. */
51 p = strtok(splitted, " ");
52 do {
53 param[paramno] = p;
54 paramno++;
55 p = strtok(NULL, " ");
56 } while (p != NULL && paramno < MAXCMDPARAMS);
57 /* Set unused parameters to NULL. */
58 i = paramno;
59 while (i < MAXCMDPARAMS) {
60 param[i] = NULL;
61 i++;
62 }
63
64 /*
65 * Because we don't know what features are compiled in, we can't use
66 * "else if" at all.
67 */
68 #ifdef RELEASENICK
69 if (xstrcmp(command, "NICK") == 0 && paramno == 2) {
70 int time = atoi(param[1]);
71 if (time < 10) { time = 10; }
72 if (strlen(param[0]) > 0) {
73 irc_notice(&c_server, nick, MIAU_RELEASENICK,
74 param[0], time);
75 irc_write(&c_server, "NICK %s", param[0]);
76 report(MIAU_RELEASENICK, param[0], time);
77 timers.nickname = -time;
78 pass = 0;
79 }
80 }
81 #endif /* ifdef RELEASENICK */
82
83 /* Free parameter-list. */
84 xfree(param);
85 xfree(splitted);
86
87 return pass;
88 } /* int remote_cmd(const char *command, const char *params,
89 const char *nick) */
90
91
92
93 #endif /* ifdef NEED_CMDPASSWD */
94