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);
|
||||
}
|
||||
|
||||
int IRCC_usend(IRCC_client *irc, off_t bytes) {
|
||||
int IRCC_usend(IRCC_client *irc, const char *msg, off_t bytes) {
|
||||
#ifdef ENABLE_SSL
|
||||
if (irc->irc_usingssl)
|
||||
return SSL_write(irc->irc_ssl, irc->irc_raw, bytes);
|
||||
return SSL_write(irc->irc_ssl, msg, bytes);
|
||||
#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) {
|
||||
|
@ -32,7 +32,7 @@ int IRCC_connect(IRCC_client *irc, const char *ip, const unsigned int port) {
|
|||
if (!hp)
|
||||
return IRCC_ERROR;
|
||||
|
||||
//Only ipv4
|
||||
/* Only ipv4 */
|
||||
struct sockaddr_in client_str;
|
||||
memset(&client_str, 0, sizeof(client_str));
|
||||
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';
|
||||
|
||||
if (tmp != NULL) {
|
||||
//Message
|
||||
/* Message */
|
||||
char *val = strchr(tmp, ':');
|
||||
if (val != NULL) {
|
||||
val[0] = '\0';
|
||||
irc->irc_msg = val + 1;
|
||||
|
||||
//Del space before :
|
||||
/* Del space before : */
|
||||
*(val - 1) = '\0';
|
||||
}
|
||||
|
||||
//Channel
|
||||
/* Channel */
|
||||
val = strchr(tmp, ' ');
|
||||
if (val != NULL) {
|
||||
val[0] = '\0';
|
||||
irc->irc_channel = val + 1;
|
||||
}
|
||||
|
||||
//Nickname
|
||||
/* Nickname */
|
||||
val = strchr(irc->irc_raw, '!');
|
||||
if (val != NULL) {
|
||||
val[0] = '\0';
|
||||
|
@ -91,6 +91,13 @@ int IRCC_recv(IRCC_client *irc) {
|
|||
if (msg_size == 0 || msg_size == -1)
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -99,15 +106,7 @@ int IRCC_parse(IRCC_client *irc) {
|
|||
irc->irc_msg = NULL;
|
||||
irc->irc_nick = NULL;
|
||||
|
||||
if (!strncmp(irc->irc_raw, "PING", 4)) {
|
||||
*(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
|
||||
/* Check end of motd */
|
||||
if (strstr(irc->irc_raw, "PRIVMSG ") == NULL && strstr(irc->irc_raw, "MOTD"))
|
||||
return IRCC_CONNECTED;
|
||||
|
||||
|
@ -147,14 +146,14 @@ int IRCC_parse(IRCC_client *irc) {
|
|||
|
||||
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);
|
||||
if (IRCC_usend(irc, bytes) == -1)
|
||||
if (IRCC_usend(irc, irc->irc_raw, bytes) == -1)
|
||||
return IRCC_ERROR;
|
||||
|
||||
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;
|
||||
|
||||
//Motd skip
|
||||
/* Motd skip */
|
||||
while (1) {
|
||||
int status = IRCC_recv(irc);
|
||||
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) {
|
||||
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_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) {
|
||||
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_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);
|
||||
|
||||
//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);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue