aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-04-28 16:46:03 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-04-28 16:46:03 +0200
commit7a73cf3d8bbe5445e441d400099736f05cc4e5d8 (patch)
tree815fa9277111767d7596d929daf953840e9987b1
parent7c321d614e8d91b23434b13bfcf89274797815ec (diff)
downloadirc-7a73cf3d8bbe5445e441d400099736f05cc4e5d8.zip
irc-7a73cf3d8bbe5445e441d400099736f05cc4e5d8.tar.bz2
Got the thing to work.
-rw-r--r--CMakeLists.txt2
-rw-r--r--src/irc/irc.c36
-rw-r--r--src/irc/irc.h7
-rw-r--r--src/irc/irc_handle_connected.c26
-rw-r--r--src/irc/irc_receive.c26
-rw-r--r--src/irc/irc_select.c40
-rw-r--r--src/irc/irc_send.c73
-rw-r--r--src/main.c10
-rw-r--r--src/meta_net/meta_net.c89
-rw-r--r--src/meta_net/meta_net.h1
-rw-r--r--src/meta_net/meta_net_handle_reply.c232
-rw-r--r--src/meta_net/meta_net_select.c8
-rw-r--r--src/meta_net/meta_net_try_request.c106
-rw-r--r--src/meta_net/meta_net_types.h23
-rw-r--r--src/parameters/parameters.c18
-rw-r--r--src/parameters/parameters.h10
-rw-r--r--src/parameters/parameters_getters.c16
-rw-r--r--src/parameters/parameters_types.h5
18 files changed, 636 insertions, 92 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4540388..5b994db 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -15,7 +15,7 @@ find_package(LibIRCClient REQUIRED)
if(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_C_FLAGS "-g -Wall -Wpedantic -Wconversion")
#message(STATUS "GNUCC detected. Adding '-O3' parameter.")
- #set(CMAKE_C_FLAGS "-O2")
+ #set(CMAKE_C_FLAGS "-O3")
endif()
# ${SRC_FILES} is recursively defined in the subdirectories.
diff --git a/src/irc/irc.c b/src/irc/irc.c
index 3e0bca7..f1290f9 100644
--- a/src/irc/irc.c
+++ b/src/irc/irc.c
@@ -41,6 +41,7 @@ int JH_irc_initialize
irc->callbacks.event_dcc_send_req = JH_irc_handle_dcc_send_req_event;
irc->session = irc_create_session(&(irc->callbacks));
+ irc_set_ctx(irc->session, (void *) irc);
irc->params = params;
irc->jh_net = jh_net;
@@ -59,7 +60,8 @@ int JH_irc_connect (struct JH_irc irc [const restrict static 1])
{
if (JH_parameters_get_irc_is_ipv6(irc->params))
{
- return
+ if
+ (
irc_connect6
(
irc->session,
@@ -69,11 +71,23 @@ int JH_irc_connect (struct JH_irc irc [const restrict static 1])
JH_parameters_get_irc_nick(irc->params),
JH_parameters_get_irc_username(irc->params),
JH_parameters_get_irc_realname(irc->params)
+ ) != 0
+ )
+ {
+ JH_FATAL
+ (
+ stderr,
+ "[IRC] Unable to attempt connection (IPv6): %s.\n",
+ irc_strerror(irc_errno(irc->session))
);
+
+ return -1;
+ }
}
else
{
- return
+ if
+ (
irc_connect
(
irc->session,
@@ -83,8 +97,26 @@ int JH_irc_connect (struct JH_irc irc [const restrict static 1])
JH_parameters_get_irc_nick(irc->params),
JH_parameters_get_irc_username(irc->params),
JH_parameters_get_irc_realname(irc->params)
+ ) != 0
+ )
+ {
+ JH_FATAL
+ (
+ stderr,
+ "[IRC] Unable to attempt connection: %s.\n",
+ irc_strerror(irc_errno(irc->session))
);
+
+ return -1;
+ }
}
+
+ return 0;
+}
+
+void JH_irc_finalize (struct JH_irc irc [const restrict static 1])
+{
+ /* TODO */
}
void JH_irc_do_nothing
diff --git a/src/irc/irc.h b/src/irc/irc.h
index 9bdfcef..a6c2df3 100644
--- a/src/irc/irc.h
+++ b/src/irc/irc.h
@@ -22,7 +22,12 @@ int JH_irc_send_message
const char msg [const restrict static 1]
);
-/* TODO */
+int JH_irc_send_action
+(
+ struct JH_irc irc [const restrict static 1],
+ const char msg [const restrict static 1]
+);
+
void JH_irc_finalize (struct JH_irc irc [const restrict static 1]);
int JH_irc_pre_select
diff --git a/src/irc/irc_handle_connected.c b/src/irc/irc_handle_connected.c
index 3d24af9..b797d91 100644
--- a/src/irc/irc_handle_connected.c
+++ b/src/irc/irc_handle_connected.c
@@ -1,5 +1,7 @@
#include <libircclient/libircclient.h>
+#include "../error/error.h"
+
#include "../parameters/parameters.h"
#include "irc.h"
@@ -18,10 +20,24 @@ void JH_irc_handle_connected_event
irc = (struct JH_irc *) irc_get_ctx(session);
- irc_cmd_join
+ JH_S_DEBUG(stderr, 1, "[IRC] Connected.");
+
+ if
(
- session,
- JH_parameters_get_irc_channel(irc->params),
- 0
- );
+ irc_cmd_join
+ (
+ session,
+ JH_parameters_get_irc_channel(irc->params),
+ 0
+ )
+ != 0
+ )
+ {
+ JH_ERROR
+ (
+ stderr,
+ "[IRC] Unable to join: %s",
+ irc_strerror(irc_errno(session))
+ );
+ }
}
diff --git a/src/irc/irc_receive.c b/src/irc/irc_receive.c
index 0edb324..64804e3 100644
--- a/src/irc/irc_receive.c
+++ b/src/irc/irc_receive.c
@@ -2,6 +2,8 @@
#include <libircclient/libircclient.h>
+#include "../parameters/parameters.h"
+
#include "../meta_net/meta_net.h"
#include "irc.h"
@@ -26,6 +28,16 @@ void JH_irc_handle_channel_message_event
params[1],
strlen(params[1])
);
+
+ if (JH_parameters_get_print_chat(irc->params))
+ {
+ printf
+ (
+ "[CHAT] <%s> %s\n",
+ origin,
+ params[1]
+ );
+ }
}
void JH_irc_handle_ctcp_action_event
@@ -44,7 +56,17 @@ void JH_irc_handle_ctcp_action_event
JH_meta_net_handle_user_action
(
irc->jh_net,
- params[0],
- strlen(params[0])
+ params[1],
+ strlen(params[1])
);
+
+ if (JH_parameters_get_print_chat(irc->params))
+ {
+ printf
+ (
+ "[CHAT] *%s %s*\n",
+ origin,
+ params[1]
+ );
+ }
}
diff --git a/src/irc/irc_select.c b/src/irc/irc_select.c
index fe15662..3d0772f 100644
--- a/src/irc/irc_select.c
+++ b/src/irc/irc_select.c
@@ -1,4 +1,7 @@
#include <libircclient/libircclient.h>
+#include <unistd.h>
+
+#include "../error/error.h"
#include "irc.h"
@@ -12,12 +15,33 @@ int JH_irc_pre_select
{
while (!irc_is_connected(irc->session))
{
+ JH_S_ERROR(stderr, "[IRC] Not connected.");
+
/* TODO: reconnect or fail. */
- JH_irc_connect(irc);
- /* TODO: wait a bit... */
+ if (JH_irc_connect(irc) != 0)
+ {
+ JH_ERROR
+ (
+ stderr,
+ "[IRC] Failed to connect: %s.",
+ irc_strerror(irc_errno(irc->session))
+ );
+
+ }
+ sleep(10);
}
- irc_add_select_descriptors(irc->session, in, out, max_fd);
+ if (irc_add_select_descriptors(irc->session, in, out, max_fd) != 0)
+ {
+ JH_ERROR
+ (
+ stderr,
+ "[IRC] Failed to add file descriptors to select: %s.",
+ irc_strerror(irc_errno(irc->session))
+ );
+
+ return -1;
+ }
return 0;
}
@@ -29,9 +53,17 @@ int JH_irc_post_select
fd_set out [const restrict static 1]
)
{
- if (!irc_process_select_descriptors(irc->session, in, out))
+ if (irc_process_select_descriptors(irc->session, in, out) != 0)
{
/* TODO: reconnect or fail. */
+ JH_ERROR
+ (
+ stderr,
+ "[IRC] Failed select file descriptors: %s.",
+ irc_strerror(irc_errno(irc->session))
+ );
+
+ return -1;
}
return 0;
diff --git a/src/irc/irc_send.c b/src/irc/irc_send.c
index 7e474be..6297a6e 100644
--- a/src/irc/irc_send.c
+++ b/src/irc/irc_send.c
@@ -4,6 +4,8 @@
#include "../parameters/parameters.h"
+#include "../error/error.h"
+
#include "irc.h"
int JH_irc_send_message
@@ -12,27 +14,80 @@ int JH_irc_send_message
const char msg [const restrict static 1]
)
{
- if (JH_IS_PREFIX("/me ", msg))
- {
- /* TODO: what to do in case of failure? */
- (void) irc_cmd_me
+ if
+ (
+ irc_cmd_msg
(
irc->session,
JH_parameters_get_irc_channel(irc->params),
- (msg + 4)
+ msg
+ )
+ != 0
+ )
+ {
+ JH_ERROR
+ (
+ stderr,
+ "[IRC] Unable to send message: %s.",
+ irc_strerror(irc_errno(irc->session))
);
+
+ /* TODO: what to do in case of failure? */
+
+ return -1;
}
- else
+
+ if (JH_parameters_get_print_chat(irc->params))
{
- /* TODO: what to do in case of failure? */
- (void) irc_cmd_msg
+ printf
+ (
+ "[CHAT] <%s> %s\n",
+ JH_parameters_get_irc_username(irc->params),
+ msg
+ );
+ }
+
+ return 0;
+}
+
+int JH_irc_send_action
+(
+ struct JH_irc irc [const restrict static 1],
+ const char msg [const restrict static 1]
+)
+{
+ if
+ (
+ irc_cmd_me
(
irc->session,
JH_parameters_get_irc_channel(irc->params),
msg
+ )
+ != 0
+ )
+ {
+ JH_ERROR
+ (
+ stderr,
+ "[IRC] Unable to send emote: %s.",
+ irc_strerror(irc_errno(irc->session))
+ );
+
+ /* TODO: what to do in case of failure? */
+
+ return -1;
+ }
+
+ if (JH_parameters_get_print_chat(irc->params))
+ {
+ printf
+ (
+ "[CHAT] *%s %s*\n",
+ JH_parameters_get_irc_username(irc->params),
+ msg
);
}
return 0;
}
-
diff --git a/src/main.c b/src/main.c
index 509255c..732ad20 100644
--- a/src/main.c
+++ b/src/main.c
@@ -33,6 +33,9 @@ static void print_help (const char runnable [const restrict static 1])
" IRC_PORT:\tPort to use for the IRC connection.\n"
"\nOptions:\n"
" -6, --ipv6:\tEnables IPv6.\n"
+ " -c, --print-chat:\tDisplays IRC conversations on stdout.\n"
+ " -i, --print-additional-info:\tDisplays received JH info messages on"
+ " stdout.\n"
" -u USERNAME, --username USERNAME:\tSets the IRC username.\n"
" -r REALNAME, --realname REALNAME:\tSets the IRC realname.\n"
" -p PASSWORD, --password PASSWORD:\tSets the IRC password.\n",
@@ -178,6 +181,13 @@ static int event_handling_loop
return -1;
}
+
+ JH_meta_net_handle_reply
+ (
+ socket,
+ irc,
+ params
+ );
}
return 0;
diff --git a/src/meta_net/meta_net.c b/src/meta_net/meta_net.c
index fdd0fec..8f290a8 100644
--- a/src/meta_net/meta_net.c
+++ b/src/meta_net/meta_net.c
@@ -33,7 +33,7 @@ static int open_socket
JH_FATAL
(
stderr,
- "Unable to create socket: %s.",
+ "Unable to create JabberHive (UNIX) socket: %s.",
strerror(errno)
);
@@ -62,7 +62,8 @@ static int open_socket
JH_FATAL
(
stderr,
- "Unable to connect to address: %s.",
+ "Unable to connect to JabberHive (UNIX) address \"%s\": %s",
+ socket_name,
strerror(errno)
);
@@ -82,7 +83,7 @@ static int open_socket
JH_FATAL
(
stderr,
- "Unable to get fd flag information for JabberHive socket: %s.",
+ "Unable to get fd flag information for JabberHive (UNIX) socket: %s.",
strerror(errno)
);
@@ -100,7 +101,7 @@ static int open_socket
JH_FATAL
(
stderr,
- "Unable to get fd flag information for JabberHive socket: %s.",
+ "Unable to get fd flag information for JabberHive (UNIX) socket: %s.",
strerror(errno)
);
@@ -154,5 +155,83 @@ void JH_meta_net_finalize
struct JH_meta_net socket [const restrict static 1]
)
{
- /* TODO */
+ if (socket->in.data != (char *) NULL)
+ {
+ free((void *) socket->in.data);
+ socket->in.data = (char *) NULL;
+ }
+
+ socket->in.capacity = 0;
+ socket->in.length = 0;
+ socket->in.index = 0;
+
+ if (socket->out.data != (char *) NULL)
+ {
+ free((void *) socket->out.data);
+ socket->out.data = (char *) NULL;
+ }
+
+ socket->out.capacity = 0;
+ socket->out.length = 0;
+ socket->out.index = 0;
+
+ if (socket->fd != -1)
+ {
+ close(socket->fd);
+ socket->fd = -1;
+ }
+
+ socket->has_request_in_progress = 0;
+}
+
+int JH_meta_net_write
+(
+ struct JH_meta_net socket [const restrict static 1]
+)
+{
+ const int old_errno = errno;
+ ssize_t written;
+
+ written =
+ write
+ (
+ socket->fd,
+ (socket->out.data + socket->out.index),
+ (socket->out.length - socket->out.index)
+ );
+
+ if (written <= 0)
+ {
+ if (errno == EAGAIN)
+ {
+ errno = old_errno;
+
+ return 0;
+ }
+
+ JH_ERROR
+ (
+ stderr,
+ "Unable to write to JabberHive (UNIX) socket: %s.",
+ strerror(errno)
+ );
+
+ errno = old_errno;
+
+ return -1;
+ }
+
+ errno = old_errno;
+
+ /* Move the index to track how much of the message we have sent. */
+ socket->out.index += (size_t) written;
+
+ if (socket->out.index >= socket->out.length)
+ {
+ /* Message completely sent, let's get ready for the next one. */
+ socket->out.index = 0;
+ socket->out.length = 0;
+ }
+
+ return 0;
}
diff --git a/src/meta_net/meta_net.h b/src/meta_net/meta_net.h
index ce5c61e..0673f74 100644
--- a/src/meta_net/meta_net.h
+++ b/src/meta_net/meta_net.h
@@ -49,7 +49,6 @@ int JH_meta_net_read
struct JH_meta_net socket [const restrict static 1]
);
-/* TODO */
int JH_meta_net_write
(
struct JH_meta_net socket [const restrict static 1]
diff --git a/src/meta_net/meta_net_handle_reply.c b/src/meta_net/meta_net_handle_reply.c
index b823078..558daed 100644
--- a/src/meta_net/meta_net_handle_reply.c
+++ b/src/meta_net/meta_net_handle_reply.c
@@ -5,70 +5,216 @@
#include "meta_net.h"
-void JH_meta_net_handle_reply
+static void handle_generated_reply
(
struct JH_meta_net socket [const restrict static 1],
struct JH_irc irc [const restrict static 1],
const struct JH_parameters params [const restrict static 1]
)
{
- if (socket->in.index == 0)
- {
- /* No reply to handle. */
- return;
- }
-
- socket->in.data[socket->in.index] = '\0';
-
- if (JH_IS_PREFIX("!CPV ", socket->in.data))
- {
- }
- else if (JH_IS_PREFIX("!CPS ", socket->in.data))
+ if
+ (
+ JH_IS_PREFIX
+ (
+ JH_META_NET_ACTION_STRING " ",
+ (
+ socket->in.data
+ +
+ (
+ JH_META_NET_GR_STRING_LENGTH
+ + 1 /* ' ' */
+ )
+ )
+ )
+ )
{
+ JH_irc_send_action
+ (
+ irc,
+ (
+ socket->in.data
+ +
+ (
+ JH_META_NET_GR_STRING_LENGTH
+ + 1 /* ' ' */
+ + JH_META_NET_ACTION_STRING_LENGTH
+ + 1 /* ' ' */
+ )
+ )
+ );
}
- else if (JH_IS_PREFIX("!GR ", socket->in.data))
+ else if
+ (
+ socket->in.index
+ >
+ (
+ JH_META_NET_GR_STRING_LENGTH
+ + 1 /* ' ' */
+ )
+ )
{
- /* TODO: /me vs message should be handled prior to this. */
- JH_irc_send_message(irc, (socket->in.data + 4));
-
- JH_DEBUG
+ JH_irc_send_message
(
- stderr,
- /* TODO: Parameter dependent behavior. */
- JH_DEBUG_DISPLAY_IRC_MSG_EXCHANGES,
- "<%s> %s",
- JH_parameters_get_irc_nick(params),
- (socket->in.data + 4)
+ irc,
+ (
+ socket->in.data
+ +
+ (
+ JH_META_NET_GR_STRING_LENGTH
+ + 1 /* ' ' */
+ )
+ )
);
}
- else if (JH_IS_PREFIX("!AI ", socket->in.data))
+}
+
+static void move_to_next_reply
+(
+ struct JH_meta_net socket [const restrict static 1]
+)
+{
+ if (socket->in.index < socket->in.length)
{
- /* TODO: Parameter dependent behavior. */
- JH_DEBUG
+ memmove
(
- stderr,
- 1,
- "Received: %s.",
- socket->in.data
+ (void *) socket->in.data,
+ (const void *) (socket->in.data + socket->in.index + 1),
+ ((socket->in.length - 1) - socket->in.index) * sizeof(char)
);
}
- else if (JH_IS_PREFIX("!P ", socket->in.data))
+
+ socket->in.length = (socket->in.length - 1) - socket->in.index;
+
+ for
+ (
+ socket->in.index = 0;
+ (socket->in.index < socket->in.length);
+ socket->in.index += 1
+ )
{
- socket->has_request_in_progress = 0;
+ if (socket->in.data[socket->in.index] == '\n')
+ {
+ return;
+ }
}
- else if (JH_IS_PREFIX("!N ", socket->in.data))
- {
- JH_S_WARNING(stderr, "Received Negative reply.");
- socket->has_request_in_progress = 0;
- }
- else
+ socket->in.index = 0;
+}
+
+static void handle_additional_info
+(
+ struct JH_meta_net socket [const restrict static 1],
+ const struct JH_parameters params [const restrict static 1]
+)
+{
+ if (JH_parameters_get_print_additional_info(params))
{
- JH_WARNING
+ printf
(
- stderr,
- "Unsupported reply received: %s.",
- socket->in.data
+ "[JH][AI] %s\n",
+ (
+ socket->in.data
+ +
+ (
+ JH_META_NET_AI_STRING_LENGTH
+ + 1 /* ' ' */
+ )
+ )
);
}
}
+
+void JH_meta_net_handle_reply
+(
+ struct JH_meta_net socket [const restrict static 1],
+ struct JH_irc irc [const restrict static 1],
+ const struct JH_parameters params [const restrict static 1]
+)
+{
+ while
+ (
+ (socket->in.length != 0)
+ && (socket->in.data[socket->in.index] == '\n')
+ )
+ {
+ socket->in.data[socket->in.index] = '\0';
+
+ if
+ (
+ JH_IS_PREFIX
+ (
+ JH_META_NET_CPV_STRING " ",
+ socket->in.data
+ )
+ )
+ {
+ }
+ else if
+ (
+ JH_IS_PREFIX
+ (
+ JH_META_NET_CPS_STRING " ",
+ socket->in.data
+ )
+ )
+ {
+ }
+ else if
+ (
+ JH_IS_PREFIX
+ (
+ JH_META_NET_GR_STRING " ",
+ socket->in.data
+ )
+ )
+ {
+ handle_generated_reply(socket, irc, params);
+ }
+ else if
+ (
+ JH_IS_PREFIX
+ (
+ JH_META_NET_AI_STRING " ",
+ socket->in.data
+ )
+ )
+ {
+ handle_additional_info(socket, params);
+ }
+ else if
+ (
+ JH_IS_PREFIX
+ (
+ JH_META_NET_P_STRING " ",
+ socket->in.data
+ )
+ )
+ {
+ socket->has_request_in_progress = 0;
+ }
+ else if
+ (
+ JH_IS_PREFIX
+ (
+ JH_META_NET_N_STRING " ",
+ socket->in.data
+ )
+ )
+ {
+ JH_S_WARNING(stderr, "[JH] Received Negative reply.");
+
+ socket->has_request_in_progress = 0;
+ }
+ else
+ {
+ JH_WARNING
+ (
+ stderr,
+ "[JH] Unsupported reply received: %s.",
+ socket->in.data
+ );
+ }
+
+ move_to_next_reply(socket);
+ }
+}
diff --git a/src/meta_net/meta_net_select.c b/src/meta_net/meta_net_select.c
index 069a671..f126176 100644
--- a/src/meta_net/meta_net_select.c
+++ b/src/meta_net/meta_net_select.c
@@ -13,7 +13,11 @@ int JH_meta_net_pre_select
)
{
FD_SET(socket->fd, in);
- FD_SET(socket->fd, out);
+
+ if (socket->out.length != 0)
+ {
+ FD_SET(socket->fd, out);
+ }
if ((*max_fd) < socket->fd)
{
@@ -40,7 +44,7 @@ int JH_meta_net_post_select
}
}
- if (FD_ISSET(socket->fd, out))
+ if ((socket->out.length != 0) && FD_ISSET(socket->fd, out))
{
if (JH_meta_net_write(socket) < 0)
{
diff --git a/src/meta_net/meta_net_try_request.c b/src/meta_net/meta_net_try_request.c
index 121ef8d..89c7539 100644
--- a/src/meta_net/meta_net_try_request.c
+++ b/src/meta_net/meta_net_try_request.c
@@ -76,7 +76,12 @@ int JH_meta_net_handle_user_message
(
&(socket->out.data),
&(socket->out.capacity),
- string_size
+ (
+ string_size
+ + JH_META_NET_RLR_STRING_LENGTH
+ + 1 /* ' ' */
+ + 1 /* '\n' */
+ )
)
< 0
)
@@ -87,13 +92,41 @@ int JH_meta_net_handle_user_message
memcpy
(
(void *) socket->out.data,
+ (const void *) (JH_META_NET_RLR_STRING " "),
+ (
+ (
+ JH_META_NET_RLR_STRING_LENGTH
+ + 1 /* ' ' */
+ )
+ * sizeof(char)
+ )
+ );
+
+ memcpy
+ (
+ (void *)
+ (
+ socket->out.data
+ +
+ (
+ JH_META_NET_RLR_STRING_LENGTH
+ + 1 /* ' ' */
+ )
+ ),
(const void *) string,
(string_size * sizeof(char))
);
- socket->out.length = string_size;
- socket->out.index = 0;
+ socket->out.length =
+ (
+ string_size
+ + JH_META_NET_RLR_STRING_LENGTH
+ + 1 /* ' ' */
+ + 1 /* '\n' */
+ );
+ socket->out.index = 0;
+ socket->out.data[socket->out.length - 1] = '\n';
socket->has_request_in_progress = 1;
return 0;
@@ -117,7 +150,14 @@ int JH_meta_net_handle_user_action
(
&(socket->out.data),
&(socket->out.capacity),
- (string_size + (JH_META_NET_ACTION_STRING_LENGTH + 1))
+ (
+ string_size
+ + JH_META_NET_RLR_STRING_LENGTH
+ + 1 /* ' ' */
+ + JH_META_NET_ACTION_STRING_LENGTH
+ + 1 /* ' ' */
+ + 1 /* '\n' */
+ )
)
< 0
)
@@ -128,22 +168,53 @@ int JH_meta_net_handle_user_action
memcpy
(
(void *) socket->out.data,
- (const void *) JH_META_NET_ACTION_STRING,
- (JH_META_NET_ACTION_STRING_LENGTH * sizeof(char))
+ (const void *)
+ (
+ JH_META_NET_RLR_STRING
+ " "
+ JH_META_NET_ACTION_STRING
+ " "
+ ),
+ (
+ (
+ JH_META_NET_RLR_STRING_LENGTH
+ + 1 /* ' ' */
+ + JH_META_NET_ACTION_STRING_LENGTH
+ + 1 /* ' ' */
+ )
+ * sizeof(char)
+ )
);
- socket->out.data[JH_META_NET_ACTION_STRING_LENGTH] = ' ';
-
memcpy
(
- (void *) (socket->out.data + (JH_META_NET_ACTION_STRING_LENGTH + 1)),
+ (void *)
+ (
+ socket->out.data
+ +
+ (
+ JH_META_NET_RLR_STRING_LENGTH
+ + 1 /* ' ' */
+ + JH_META_NET_ACTION_STRING_LENGTH
+ + 1 /* ' ' */
+ )
+ ),
(const void *) string,
(string_size * sizeof(char))
);
- socket->out.length = string_size;
- socket->out.index = 0;
+ socket->out.length =
+ (
+ string_size
+ + JH_META_NET_RLR_STRING_LENGTH
+ + 1 /* ' ' */
+ + JH_META_NET_ACTION_STRING_LENGTH
+ + 1 /* ' ' */
+ + 1 /* '\n' */
+ );
+ socket->out.index = 0;
+ socket->out.data[socket->out.length - 1] = '\n';
socket->has_request_in_progress = 1;
return 0;
@@ -188,13 +259,13 @@ int JH_meta_net_read
read
(
socket->fd,
- (&(socket->in.data) + socket->in.length),
+ (socket->in.data + socket->in.length),
(size_t) JH_META_NET_READ_SIZE
);
- if (in_bytes_count < 0)
+ if (in_bytes_count <= 0)
{
- if (errno == EAGAIN)
+ if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
{
errno = old_errno;
@@ -204,8 +275,9 @@ int JH_meta_net_read
JH_ERROR
(
stderr,
- "Unable to read from JabberHive socket: %s.",
- strerror(errno)
+ "Unable to read from JabberHive (UNIX) socket: %s (errno: %d).",
+ strerror(errno),
+ errno
);
errno = old_errno;
@@ -216,7 +288,7 @@ int JH_meta_net_read
errno = old_errno;
/* Safe. */
- socket->in.length += (size_t) in_bytes_count;
+ socket->in.length += (size_t) (in_bytes_count);
while (socket->in.index < socket->in.length)
{
diff --git a/src/meta_net/meta_net_types.h b/src/meta_net/meta_net_types.h
index 251f85b..0d0a847 100644
--- a/src/meta_net/meta_net_types.h
+++ b/src/meta_net/meta_net_types.h
@@ -7,6 +7,29 @@
#define JH_META_NET_ACTION_STRING "/me"
#define JH_META_NET_ACTION_STRING_LENGTH 3
+#define JH_META_NET_RPV_STRING "?RPV"
+#define JH_META_NET_RPV_STRING_LENGTH 4
+#define JH_META_NET_RPS_STRING "?RPS"
+#define JH_META_NET_RPS_STRING_LENGTH 4
+#define JH_META_NET_RL_STRING "?RL"
+#define JH_META_NET_RL_STRING_LENGTH 3
+#define JH_META_NET_RR_STRING "?RR"
+#define JH_META_NET_RR_STRING_LENGTH 3
+#define JH_META_NET_RLR_STRING "?RLR"
+#define JH_META_NET_RLR_STRING_LENGTH 4
+
+#define JH_META_NET_CPV_STRING "!CPV"
+#define JH_META_NET_CPV_STRING_LENGTH 4
+#define JH_META_NET_CPS_STRING "!CPV"
+#define JH_META_NET_CPS_STRING_LENGTH 4
+#define JH_META_NET_GR_STRING "!GR"
+#define JH_META_NET_GR_STRING_LENGTH 3
+#define JH_META_NET_AI_STRING "!AI"
+#define JH_META_NET_AI_STRING_LENGTH 3
+#define JH_META_NET_P_STRING "!P"
+#define JH_META_NET_P_STRING_LENGTH 2
+#define JH_META_NET_N_STRING "!N"
+#define JH_META_NET_N_STRING_LENGTH 2
struct JH_meta_net_buffer
{
char * data;
diff --git a/src/parameters/parameters.c b/src/parameters/parameters.c
index 63556f0..116e716 100644
--- a/src/parameters/parameters.c
+++ b/src/parameters/parameters.c
@@ -53,6 +53,8 @@ static void set_default_to_all_fields
struct JH_parameters param [const restrict static 1]
)
{
+ param->print_chat = 0;
+ param->print_additional_info = 0;
param->socket_name = (const char *) NULL;
param->server = (const char *) NULL;
param->password = (const char *) NULL;
@@ -174,6 +176,22 @@ static int set_options
{
param->use_ipv6 = 1;
}
+ if
+ (
+ JH_STRING_EQUALS("-c", argv[i])
+ || JH_STRING_EQUALS("--print-chat", argv[i])
+ )
+ {
+ param->print_chat = 1;
+ }
+ if
+ (
+ JH_STRING_EQUALS("-i", argv[i])
+ || JH_STRING_EQUALS("--print-additional-info", argv[i])
+ )
+ {
+ param->print_additional_info = 1;
+ }
else if
(
JH_STRING_EQUALS("-u", argv[i])
diff --git a/src/parameters/parameters.h b/src/parameters/parameters.h
index 58fc957..5993fba 100644
--- a/src/parameters/parameters.h
+++ b/src/parameters/parameters.h
@@ -10,6 +10,16 @@ int JH_parameters_initialize
const char * argv [const static argc]
);
+const int JH_parameters_get_print_additional_info
+(
+ const struct JH_parameters param [const restrict static 1]
+);
+
+const int JH_parameters_get_print_chat
+(
+ const struct JH_parameters param [const restrict static 1]
+);
+
const char * JH_parameters_get_socket_name
(
const struct JH_parameters param [const restrict static 1]
diff --git a/src/parameters/parameters_getters.c b/src/parameters/parameters_getters.c
index ee2bdee..4cd422e 100644
--- a/src/parameters/parameters_getters.c
+++ b/src/parameters/parameters_getters.c
@@ -1,5 +1,21 @@
#include "parameters.h"
+const int JH_parameters_get_print_additional_info
+(
+ const struct JH_parameters param [const restrict static 1]
+)
+{
+ return param->print_additional_info;
+}
+
+const int JH_parameters_get_print_chat
+(
+ const struct JH_parameters param [const restrict static 1]
+)
+{
+ return param->print_chat;
+}
+
const char * JH_parameters_get_socket_name
(
const struct JH_parameters param [const restrict static 1]
diff --git a/src/parameters/parameters_types.h b/src/parameters/parameters_types.h
index 7d8dd1c..6b17df6 100644
--- a/src/parameters/parameters_types.h
+++ b/src/parameters/parameters_types.h
@@ -5,8 +5,13 @@
struct JH_parameters
{
+ int print_chat;
+ int print_additional_info;
+
+ /* JH **********************************************************************/
const char * restrict socket_name;
+ /* IRC *********************************************************************/
const char * server;
const char * password;
const char * nick;