Skip to content
Browse files

voip enabled can be set per connection

  • Loading branch information...
1 parent ee0cae2 commit 02243cd5b6601ff77a6a0423b65a0a1e93408dd6 @dinhviethoa dinhviethoa committed
View
15 src/data-types/mailstream_cfstream.c
@@ -176,11 +176,16 @@ static void cfstream_data_close(struct mailstream_cfstream_data * cfstream_data)
mailstream * mailstream_cfstream_open(const char * hostname, int16_t port)
{
+ return mailstream_cfstream_open_voip(hostname, port, mailstream_cfstream_voip_enabled);
+}
+
+mailstream * mailstream_cfstream_open_voip(const char * hostname, int16_t port, int voip_enabled)
+{
#if HAVE_CFNETWORK
mailstream_low * low;
mailstream * s;
- low = mailstream_low_cfstream_open(hostname, port);
+ low = mailstream_low_cfstream_open_voip(hostname, port, voip_enabled);
if (low == NULL) {
return NULL;
}
@@ -394,6 +399,11 @@ static void writeStreamCallback(CFWriteStreamRef stream, CFStreamEventType event
mailstream_low * mailstream_low_cfstream_open(const char * hostname, int16_t port)
{
+ return mailstream_low_cfstream_open_voip(hostname, port, mailstream_cfstream_voip_enabled);
+}
+
+mailstream_low * mailstream_low_cfstream_open_voip(const char * hostname, int16_t port, int voip_enabled)
+{
#if HAVE_CFNETWORK
mailstream_low * s;
struct mailstream_cfstream_data * cfstream_data;
@@ -408,7 +418,7 @@ mailstream_low * mailstream_low_cfstream_open(const char * hostname, int16_t por
CFStreamCreatePairWithSocketToHost(NULL, hostString, port, &readStream, &writeStream);
#if TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR
- if (mailstream_cfstream_voip_enabled) {
+ if (voip_enabled) {
CFReadStreamSetProperty(readStream, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP);
CFWriteStreamSetProperty(writeStream, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP);
}
@@ -457,6 +467,7 @@ mailstream_low * mailstream_low_cfstream_open(const char * hostname, int16_t por
#endif
}
+
static int mailstream_low_cfstream_close(mailstream_low * s)
{
#if HAVE_CFNETWORK
View
2 src/data-types/mailstream_cfstream.h
@@ -67,6 +67,8 @@ extern "C" {
mailstream_low * mailstream_low_cfstream_open(const char * hostname, int16_t port);
mailstream * mailstream_cfstream_open(const char * hostname, int16_t port);
+ mailstream_low * mailstream_low_cfstream_open_voip(const char * hostname, int16_t port, int voip_enabled);
+ mailstream * mailstream_cfstream_open_voip(const char * hostname, int16_t port, int voip_enabled);
/* first, set these settings */
void mailstream_cfstream_set_ssl_verification_mask(mailstream * s, int verification_mask);
View
76 src/low-level/imap/mailimap_socket.c
@@ -57,43 +57,49 @@
#define SERVICE_NAME_IMAP "imap2"
#define SERVICE_TYPE_TCP "tcp"
-static int mailimap_cfsocket_connect(mailimap * f, const char * server, uint16_t port);
+static int mailimap_cfsocket_connect_voip(mailimap * f, const char * server, uint16_t port, int voip_enabled);
LIBETPAN_EXPORT
-int mailimap_socket_connect(mailimap * f, const char * server, uint16_t port)
+int mailimap_socket_connect_voip(mailimap * f, const char * server, uint16_t port, int voip_enabled)
{
- int s;
- mailstream * stream;
-
-#if HAVE_CFNETWORK
- if (mailstream_cfstream_enabled) {
- return mailimap_cfsocket_connect(f, server, port);
- }
-#endif
-
- if (port == 0) {
- port = mail_get_service_port(SERVICE_NAME_IMAP, SERVICE_TYPE_TCP);
- if (port == 0)
- port = DEFAULT_IMAP_PORT;
- }
-
- /* Connection */
-
- s = mail_tcp_connect(server, port);
- if (s == -1)
- return MAILIMAP_ERROR_CONNECTION_REFUSED;
+ int s;
+ mailstream * stream;
+
+ #if HAVE_CFNETWORK
+ if (mailstream_cfstream_enabled) {
+ return mailimap_cfsocket_connect_voip(f, server, port, voip_enabled);
+ }
+ #endif
+
+ if (port == 0) {
+ port = mail_get_service_port(SERVICE_NAME_IMAP, SERVICE_TYPE_TCP);
+ if (port == 0)
+ port = DEFAULT_IMAP_PORT;
+ }
+
+ /* Connection */
+
+ s = mail_tcp_connect(server, port);
+ if (s == -1)
+ return MAILIMAP_ERROR_CONNECTION_REFUSED;
+
+ stream = mailstream_socket_open(s);
+ if (stream == NULL) {
+ #ifdef WIN32
+ closesocket(s);
+ #else
+ close(s);
+ #endif
+ return MAILIMAP_ERROR_MEMORY;
+ }
+
+ return mailimap_connect(f, stream);
+}
- stream = mailstream_socket_open(s);
- if (stream == NULL) {
-#ifdef WIN32
- closesocket(s);
-#else
- close(s);
-#endif
- return MAILIMAP_ERROR_MEMORY;
- }
-
- return mailimap_connect(f, stream);
+LIBETPAN_EXPORT
+int mailimap_socket_connect(mailimap * f, const char * server, uint16_t port)
+{
+ return mailimap_socket_connect_voip(f, server, port, mailstream_cfstream_voip_enabled);
}
@@ -141,11 +147,11 @@ int mailimap_socket_starttls_with_callback(mailimap * f,
return MAILIMAP_NO_ERROR;
}
-static int mailimap_cfsocket_connect(mailimap * f, const char * server, uint16_t port)
+static int mailimap_cfsocket_connect_voip(mailimap * f, const char * server, uint16_t port, int voip_enabled)
{
mailstream * stream;
- stream = mailstream_cfstream_open(server, port);
+ stream = mailstream_cfstream_open_voip(server, port, voip_enabled);
if (stream == NULL) {
return MAILIMAP_ERROR_CONNECTION_REFUSED;
}
View
3 src/low-level/imap/mailimap_socket.h
@@ -48,6 +48,9 @@ extern "C" {
#include <libetpan/mailimap_types.h>
LIBETPAN_EXPORT
+int mailimap_socket_connect_voip(mailimap * f, const char * server, uint16_t port, int voip_enabled);
+
+LIBETPAN_EXPORT
int mailimap_socket_connect(mailimap * f, const char * server, uint16_t port);
LIBETPAN_EXPORT
View
21 src/low-level/imap/mailimap_ssl.c
@@ -57,18 +57,24 @@
#define SERVICE_NAME_IMAPS "imaps"
#define SERVICE_TYPE_TCP "tcp"
-static int mailimap_cfssl_connect(mailimap * f, const char * server, uint16_t port);
+static int mailimap_cfssl_connect_voip(mailimap * f, const char * server, uint16_t port, int voip_enabled);
int mailimap_ssl_connect_with_callback(mailimap * f, const char * server, uint16_t port,
void (* callback)(struct mailstream_ssl_context * ssl_context, void * data), void * data)
{
+ return mailimap_ssl_connect_voip_with_callback(f, server, port, mailstream_cfstream_voip_enabled, callback, data);
+}
+
+int mailimap_ssl_connect_voip_with_callback(mailimap * f, const char * server, uint16_t port, int voip_enabled,
+ void (* callback)(struct mailstream_ssl_context * ssl_context, void * data), void * data)
+{
int s;
mailstream * stream;
#if HAVE_CFNETWORK
if (mailstream_cfstream_enabled) {
if (callback == NULL) {
- return mailimap_cfssl_connect(f, server, port);
+ return mailimap_cfssl_connect_voip(f, server, port, voip_enabled);
}
}
#endif
@@ -100,16 +106,21 @@ int mailimap_ssl_connect_with_callback(mailimap * f, const char * server, uint16
int mailimap_ssl_connect(mailimap * f, const char * server, uint16_t port)
{
- return mailimap_ssl_connect_with_callback(f, server, port,
+ return mailimap_ssl_connect_voip(f, server, port, mailstream_cfstream_voip_enabled);
+}
+
+int mailimap_ssl_connect_voip(mailimap * f, const char * server, uint16_t port, int voip_enabled)
+{
+ return mailimap_ssl_connect_voip_with_callback(f, server, port, voip_enabled,
NULL, NULL);
}
-static int mailimap_cfssl_connect(mailimap * f, const char * server, uint16_t port)
+static int mailimap_cfssl_connect_voip(mailimap * f, const char * server, uint16_t port, int voip_enabled)
{
mailstream * stream;
int r;
- stream = mailstream_cfstream_open(server, port);
+ stream = mailstream_cfstream_open_voip(server, port, voip_enabled);
if (stream == NULL) {
return MAILIMAP_ERROR_CONNECTION_REFUSED;
}
View
7 src/low-level/imap/mailimap_ssl.h
@@ -51,9 +51,16 @@ LIBETPAN_EXPORT
int mailimap_ssl_connect(mailimap * f, const char * server, uint16_t port);
LIBETPAN_EXPORT
+int mailimap_ssl_connect_voip(mailimap * f, const char * server, uint16_t port, int voip_enabled);
+
+LIBETPAN_EXPORT
int mailimap_ssl_connect_with_callback(mailimap * f, const char * server, uint16_t port,
void (* callback)(struct mailstream_ssl_context * ssl_context, void * data), void * data);
+LIBETPAN_EXPORT
+int mailimap_ssl_connect_voip_with_callback(mailimap * f, const char * server, uint16_t port, int voip_enabled,
+ void (* callback)(struct mailstream_ssl_context * ssl_context, void * data), void * data);
+
#ifdef __cplusplus
}
#endif

0 comments on commit 02243cd

Please sign in to comment.
Something went wrong with that request. Please try again.