Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,17 @@ include ../../Makefile.defs
auto_gen=
NAME=push.so

DEFS += -I$(LOCALBASE)/ssl/include
LIBS += -L$(LOCALBASE)/lib -L$(LOCALBASE)/ssl/lib \
-L$(LOCALBASE)/lib64 -L$(LOCALBASE)/ssl/lib64 \
-lssl -lcrypto
DEFS += -I$(LOCALBASE)/ssl/include
LIBS += -L$(LOCALBASE)/lib -L$(LOCALBASE)/ssl/lib \
-L$(LOCALBASE)/lib64 -L$(LOCALBASE)/ssl/lib64 \
-lssl -lcrypto

CFLAGS+=-g3
#include ../../Makefile.push

DEFS+=-DKAMAILIO_MOD_INTERFACE

SERLIBPATH=../../lib
SER_LIBS+=$(SERLIBPATH)/kcore/kcore
SER_LIBS+=$(SERLIBPATH)/srdb1/srdb1


include ../../Makefile.modules
2 changes: 1 addition & 1 deletion apns_feedback.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "push_ssl_utils.h"
#include "apns_feedback.h"

#include "../../dprint.h"
#include "../../core/dprint.h"

#define CHECK_FEEDBACK_TIMEOUT 3600

Expand Down
8 changes: 4 additions & 4 deletions push.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

#include <arpa/inet.h>

#include "../../sr_module.h"
#include "../../dprint.h"
#include "../../mem/mem.h"
#include "../../parser/parse_to.h"
#include "../../core/sr_module.h"
#include "../../core/dprint.h"
#include "../../core/mem/mem.h"
#include "../../core/parser/parse_to.h"
#include "../../lib/cds/list.h"
#include "../../lib/srdb1/db.h"
#include "../../lib/srdb1/db_val.h"
Expand Down
4 changes: 2 additions & 2 deletions push_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
#include <sys/select.h>
#include <sys/time.h>

#include "../../dprint.h"
#include "../../core/dprint.h"
#include "../../lib/srdb1/db_val.h"
#include "../../locking.h"
#include "../../core/locking.h"

#include "push_common.h"
#include "push_ssl_utils.h"
Expand Down
2 changes: 1 addition & 1 deletion push_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "../../lib/srdb1/db.h"

#define ENABLE_FEEDBACK_SERVICE
//#define ENABLE_FEEDBACK_SERVICE

#define PUSH_TABLE_VERSION 1

Expand Down
14 changes: 7 additions & 7 deletions push_mod.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
#include <arpa/inet.h>
#include <netdb.h>

#include "../../sr_module.h"
#include "../../trim.h"
#include "../../dprint.h"
#include "../../mem/mem.h"
#include "../../parser/parse_to.h"
#include "../../parser/parse_uri.h"
#include "../../cfg/cfg_struct.h"
#include "../../core/sr_module.h"
#include "../../core/trim.h"
#include "../../core/dprint.h"
#include "../../core/mem/mem.h"
#include "../../core/parser/parse_to.h"
#include "../../core/parser/parse_uri.h"
#include "../../core/cfg/cfg_struct.h"

#include "push_mod.h"
#include "push.h"
Expand Down
48 changes: 24 additions & 24 deletions push_ssl_utils.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* $Id$
*
*
* APNs support module
*
* Copyright (C) 2013 Volodymyr Tarasenko
Expand Down Expand Up @@ -42,7 +42,7 @@
#include <openssl/ssl.h>
#include <openssl/err.h>

#include "../../dprint.h"
#include "../../core/dprint.h"

#include "push_common.h"
#include "push_ssl_utils.h"
Expand All @@ -57,7 +57,7 @@ struct Push_error_Item
{
char code;
const char* msg;
} push_codes[] =
} push_codes[] =
{
{0, "No errors encountered"},
{1, "Processing error"},
Expand All @@ -72,7 +72,7 @@ struct Push_error_Item
{255, "None (unknown)"}
};

// Declaration: Static functions
// Declaration: Static functions
//static void read_status(PushServer* server);
static int load_ssl_certs(SSL_CTX* ctx, char* cert, char* key, char* ca);
static int socket_init(const char* server, uint16_t port);
Expand Down Expand Up @@ -102,7 +102,7 @@ static int load_ssl_certs(SSL_CTX* ctx, char* cert, char* key, char* ca)
LOG_SSL_ERROR(err);
return -1;
}

