fixed
This commit is contained in:
parent
65de41ff41
commit
8d36d6a974
2 changed files with 22 additions and 23 deletions
43
C/irc.c
43
C/irc.c
|
@ -18,13 +18,13 @@ int IRCC_urecv(IRCC_client *irc) {
|
||||||
return recv(irc->irc_socket, irc->irc_raw, sizeof(irc->irc_raw), 0);
|
return recv(irc->irc_socket, irc->irc_raw, sizeof(irc->irc_raw), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int IRCC_usend(IRCC_client *irc, off_t bytes) {
|
int IRCC_usend(IRCC_client *irc, const char *msg, off_t bytes) {
|
||||||
#ifdef ENABLE_SSL
|
#ifdef ENABLE_SSL
|
||||||
if (irc->irc_usingssl)
|
if (irc->irc_usingssl)
|
||||||
return SSL_write(irc->irc_ssl, irc->irc_raw, bytes);
|
return SSL_write(irc->irc_ssl, msg, bytes);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return send(irc->irc_socket, irc->irc_raw, bytes, 0);
|
return send(irc->irc_socket, msg, bytes, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int IRCC_connect(IRCC_client *irc, const char *ip, const unsigned int port) {
|
int IRCC_connect(IRCC_client *irc, const char *ip, const unsigned int port) {
|
||||||
|
@ -32,7 +32,7 @@ int IRCC_connect(IRCC_client *irc, const char *ip, const unsigned int port) {
|
||||||
if (!hp)
|
if (!hp)
|
||||||
return IRCC_ERROR;
|
return IRCC_ERROR;
|
||||||
|
|
||||||
//Only ipv4
|
/* Only ipv4 */
|
||||||
struct sockaddr_in client_str;
|
struct sockaddr_in client_str;
|
||||||
memset(&client_str, 0, sizeof(client_str));
|
memset(&client_str, 0, sizeof(client_str));
|
||||||
client_str.sin_family = AF_INET;
|
client_str.sin_family = AF_INET;
|
||||||
|
@ -58,24 +58,24 @@ void IRCC_parse_msg(char *tmp, IRCC_client *irc) {
|
||||||
irc->irc_raw[strcspn(irc->irc_raw, "\r\n")] = '\0';
|
irc->irc_raw[strcspn(irc->irc_raw, "\r\n")] = '\0';
|
||||||
|
|
||||||
if (tmp != NULL) {
|
if (tmp != NULL) {
|
||||||
//Message
|
/* Message */
|
||||||
char *val = strchr(tmp, ':');
|
char *val = strchr(tmp, ':');
|
||||||
if (val != NULL) {
|
if (val != NULL) {
|
||||||
val[0] = '\0';
|
val[0] = '\0';
|
||||||
irc->irc_msg = val + 1;
|
irc->irc_msg = val + 1;
|
||||||
|
|
||||||
//Del space before :
|
/* Del space before : */
|
||||||
*(val - 1) = '\0';
|
*(val - 1) = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
//Channel
|
/* Channel */
|
||||||
val = strchr(tmp, ' ');
|
val = strchr(tmp, ' ');
|
||||||
if (val != NULL) {
|
if (val != NULL) {
|
||||||
val[0] = '\0';
|
val[0] = '\0';
|
||||||
irc->irc_channel = val + 1;
|
irc->irc_channel = val + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Nickname
|
/* Nickname */
|
||||||
val = strchr(irc->irc_raw, '!');
|
val = strchr(irc->irc_raw, '!');
|
||||||
if (val != NULL) {
|
if (val != NULL) {
|
||||||
val[0] = '\0';
|
val[0] = '\0';
|
||||||
|
@ -91,6 +91,13 @@ int IRCC_recv(IRCC_client *irc) {
|
||||||
if (msg_size == 0 || msg_size == -1)
|
if (msg_size == 0 || msg_size == -1)
|
||||||
return IRCC_DISCONNECTED;
|
return IRCC_DISCONNECTED;
|
||||||
|
|
||||||
|
char *ptr;
|
||||||
|
if ((ptr = strstr(irc->irc_raw, "PING :")) != NULL) {
|
||||||
|
*(strchr(ptr, 'I')) = 'O';
|
||||||
|
if (IRCC_usend(irc, ptr, strlen(irc->irc_raw)) == -1)
|
||||||
|
return IRCC_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
return IRCC_SUCCESS;
|
return IRCC_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,15 +106,7 @@ int IRCC_parse(IRCC_client *irc) {
|
||||||
irc->irc_msg = NULL;
|
irc->irc_msg = NULL;
|
||||||
irc->irc_nick = NULL;
|
irc->irc_nick = NULL;
|
||||||
|
|
||||||
if (!strncmp(irc->irc_raw, "PING", 4)) {
|
/* Check end of motd */
|
||||||
*(strchr(irc->irc_raw, 'I')) = 'O';
|
|
||||||
if (IRCC_usend(irc, strlen(irc->irc_raw)) == -1)
|
|
||||||
return IRCC_ERROR;
|
|
||||||
|
|
||||||
return IRCC_PING;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Check end of motd
|
|
||||||
if (strstr(irc->irc_raw, "PRIVMSG ") == NULL && strstr(irc->irc_raw, "MOTD"))
|
if (strstr(irc->irc_raw, "PRIVMSG ") == NULL && strstr(irc->irc_raw, "MOTD"))
|
||||||
return IRCC_CONNECTED;
|
return IRCC_CONNECTED;
|
||||||
|
|
||||||
|
@ -147,14 +146,14 @@ int IRCC_parse(IRCC_client *irc) {
|
||||||
|
|
||||||
int IRCC_register(IRCC_client *irc, const char *nickname) {
|
int IRCC_register(IRCC_client *irc, const char *nickname) {
|
||||||
off_t bytes = snprintf(irc->irc_raw, sizeof(irc->irc_raw), "NICK %s\r\n", nickname);
|
off_t bytes = snprintf(irc->irc_raw, sizeof(irc->irc_raw), "NICK %s\r\n", nickname);
|
||||||
if (IRCC_usend(irc, bytes) == -1)
|
if (IRCC_usend(irc, irc->irc_raw, bytes) == -1)
|
||||||
return IRCC_ERROR;
|
return IRCC_ERROR;
|
||||||
|
|
||||||
bytes = snprintf(irc->irc_raw, sizeof(irc->irc_raw), "USER %s 0 localhost :%s\r\n", nickname, nickname);
|
bytes = snprintf(irc->irc_raw, sizeof(irc->irc_raw), "USER %s 0 localhost :%s\r\n", nickname, nickname);
|
||||||
if (IRCC_usend(irc, bytes) == -1)
|
if (IRCC_usend(irc, irc->irc_raw, bytes) == -1)
|
||||||
return IRCC_ERROR;
|
return IRCC_ERROR;
|
||||||
|
|
||||||
//Motd skip
|
/* Motd skip */
|
||||||
while (1) {
|
while (1) {
|
||||||
int status = IRCC_recv(irc);
|
int status = IRCC_recv(irc);
|
||||||
if (status == IRCC_DISCONNECTED)
|
if (status == IRCC_DISCONNECTED)
|
||||||
|
@ -170,7 +169,7 @@ int IRCC_register(IRCC_client *irc, const char *nickname) {
|
||||||
|
|
||||||
int IRCC_join(IRCC_client *irc, const char *channel, const char *key) {
|
int IRCC_join(IRCC_client *irc, const char *channel, const char *key) {
|
||||||
off_t bytes = snprintf(irc->irc_raw, sizeof(irc->irc_raw), "JOIN %s %s\r\n", channel, (key) ? key : "");
|
off_t bytes = snprintf(irc->irc_raw, sizeof(irc->irc_raw), "JOIN %s %s\r\n", channel, (key) ? key : "");
|
||||||
if (IRCC_usend(irc, bytes) == -1)
|
if (IRCC_usend(irc, irc->irc_raw, bytes) == -1)
|
||||||
return IRCC_ERROR;
|
return IRCC_ERROR;
|
||||||
|
|
||||||
return IRCC_SUCCESS;
|
return IRCC_SUCCESS;
|
||||||
|
@ -178,7 +177,7 @@ int IRCC_join(IRCC_client *irc, const char *channel, const char *key) {
|
||||||
|
|
||||||
int IRCC_send(IRCC_client *irc, const char *channel, const char *msg) {
|
int IRCC_send(IRCC_client *irc, const char *channel, const char *msg) {
|
||||||
off_t bytes = snprintf(irc->irc_raw, sizeof(irc->irc_raw), "PRIVMSG %s :%s\r\n", channel, msg);
|
off_t bytes = snprintf(irc->irc_raw, sizeof(irc->irc_raw), "PRIVMSG %s :%s\r\n", channel, msg);
|
||||||
if (IRCC_usend(irc, bytes) == -1)
|
if (IRCC_usend(irc, irc->irc_raw, bytes) == -1)
|
||||||
return IRCC_ERROR;
|
return IRCC_ERROR;
|
||||||
|
|
||||||
return IRCC_SUCCESS;
|
return IRCC_SUCCESS;
|
||||||
|
|
2
C/irc.h
2
C/irc.h
|
@ -59,7 +59,7 @@ int IRCC_initssl(IRCC_client *irc);
|
||||||
void IRCC_close(IRCC_client *irc);
|
void IRCC_close(IRCC_client *irc);
|
||||||
|
|
||||||
//u - mean universal. Functions uses internal fields in structure
|
//u - mean universal. Functions uses internal fields in structure
|
||||||
int IRCC_usend(IRCC_client *irc, off_t bytes);
|
int IRCC_usend(IRCC_client *irc, const char *msg, off_t bytes);
|
||||||
int IRCC_urecv(IRCC_client *irc);
|
int IRCC_urecv(IRCC_client *irc);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue