response_realloc, response_body, response_header, response_code,
};
-static pthread_mutex_t dacp_conversation_lock = PTHREAD_MUTEX_INITIALIZER;
-static pthread_mutex_t dacp_server_information_lock = PTHREAD_MUTEX_INITIALIZER;
+// static pthread_mutex_t dacp_conversation_lock = PTHREAD_MUTEX_INITIALIZER;
+// static pthread_mutex_t dacp_server_information_lock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t dacp_conversation_lock;
+static pthread_mutex_t dacp_server_information_lock;
static pthread_cond_t dacp_server_information_cv = PTHREAD_COND_INITIALIZER;
int dacp_send_command(const char *command, char **body, ssize_t *bodysize) {
response.size = 0;
response.code = 0;
- char portstring[10], server[256], message[1024];
+ char portstring[10], server[1024], message[1024];
memset(&portstring, 0, sizeof(portstring));
if (dacp_server.connection_family == AF_INET6) {
- sprintf(server, "%s%%%u", dacp_server.ip_string, dacp_server.scope_id);
+ snprintf(server, sizeof(server), "%s%%%u", dacp_server.ip_string, dacp_server.scope_id);
} else {
strcpy(server, dacp_server.ip_string);
}
- sprintf(portstring, "%u", dacp_server.port);
+ snprintf(portstring, sizeof(portstring), "%u", dacp_server.port);
// first, load up address structs with getaddrinfo():
} else {
// debug(1,"DACP connect succeeded.");
- sprintf(message,
- "GET /ctrl-int/1/%s HTTP/1.1\r\nHost: %s:%u\r\nActive-Remote: %u\r\n\r\n",
- command, dacp_server.ip_string, dacp_server.port, dacp_server.active_remote_id);
+ snprintf(message, sizeof(message),
+ "GET /ctrl-int/1/%s HTTP/1.1\r\nHost: %s:%u\r\nActive-Remote: %u\r\n\r\n",
+ command, dacp_server.ip_string, dacp_server.port, dacp_server.active_remote_id);
// Send command
// debug(1,"DACP connect message: \"%s\".",message);
if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (const char *)&tv, sizeof tv) == -1)
debug(1, "Error %d setting receive timeout for DACP service.", errno);
int ndata = recv(sockfd, buffer, sizeof(buffer), 0);
- // debug(1,"Received %d bytes: \"%s\".",ndata,buffer);
+ debug(3, "Received %d bytes: \"%s\".", ndata, buffer);
if (ndata <= 0) {
debug(1, "dacp_send_command -- error receiving response for command \"%s\".",
command);
else
idle_scan_count = 0;
- debug(3, "Scan Result: %d, Bad Scan Count: %d, Idle Scan Count: %d.", result, bad_result_count,
+ debug(2, "Scan Result: %d, Bad Scan Count: %d, Idle Scan Count: %d.", result, bad_result_count,
idle_scan_count);
if ((bad_result_count == config.scan_max_bad_response_count) ||
}
void dacp_monitor_start() {
+ int rc;
+ pthread_mutexattr_t mta;
+
+ rc = pthread_mutexattr_init(&mta);
+ if (rc)
+ debug(1, "Error creating the DACP Conversation Lock Mutex Att Init");
+
+ rc = pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_ERRORCHECK);
+ if (rc)
+ debug(1, "Error creating the DACP Conversation Lock Mutex Errorcheck");
+
+ // rc = pthread_mutexattr_setname_np(&mta, "DACP Conversation Lock");
+ // if (rc)
+ // debug(1,"Error creating the DACP Conversation Lock Mutex Set Name");
+
+ rc = pthread_mutex_init(&dacp_conversation_lock, &mta);
+ if (rc)
+ debug(1, "Error creating the DACP Conversation Lock Mutex Init");
+
+ rc = pthread_mutexattr_destroy(&mta);
+ if (rc)
+ debug(1, "Error creating the DACP Conversation Lock Attr Destroy");
+
+ rc = pthread_mutexattr_init(&mta);
+ if (rc)
+ debug(1, "Error creating the DACP Server Information Lock Mutex Att Init");
+
+ rc = pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_ERRORCHECK);
+ if (rc)
+ debug(1, "Error creating the DACP Server Information Lock Mutex Errorcheck");
+
+ // rc = pthread_mutexattr_setname_np(&mta, "DACP Conversation Lock");
+ // if (rc)
+ // debug(1,"Error creating the DACP Server Information Lock Mutex Set Name");
+
+ rc = pthread_mutex_init(&dacp_server_information_lock, &mta);
+ if (rc)
+ debug(1, "Error creating the DACP Server Information Lock Mutex Init");
+
+ rc = pthread_mutexattr_destroy(&mta);
+ if (rc)
+ debug(1, "Error creating the DACP Server Information Lock Attr Destroy");
+
memset(&dacp_server, 0, sizeof(dacp_server_record));
pthread_create(&dacp_monitor_thread, NULL, dacp_monitor_thread_code, NULL);
}
debug(2, "dacp_set_include_speaker_volume to %" PRId32 ".", vo);
char message[1000];
memset(message, 0, sizeof(message));
- sprintf(message, "setproperty?include-speaker-id=%" PRId64 "&dmcp.volume=%" PRId32 "",
- machine_number, vo);
+ snprintf(message, sizeof(message),
+ "setproperty?include-speaker-id=%" PRId64 "&dmcp.volume=%" PRId32 "", machine_number,
+ vo);
debug(2, "sending \"%s\"", message);
return send_simple_dacp_command(message);
// should return 204
int dacp_set_speaker_volume(int64_t machine_number, int32_t vo) {
char message[1000];
memset(message, 0, sizeof(message));
- sprintf(message, "setproperty?speaker-id=%" PRId64 "&dmcp.volume=%" PRId32 "", machine_number,
- vo);
+ snprintf(message, sizeof(message), "setproperty?speaker-id=%" PRId64 "&dmcp.volume=%" PRId32 "",
+ machine_number, vo);
debug(2, "sending \"%s\"", message);
return send_simple_dacp_command(message);
// should return 204