err = SSL_CTX_load_verify_locations(ctx, ca, 0);
if (err != 1)
{
Expand Down Expand Up @@ -136,15 +136,15 @@ static int socket_init(const char* server, uint16_t port)
memcpy(&sa.sin_addr, host->h_addr_list[0], host->h_length);
}

LM_ERR("Create a socket and connect it to %s:%d\n", server, port);
LM_DBG("Create a socket and connect it to %s:%d\n", server, port);
/* Create a socket and connect to server using normal socket calls. */
sd = socket (PF_INET, SOCK_STREAM, 0);
if (sd == -1)
{
LM_ERR("Socket creation error\n");
return -1;
}

err = connect(sd, (struct sockaddr*) &sa, sizeof(sa));
if (err == -1)
{
Expand All @@ -154,7 +154,7 @@ static int socket_init(const char* server, uint16_t port)
}

LM_DBG("Socket %d connected\n", sd);

return sd;
}

Expand Down Expand Up @@ -195,10 +195,10 @@ static SSL* ssl_start(int sd, SSL_CTX* ctx)
LM_DBG("SSL connect...\n");
err = SSL_connect (s);
LM_DBG("SSL connect done...\n");
if ((err) == -1)
{
ERR_print_errors_fp(stderr);
return NULL;
if ((err) == -1)
{
ERR_print_errors_fp(stderr);
return NULL;
}
LM_DBG("SSL connect done...\n");

Expand All @@ -215,7 +215,7 @@ static int check_cert(SSL* s)
data exchange to be successful. */
/* /\* Get the cipher - opt *\/ */
/* printf ("SSL connection using %s\n", SSL_get_cipher (ssl)); */

/* Get server's certificate (note: beware of dynamic allocation) - opt */
server_cert = SSL_get_peer_certificate (s);
if (server_cert == NULL)
Expand Down Expand Up @@ -299,14 +299,14 @@ int send_push_data(PushServer* server, const char* buffer, uint32_t length)
int err = 0;
uint32_t written = 0;
int first_try = 1;

again:
if ((server->socket == -1) && (server->flags != NoReconnect))
if ((server->socket == -1 || server->ssl == NULL) && (server->flags != NoReconnect))
establish_ssl_connection(server);

while(written != length)
{
if (server->socket == -1)
if (server->socket == -1 || server->ssl == NULL)
{
LM_ERR("Cannot write, peer disconnected...\n");
return -1;
Expand Down Expand Up @@ -344,7 +344,7 @@ int send_push_data(PushServer* server, const char* buffer, uint32_t length)
}

// read_status(server);
if (server->socket == -1 && first_try)
if ((server->socket == -1 || server->ssl == NULL) && first_try)
{
first_try = 0;
goto again;
Expand Down Expand Up @@ -389,9 +389,9 @@ int establish_ssl_connection(PushServer* server)

LM_DBG("SSL context started, looading certs if any\n");
if (server->cert_file)
load_ssl_certs(server->ssl_ctx,
server->cert_file,
server->cert_key,
load_ssl_certs(server->ssl_ctx,
server->cert_file,
server->cert_key,
server->cert_ca);

LM_DBG("Create new socket, old: %d",server->socket);
Expand All @@ -403,7 +403,7 @@ int establish_ssl_connection(PushServer* server)
return -1;
}

LM_DBG("Push socket initialed\n");
LM_DBG("Push socket initialed\n");

server->ssl = ssl_start(server->socket, server->ssl_ctx);
if (server->ssl == NULL)
Expand All @@ -430,7 +430,7 @@ int establish_ssl_connection(PushServer* server)

void ssl_init()
{
SSL_library_init();
SSL_library_init();
SSL_load_error_strings();
}

Expand All @@ -449,7 +449,7 @@ int extended_read(PushServer* server,
fd_set readfds;
struct timeval timeout;

if ((server->socket == -1) && -1 == establish_ssl_connection(server))
if ((server->socket == -1 || server->ssl == NULL) && -1 == establish_ssl_connection(server))
{
LM_ERR("extended_read failed, cannot reconnecd initialization failed\n");
return -1;
Expand All @@ -466,7 +466,7 @@ int extended_read(PushServer* server,
{
FD_SET(comm_sock, &readfds);
}

mx = server->socket > comm_sock ? server->socket+1 : comm_sock +1;

err = select(mx, &readfds, 0, 0, &timeout);
Expand Down