Upload files to "C"
This commit is contained in:
parent
8d36d6a974
commit
ee7b7cd779
2 changed files with 61 additions and 55 deletions
30
C/irc.c
30
C/irc.c
|
@ -10,24 +10,24 @@
|
|||
#include "irc.h"
|
||||
|
||||
int IRCC_urecv(IRCC_client *irc) {
|
||||
#ifdef ENABLE_SSL
|
||||
#if defined(ENABLE_SSL) || defined(ENABLE_TLS)
|
||||
if (irc->irc_usingssl)
|
||||
return SSL_read(irc->irc_ssl, irc->irc_raw, sizeof(irc->irc_raw));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return recv(irc->irc_socket, irc->irc_raw, sizeof(irc->irc_raw), 0);
|
||||
}
|
||||
|
||||
int IRCC_usend(IRCC_client *irc, const char *msg, off_t bytes) {
|
||||
#ifdef ENABLE_SSL
|
||||
int IRCC_usend(IRCC_client *irc, const char *msg, const int bytes) {
|
||||
#if defined(ENABLE_SSL) || defined(ENABLE_TLS)
|
||||
if (irc->irc_usingssl)
|
||||
return SSL_write(irc->irc_ssl, msg, bytes);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
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 int port) {
|
||||
struct hostent *hp = gethostbyname(ip);
|
||||
if (!hp)
|
||||
return IRCC_ERROR;
|
||||
|
@ -145,7 +145,7 @@ 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);
|
||||
int bytes = snprintf(irc->irc_raw, sizeof(irc->irc_raw), "NICK %s\r\n", nickname);
|
||||
if (IRCC_usend(irc, irc->irc_raw, bytes) == -1)
|
||||
return IRCC_ERROR;
|
||||
|
||||
|
@ -168,7 +168,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 : "");
|
||||
ssize_t bytes = snprintf(irc->irc_raw, sizeof(irc->irc_raw), "JOIN %s %s\r\n", channel, (key) ? key : "");
|
||||
if (IRCC_usend(irc, irc->irc_raw, bytes) == -1)
|
||||
return IRCC_ERROR;
|
||||
|
||||
|
@ -176,7 +176,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);
|
||||
ssize_t bytes = snprintf(irc->irc_raw, sizeof(irc->irc_raw), "PRIVMSG %s :%s\r\n", channel, msg);
|
||||
if (IRCC_usend(irc, irc->irc_raw, bytes) == -1)
|
||||
return IRCC_ERROR;
|
||||
|
||||
|
@ -185,7 +185,7 @@ int IRCC_send(IRCC_client *irc, const char *channel, const char *msg) {
|
|||
}
|
||||
|
||||
int IRCC_initssl(IRCC_client *irc) {
|
||||
#ifdef ENABLE_SSL
|
||||
#if defined(ENABLE_SSL) || defined(ENABLE_TLS)
|
||||
irc->irc_ssl = NULL;
|
||||
irc->irc_sslctx = NULL;
|
||||
irc->irc_sslmethod = NULL;
|
||||
|
@ -209,9 +209,10 @@ int IRCC_initssl(IRCC_client *irc) {
|
|||
|
||||
irc->irc_usingssl = 1;
|
||||
|
||||
#else
|
||||
#else
|
||||
(void)irc;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
return IRCC_SUCCESS;
|
||||
}
|
||||
|
@ -220,7 +221,7 @@ void IRCC_close(IRCC_client *irc) {
|
|||
close(irc->irc_socket);
|
||||
irc->irc_msg = irc->irc_nick = irc->irc_channel = NULL;
|
||||
|
||||
#ifdef ENABLE_SSL
|
||||
#if defined(ENABLE_SSL) || defined(ENABLE_TLS)
|
||||
if (!irc->irc_usingssl)
|
||||
return;
|
||||
|
||||
|
@ -231,6 +232,5 @@ void IRCC_close(IRCC_client *irc) {
|
|||
|
||||
if (irc->irc_sslctx != NULL)
|
||||
SSL_CTX_free(irc->irc_sslctx);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
20
C/irc.h
20
C/irc.h
|
@ -12,9 +12,10 @@
|
|||
|
||||
#define IRCC_MSG_MAX 512
|
||||
#define IRCC_PING_TIMEOUT 600
|
||||
#define IRCC_VERSION "2.0"
|
||||
|
||||
#ifdef ENABLE_SSL
|
||||
#include <openssl/ssl.h>
|
||||
#if defined(ENABLE_SSL) || defined(ENABLE_TLS)
|
||||
#include <openssl/ssl.h>
|
||||
#endif
|
||||
|
||||
enum {
|
||||
|
@ -33,23 +34,28 @@ enum {
|
|||
};
|
||||
|
||||
typedef struct {
|
||||
/* RW */
|
||||
int irc_socket;
|
||||
|
||||
char irc_raw[IRCC_MSG_MAX + 1];
|
||||
|
||||
/* RONLY */
|
||||
char *irc_msg;
|
||||
char *irc_channel;
|
||||
char *irc_nick;
|
||||
|
||||
#ifdef ENABLE_SSL
|
||||
#if defined(ENABLE_SSL) || defined(ENABLE_TLS)
|
||||
/* RONLY */
|
||||
int irc_usingssl;
|
||||
|
||||
SSL_METHOD *irc_sslmethod;
|
||||
SSL_CTX *irc_sslctx;
|
||||
SSL *irc_ssl;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
} IRCC_client;
|
||||
|
||||
int IRCC_connect(IRCC_client *irc, const char *ip, const unsigned int port);
|
||||
int IRCC_connect(IRCC_client *irc, const char *ip, const int port);
|
||||
int IRCC_recv(IRCC_client *irc);
|
||||
int IRCC_parse(IRCC_client *irc);
|
||||
int IRCC_join(IRCC_client *irc, const char *channel, const char *key);
|
||||
|
@ -58,8 +64,8 @@ int IRCC_register(IRCC_client *irc, const char *nickname);
|
|||
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, const char *msg, off_t bytes);
|
||||
/* Raw data operations. Uses tls when possible */
|
||||
int IRCC_usend(IRCC_client *irc, const char *msg, const int bytes);
|
||||
int IRCC_urecv(IRCC_client *irc);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue