3 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
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 3 of the License, or
8 * (at your option) any later version.
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 static char *cmd_window
;
32 static char *cmd_cache
;
33 static unsigned cmd_len
;
36 void setcolor (unsigned char t
, unsigned char f
)
42 static int getstring (char *str
)
44 if (cmd_len
> CMDS_CACHE_SIZE
-1) {
46 printf ("\nERROR -> commands cache buffer is full ! Clearing cache ..\n");
76 int cmds_handler (char *buffer
, unsigned len
)
78 if (!strncmp (buffer
, "/to ", 4)) {
82 cmd_window
= strndup (buffer
+4, len
-4);
87 printf ("> Current chat window: %s\n", cmd_window
);
90 } else if (!strncmp (buffer
, "/help", len
)) {
91 printf ("> zjab help\n\t/to\t-\tSpecify JID of chat window\n\t/status\t-\tChange status\n\t/quit\t-\tQuit the zjab\n");
94 } else if (!strncmp (buffer
, "/status ", 8)) {
95 printf ("> Status was changed to \"%s\"\n", buffer
+8);
96 xmpp_presence ("online", buffer
+8);
98 } else if (!strncmp (buffer
, "/quit", len
))
102 printf ("> Unknown chat window, please use /help\n");
107 xmpp_message (cmd_window
, buffer
, len
);
110 printf ("> %s\n", buffer
);
116 /* get input from keyboard */
119 int l
= getstring (cmd_cache
);
124 return cmds_handler (cmd_cache
, l
);
132 cmd_cache
= (char *) malloc (sizeof (char) * CMDS_CACHE_SIZE
);
137 /* set socket "1" to non-blocking */
138 int oldFlag
= fcntl (1, F_GETFL
, 0);
139 if (fcntl (1, F_SETFL
, oldFlag
| O_NONBLOCK
) == -1) {
140 printf ("Cant set socket to nonblocking mode\n");