summaryrefslogtreecommitdiff
path: root/ccast
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2016-10-02 19:25:17 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2016-10-02 19:25:17 +0200
commitc2ca7be5a751879159f3cb591a64bb9568b79762 (patch)
tree04e38d4f4a2aad4d789bda0a65b7abb80a3439a2 /ccast
parent45c152c326d87478fbf41714b4b8e2f7b57a282b (diff)
parent3db384424bd7398ffbb7a355cab8f15f3add009f (diff)
Updated version 1.9.1+repack from 'upstream/1.9.1+repack'
with Debian dir 98a996367aa69ae41accf9c6d369f600bc94de80
Diffstat (limited to 'ccast')
-rw-r--r--ccast/Readme.txt2
-rw-r--r--ccast/ccast.c2
-rw-r--r--ccast/ccmdns.c82
-rw-r--r--ccast/ccmes.c6
-rw-r--r--ccast/ccpacket.c6
5 files changed, 43 insertions, 55 deletions
diff --git a/ccast/Readme.txt b/ccast/Readme.txt
index 3b95267..6823ba9 100644
--- a/ccast/Readme.txt
+++ b/ccast/Readme.txt
@@ -9,4 +9,4 @@ Hierarchy:
ccpacket.c socket write/read
ccmdns.c MDNS sign on
- axTLS
+ axTLS SSL/TLS library
diff --git a/ccast/ccast.c b/ccast/ccast.c
index 981b5ae..2a2c1a8 100644
--- a/ccast/ccast.c
+++ b/ccast/ccast.c
@@ -471,7 +471,7 @@ static int start_ccast(ccast *p) {
DBG((g_log,0,"start_ccast: PING failed with '%s'\n",ccmessv_emes(merr)))
return 1;
}
-
+
/* Wait for a PONG */
// get_a_reply(p->messv, NULL);
#endif
diff --git a/ccast/ccmdns.c b/ccast/ccmdns.c
index 76ae4d1..1000db3 100644
--- a/ccast/ccmdns.c
+++ b/ccast/ccmdns.c
@@ -78,7 +78,7 @@
#include "conv.h"
#include "ccmdns.h"
-#undef DEBUG
+#undef DEBUG /* [und] */
#if defined(NT) // Windows specific
# if _WIN32_WINNT < 0x0400
@@ -128,8 +128,12 @@ typedef int SOCKET;
#ifdef DEBUG
# define DBG(xxx) a1logd xxx ;
+# define DBG2(xxx) a1logd xxx ;
+# define DLEV 0
#else
# define DBG(xxx) ;
+# define DBG2(xxx) a1logd xxx ;
+# define DLEV 2
#endif /* DEBUG */
/* ================================================================ */
@@ -285,7 +289,8 @@ static int init_send_mDNS(SOCKET *psock) {
DBG((g_log,0,"[disabling loopback failed with %d]\n",ERRNO))
}
-#ifdef NEVER // We only want this to be local
+ /* Is this desirable ? */
+
/* increase the IP TTL from the default of one to 64, so our
* multicast datagrams can get off of the local network
*/
@@ -297,7 +302,6 @@ static int init_send_mDNS(SOCKET *psock) {
closesocket(sock);
return 1;
}
-#endif
if (psock != NULL)
*psock = sock;
@@ -572,80 +576,56 @@ static int receive_mDNS(SOCKET sock, ccast_id ***ids, int emsec) {
/* Get a list of Chromecasts. Return NULL on error */
/* Last pointer in array is NULL */
-/* Takes 0.5 second to return */
+/* Takes 1.0 second to return */
ccast_id **get_ccids() {
ccast_id **ids = NULL;
- int i, j;
+ int i, j, k;
unsigned int smsec;
+ int waittime = 100;
SOCKET ssock, rsock;
+ DBG2((g_log,DLEV,"get_ccids: called\n"))
+
if (init_mDNS()) {
- DBG((g_log,0,"init_mDNS() failed\n"))
+ DBG2((g_log,0,"get_ccids: init_mDNS() failed\n"))
return NULL;
}
if (init_send_mDNS(&ssock)) {
- DBG((g_log,0,"init_send_mDNS() failed\n"))
+ DBG2((g_log,0,"get_ccids: init_send_mDNS() failed\n"))
return NULL;
}
if (init_receive_mDNS(&rsock)) {
- DBG((g_log,0,"init_receive_mDNS() failed\n"))
+ DBG2((g_log,0,"get_ccids: init_receive_mDNS() failed\n"))
closesocket(ssock);
return NULL;
}
smsec = msec_time();
- DBG((g_log,0,"Sending mDNS query:\n"))
- if (send_mDNS(ssock)) {
- DBG((g_log,0,"send_mDNS() #1 failed\n"))
- closesocket(ssock);
- closesocket(rsock);
- return NULL;
- }
-
- if (receive_mDNS(rsock, &ids, 100)) {
- DBG((g_log,0,"receive_mDNS() #1 failed\n"))
- closesocket(ssock);
- closesocket(rsock);
- return NULL;
- }
-
- if (ids == NULL && (msec_time() - smsec) < 200) {
+ /* Try a few times, with increasing response wait time */
+ for (k = 1; ids == NULL && (msec_time() - smsec) < 1000; k++) {
- DBG((g_log,0,"Sending another mDNS query:\n"))
+ DBG2((g_log,DLEV,"get_ccids: Sending mDNS query #%d:\n",k))
if (send_mDNS(ssock)) {
- DBG((g_log,0,"send_mDNS() #2 failed\n"))
- closesocket(ssock);
- closesocket(rsock);
- return NULL;
- }
-
- if (receive_mDNS(rsock, &ids, 500)) {
- DBG((g_log,0,"receive_mDNS() #2 failed\n"))
+ DBG2((g_log,0,"get_ccids: send_mDNS() #1 failed\n"))
closesocket(ssock);
closesocket(rsock);
return NULL;
}
- }
-
- if (ids == NULL) {
-
- DBG((g_log,0,"Sending a final mDNS query:\n"))
- if (send_mDNS(ssock)) {
- DBG((g_log,0,"send_mDNS() #3 failed\n"))
+
+ DBG2((g_log,DLEV,"get_ccids: Waiting for mDNS reply #%d:\n",k))
+ if (receive_mDNS(rsock, &ids, waittime)) {
+ DBG2((g_log,0,"get_ccids: receive_mDNS() #%d failed\n",k))
closesocket(ssock);
closesocket(rsock);
return NULL;
}
+ if (ids != NULL)
+ DBG2((g_log,DLEV,"get_ccids: Got reply\n"))
- if (receive_mDNS(rsock, &ids, 500)) {
- DBG((g_log,0,"receive_mDNS() #3 failed\n"))
- closesocket(ssock);
- closesocket(rsock);
- return NULL;
- }
+ waittime *= 2;
}
closesocket(ssock);
@@ -653,8 +633,9 @@ ccast_id **get_ccids() {
/* If no ChromCasts found, return an empty list */
if (ids == NULL) {
+ DBG2((g_log,DLEV,"get_ccids: no devices found\n"))
if ((ids = calloc(sizeof(ccast_id *), 1)) == NULL) {
- DBG((g_log,0,"calloc fail\n"))
+ DBG2((g_log,0,"get_ccids: calloc fail\n"))
return NULL;
}
}
@@ -670,6 +651,13 @@ ccast_id **get_ccids() {
}
}
+ for (i = 0; ids[i] != NULL; i++) {
+ DBG2((g_log,DLEV," Entry %d:\n",i))
+ DBG2((g_log,DLEV," Name: %s\n",ids[i]->name))
+ DBG2((g_log,DLEV," IP: %s\n",ids[i]->ip))
+ }
+ DBG2((g_log,DLEV,"get_ccids: Returning %d devices\n",i))
+
return ids;
}
diff --git a/ccast/ccmes.c b/ccast/ccmes.c
index d0581d9..b8f9de0 100644
--- a/ccast/ccmes.c
+++ b/ccast/ccmes.c
@@ -42,8 +42,8 @@
#include "cast_channel.pb-c.h"
#include "ccmes.h"
-#undef LOWVERBTRACE /* Low verboseness message trace */
-#undef DEBUG /* Full message trace + debug */
+#undef LOWVERBTRACE /* [und] Low verboseness message trace */
+#undef DEBUG /* [und] Full message trace + debug */
/* ------------------------------------------------------------------- */
@@ -115,7 +115,7 @@ static void mes_dump(ccmes *mes, char *pfx) {
/* Would like to pretty print the JSON data */
/* ie. convert json_reformat.c to a function */
#ifdef DEBUG
- a1logd(g_log,0," %d bytes of text data:\n",strlen(mes->data));
+ a1logd(g_log,0," %d bytes of text data:\n",strlen((char *)mes->data));
a1logd(g_log,0," '%s'\n",mes->data);
#else
yajl_val tnode, v, i;
diff --git a/ccast/ccpacket.c b/ccast/ccpacket.c
index 2efc11f..df2a0af 100644
--- a/ccast/ccpacket.c
+++ b/ccast/ccpacket.c
@@ -37,9 +37,9 @@
# include "openssl/ssl.h" /* OpenSSL header */
#endif
-#undef DEBUG
-#undef DUMPSDATA /* Send data */
-#undef DUMPRDATA /* Receive data */
+#undef DEBUG /* [und] */
+#undef DUMPSDATA /* [und] Send data */
+#undef DUMPRDATA /* [und] Receive data */
#if defined(NT) // Windows specific
# if _WIN32_WINNT < 0x0400