fix
This commit is contained in:
parent
3c9fc382f0
commit
d6d2f02367
32
C/irc.c
32
C/irc.c
@ -1,6 +1,6 @@
|
|||||||
#include "irc.h"
|
#include "irc.h"
|
||||||
|
|
||||||
unsigned 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){
|
||||||
struct hostent *hp = gethostbyname(ip);
|
struct hostent *hp = gethostbyname(ip);
|
||||||
if (!hp)
|
if (!hp)
|
||||||
return IRCC_ERROR;
|
return IRCC_ERROR;
|
||||||
@ -27,13 +27,11 @@ unsigned int IRCC_connect(IRCC_client *irc, const char *ip, const unsigned int p
|
|||||||
return IRCC_SUCCESS;
|
return IRCC_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int IRCC_register(IRCC_client *irc, const char *nickname){
|
int IRCC_register(IRCC_client *irc, const char *nickname){
|
||||||
size_t size = strlen("NICK %s\r\nUSER %s 0 localhost :%s \r\n") + (strlen(nickname) * 3);
|
size_t size = strlen("NICK %s\r\nUSER %s 0 localhost :%s \r\n") + (strlen(nickname) * 3);
|
||||||
char *tmp = (char *)malloc(size);
|
char *tmp = (char *)malloc(size);
|
||||||
if (tmp == NULL){
|
if (tmp == NULL)
|
||||||
fprintf(stderr, "malloc returned NULL (IRCC_register)\n");
|
return IRCC_ALLOC;
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
sleep(2);
|
sleep(2);
|
||||||
snprintf(tmp, size, "NICK %s\r\nUSER %s 0 localhost :%s\r\n", nickname, nickname, nickname);
|
snprintf(tmp, size, "NICK %s\r\nUSER %s 0 localhost :%s\r\n", nickname, nickname, nickname);
|
||||||
@ -62,7 +60,7 @@ void IRCC_parse(char *tmp, IRCC_client *irc){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int IRCC_recv(IRCC_client *irc){
|
int IRCC_recv(IRCC_client *irc){
|
||||||
memset(irc->raw, '\0', IRCC_MSG_MAX);
|
memset(irc->raw, '\0', IRCC_MSG_MAX);
|
||||||
irc->channel = NULL;
|
irc->channel = NULL;
|
||||||
irc->msg = NULL;
|
irc->msg = NULL;
|
||||||
@ -121,28 +119,26 @@ unsigned int IRCC_recv(IRCC_client *irc){
|
|||||||
return IRCC_SUCCESS;
|
return IRCC_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRCC_send(IRCC_client *irc, const char *msg, const char *channel){
|
int IRCC_send(IRCC_client *irc, const char *msg, const char *channel){
|
||||||
size_t size = strlen("PRIVMSG :\r\n") + strlen(channel) + strlen(msg);
|
size_t size = strlen("PRIVMSG :\r\n") + strlen(channel) + strlen(msg);
|
||||||
|
|
||||||
char *tmp = (char *)malloc(size + 1);
|
char *tmp = (char *)malloc(size + 1);
|
||||||
if (tmp == NULL){
|
if (tmp == NULL)
|
||||||
fprintf(stderr, "malloc returned NULL (IRCC_send)\n");
|
return IRCC_ALLOC;
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(tmp, size, "PRIVMSG %s :%s\r\n", channel, msg);
|
snprintf(tmp, size, "PRIVMSG %s :%s\r\n", channel, msg);
|
||||||
send(irc->socket, tmp, strlen(tmp), 0);
|
int ret = send(irc->socket, tmp, strlen(tmp), 0);
|
||||||
|
|
||||||
memset(tmp, 0, size);
|
memset(tmp, 0, size);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int IRCC_init(IRCC_client *irc) {
|
int IRCC_init(IRCC_client *irc) {
|
||||||
irc->raw = (char *)malloc(IRCC_MSG_MAX + 1);
|
irc->raw = (char *)malloc(IRCC_MSG_MAX + 1);
|
||||||
if (irc->raw == NULL){
|
if (irc->raw == NULL)
|
||||||
fprintf(stderr, "malloc returned NULL (IRCC_init)\n");
|
return IRCC_ALLOC;
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
irc->msg = irc->nick = irc->channel = NULL;
|
irc->msg = irc->nick = irc->channel = NULL;
|
||||||
return IRCC_SUCCESS;
|
return IRCC_SUCCESS;
|
||||||
|
11
C/irc.h
11
C/irc.h
@ -32,6 +32,7 @@ enum {
|
|||||||
IRCC_CONNECTED,
|
IRCC_CONNECTED,
|
||||||
IRCC_DISCONNECTED,
|
IRCC_DISCONNECTED,
|
||||||
IRCC_ERROR,
|
IRCC_ERROR,
|
||||||
|
IRCC_ALLOC,
|
||||||
IRCC_SUCCESS
|
IRCC_SUCCESS
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -44,9 +45,9 @@ typedef struct {
|
|||||||
char *nick;
|
char *nick;
|
||||||
} IRCC_client;
|
} IRCC_client;
|
||||||
|
|
||||||
unsigned 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);
|
||||||
unsigned int IRCC_register(IRCC_client *irc, const char *nickname);
|
int IRCC_register(IRCC_client *irc, const char *nickname);
|
||||||
unsigned int IRCC_recv(IRCC_client *irc);
|
int IRCC_recv(IRCC_client *irc);
|
||||||
void IRCC_send(IRCC_client *irc, const char *msg, const char *channel);
|
int IRCC_send(IRCC_client *irc, const char *msg, const char *channel);
|
||||||
unsigned int IRCC_init(IRCC_client *irc);
|
int IRCC_init(IRCC_client *irc);
|
||||||
void IRCC_close(IRCC_client *irc);
|
void IRCC_close(IRCC_client *irc);
|
||||||
|
Loading…
Reference in New Issue
Block a user