mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-30 09:03:23 -05:00
Use struct pairing_info in struct remote_info
This commit is contained in:
parent
d384bc13a3
commit
dfa3db7732
@ -55,12 +55,12 @@
|
|||||||
#include "conffile.h"
|
#include "conffile.h"
|
||||||
#include "mdns_avahi.h"
|
#include "mdns_avahi.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
#include "db.h"
|
||||||
#include "remote_pairing.h"
|
#include "remote_pairing.h"
|
||||||
|
|
||||||
|
|
||||||
struct remote_info {
|
struct remote_info {
|
||||||
char *id;
|
struct pairing_info pi;
|
||||||
char *name;
|
|
||||||
|
|
||||||
char *paircode;
|
char *paircode;
|
||||||
char *pin;
|
char *pin;
|
||||||
@ -326,12 +326,6 @@ unlink_remote(struct remote_info *ri)
|
|||||||
static void
|
static void
|
||||||
free_remote(struct remote_info *ri)
|
free_remote(struct remote_info *ri)
|
||||||
{
|
{
|
||||||
if (ri->id)
|
|
||||||
free(ri->id);
|
|
||||||
|
|
||||||
if (ri->name)
|
|
||||||
free(ri->name);
|
|
||||||
|
|
||||||
if (ri->paircode)
|
if (ri->paircode)
|
||||||
free(ri->paircode);
|
free(ri->paircode);
|
||||||
|
|
||||||
@ -341,6 +335,8 @@ free_remote(struct remote_info *ri)
|
|||||||
if (ri->address)
|
if (ri->address)
|
||||||
free(ri->address);
|
free(ri->address);
|
||||||
|
|
||||||
|
free_pi(&ri->pi, 1);
|
||||||
|
|
||||||
free(ri);
|
free(ri);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -359,10 +355,10 @@ remove_remote_byid(const char *id)
|
|||||||
|
|
||||||
for (ri = remote_list; ri; ri = ri->next)
|
for (ri = remote_list; ri; ri = ri->next)
|
||||||
{
|
{
|
||||||
if (!ri->id)
|
if (!ri->pi.remote_id)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (strcmp(ri->id, id) == 0)
|
if (strcmp(ri->pi.remote_id, id) == 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -383,7 +379,10 @@ add_remote_mdns_data(const char *id, const char *address, int port, char *name,
|
|||||||
|
|
||||||
for (ri = remote_list; ri; ri = ri->next)
|
for (ri = remote_list; ri; ri = ri->next)
|
||||||
{
|
{
|
||||||
if ((ri->id) && (strcmp(ri->id, id) == 0))
|
if (!ri->pi.remote_id)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (strcmp(ri->pi.remote_id, id) == 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -401,25 +400,21 @@ add_remote_mdns_data(const char *id, const char *address, int port, char *name,
|
|||||||
{
|
{
|
||||||
DPRINTF(E_DBG, L_REMOTE, "Remote id %s found\n", id);
|
DPRINTF(E_DBG, L_REMOTE, "Remote id %s found\n", id);
|
||||||
|
|
||||||
if (ri->id)
|
free_pi(&ri->pi, 1);
|
||||||
free(ri->id);
|
|
||||||
|
|
||||||
if (ri->address)
|
if (ri->address)
|
||||||
free(ri->address);
|
free(ri->address);
|
||||||
|
|
||||||
if (ri->name)
|
|
||||||
free(ri->name);
|
|
||||||
|
|
||||||
if (ri->paircode)
|
if (ri->paircode)
|
||||||
free(ri->paircode);
|
free(ri->paircode);
|
||||||
|
|
||||||
ret = 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ri->id = strdup(id);
|
ri->pi.remote_id = strdup(id);
|
||||||
ri->address = strdup(address);
|
ri->address = strdup(address);
|
||||||
|
|
||||||
if (!ri->id || !ri->address)
|
if (!ri->pi.remote_id || !ri->address)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_REMOTE, "Out of memory for remote pairing data\n");
|
DPRINTF(E_LOG, L_REMOTE, "Out of memory for remote pairing data\n");
|
||||||
|
|
||||||
@ -427,8 +422,8 @@ add_remote_mdns_data(const char *id, const char *address, int port, char *name,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ri->pi.name = name;
|
||||||
ri->port = port;
|
ri->port = port;
|
||||||
ri->name = name;
|
|
||||||
ri->paircode = paircode;
|
ri->paircode = paircode;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -441,7 +436,7 @@ add_remote_pin_data(char *devname, char *pin)
|
|||||||
|
|
||||||
for (ri = remote_list; ri; ri = ri->next)
|
for (ri = remote_list; ri; ri = ri->next)
|
||||||
{
|
{
|
||||||
if (strcmp(ri->name, devname) == 0)
|
if (strcmp(ri->pi.name, devname) == 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -454,13 +449,9 @@ add_remote_pin_data(char *devname, char *pin)
|
|||||||
|
|
||||||
DPRINTF(E_DBG, L_REMOTE, "Remote '%s' found\n", devname);
|
DPRINTF(E_DBG, L_REMOTE, "Remote '%s' found\n", devname);
|
||||||
|
|
||||||
if (ri->name)
|
|
||||||
free(ri->name);
|
|
||||||
|
|
||||||
if (ri->pin)
|
if (ri->pin)
|
||||||
free(ri->pin);
|
free(ri->pin);
|
||||||
|
|
||||||
ri->name = devname;
|
|
||||||
ri->pin = pin;
|
ri->pin = pin;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -564,12 +555,9 @@ remote_pairing_read_pin(char *path)
|
|||||||
pthread_mutex_lock(&remote_lck);
|
pthread_mutex_lock(&remote_lck);
|
||||||
|
|
||||||
ret = add_remote_pin_data(devname, pin);
|
ret = add_remote_pin_data(devname, pin);
|
||||||
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
free(devname);
|
free(devname);
|
||||||
|
if (ret < 0)
|
||||||
free(pin);
|
free(pin);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
kickoff_pairing();
|
kickoff_pairing();
|
||||||
|
|
||||||
@ -695,12 +683,12 @@ pairing_request_cb(struct evhttp_request *req, void *arg)
|
|||||||
|
|
||||||
if (req->response_code != HTTP_OK)
|
if (req->response_code != HTTP_OK)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_REMOTE, "Pairing failed with Remote %s/%s, HTTP response code %d\n", ri->id, ri->name, req->response_code);
|
DPRINTF(E_LOG, L_REMOTE, "Pairing failed with Remote %s/%s, HTTP response code %d\n", ri->pi.remote_id, ri->pi.name, req->response_code);
|
||||||
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
DPRINTF(E_INFO, L_REMOTE, "Pairing succeeded with Remote '%s' (id %s)\n", ri->name, ri->id);
|
DPRINTF(E_INFO, L_REMOTE, "Pairing succeeded with Remote '%s' (id %s)\n", ri->pi.name, ri->pi.remote_id);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
evhttp_connection_free(ri->evcon);
|
evhttp_connection_free(ri->evcon);
|
||||||
@ -726,7 +714,7 @@ do_pairing(struct remote_info *ri)
|
|||||||
goto hash_fail;
|
goto hash_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
DPRINTF(E_DBG, L_REMOTE, "Pairing hash for %s/%s: %s\n", ri->id, ri->name, pairing_hash);
|
DPRINTF(E_DBG, L_REMOTE, "Pairing hash for %s/%s: %s\n", ri->pi.remote_id, ri->pi.name, pairing_hash);
|
||||||
|
|
||||||
/* Prepare request URI */
|
/* Prepare request URI */
|
||||||
/* The servicename variable is the mDNS service group name; currently it's
|
/* The servicename variable is the mDNS service group name; currently it's
|
||||||
|
Loading…
Reference in New Issue
Block a user