mirror of
https://github.com/morgan9e/UxPlay
synced 2026-04-14 00:04:13 +09:00
fix broken logger during early initialization stage
This commit is contained in:
@@ -410,10 +410,10 @@ httpd_start(httpd_t *httpd, unsigned short *port)
|
||||
return -1;
|
||||
}
|
||||
httpd->server_fd6 = netutils_init_socket(port, 1, 0);
|
||||
if (httpd->server_fd6 == -1) {
|
||||
logger_log(httpd->logger, LOGGER_WARNING, "Error initialising IPv6 socket %d", SOCKET_GET_ERROR());
|
||||
logger_log(httpd->logger, LOGGER_WARNING, "Continuing without IPv6 support");
|
||||
}
|
||||
if (httpd->server_fd6 == -1) {
|
||||
logger_log(httpd->logger, LOGGER_WARNING, "Error initialising IPv6 socket %d", SOCKET_GET_ERROR());
|
||||
logger_log(httpd->logger, LOGGER_WARNING, "Continuing without IPv6 support");
|
||||
}
|
||||
|
||||
if (httpd->server_fd4 != -1 && listen(httpd->server_fd4, backlog) == -1) {
|
||||
logger_log(httpd->logger, LOGGER_ERR, "Error listening to IPv4 socket");
|
||||
|
||||
96
lib/raop.c
96
lib/raop.c
@@ -342,15 +342,10 @@ conn_destroy(void *ptr) {
|
||||
}
|
||||
|
||||
raop_t *
|
||||
raop_init(int max_clients, raop_callbacks_t *callbacks, const char *device_id, const char *keyfile) {
|
||||
raop_init(raop_callbacks_t *callbacks) {
|
||||
raop_t *raop;
|
||||
pairing_t *pairing;
|
||||
httpd_t *httpd;
|
||||
httpd_callbacks_t httpd_cbs;
|
||||
|
||||
assert(callbacks);
|
||||
assert(max_clients > 0);
|
||||
assert(max_clients < 100);
|
||||
|
||||
/* Initialize the network */
|
||||
if (netutils_init() < 0) {
|
||||
@@ -372,46 +367,8 @@ raop_init(int max_clients, raop_callbacks_t *callbacks, const char *device_id, c
|
||||
/* Initialize the logger */
|
||||
raop->logger = logger_init();
|
||||
|
||||
/* create a new public key for pairing */
|
||||
int new_key;
|
||||
pairing = pairing_init_generate(device_id, keyfile, &new_key);
|
||||
if (!pairing) {
|
||||
free(raop);
|
||||
return NULL;
|
||||
}
|
||||
/* store PK as a string in raop->pk_str */
|
||||
memset(raop->pk_str, 0, sizeof(raop->pk_str));
|
||||
#ifdef PK
|
||||
strncpy(raop->pk_str, PK, 2*ED25519_KEY_SIZE);
|
||||
#else
|
||||
unsigned char public_key[ED25519_KEY_SIZE];
|
||||
pairing_get_public_key(pairing, public_key);
|
||||
char *pk_str = utils_pk_to_string(public_key, ED25519_KEY_SIZE);
|
||||
strncpy(raop->pk_str, (const char *) pk_str, 2*ED25519_KEY_SIZE);
|
||||
free(pk_str);
|
||||
#endif
|
||||
if (new_key) {
|
||||
printf("*** A new Public Key has been created and stored in %s\n", keyfile);
|
||||
}
|
||||
|
||||
/* Set HTTP callbacks to our handlers */
|
||||
memset(&httpd_cbs, 0, sizeof(httpd_cbs));
|
||||
httpd_cbs.opaque = raop;
|
||||
httpd_cbs.conn_init = &conn_init;
|
||||
httpd_cbs.conn_request = &conn_request;
|
||||
httpd_cbs.conn_destroy = &conn_destroy;
|
||||
|
||||
/* Initialize the http daemon */
|
||||
httpd = httpd_init(raop->logger, &httpd_cbs, max_clients);
|
||||
if (!httpd) {
|
||||
pairing_destroy(pairing);
|
||||
free(raop);
|
||||
return NULL;
|
||||
}
|
||||
/* Copy callbacks structure */
|
||||
memcpy(&raop->callbacks, callbacks, sizeof(raop_callbacks_t));
|
||||
raop->pairing = pairing;
|
||||
raop->httpd = httpd;
|
||||
|
||||
/* initialize network port list */
|
||||
raop->port = 0;
|
||||
@@ -440,6 +397,57 @@ raop_init(int max_clients, raop_callbacks_t *callbacks, const char *device_id, c
|
||||
return raop;
|
||||
}
|
||||
|
||||
int
|
||||
raop_init2(raop_t *raop, int max_clients, const char *device_id, const char *keyfile) {
|
||||
pairing_t *pairing;
|
||||
httpd_t *httpd;
|
||||
httpd_callbacks_t httpd_cbs;
|
||||
|
||||
assert(max_clients > 0);
|
||||
assert(max_clients < 100);
|
||||
|
||||
/* create a new public key for pairing */
|
||||
int new_key;
|
||||
pairing = pairing_init_generate(device_id, keyfile, &new_key);
|
||||
if (!pairing) {
|
||||
logger_log(raop->logger, LOGGER_ERR, "failed to create new public key for pairing");
|
||||
return -1;
|
||||
}
|
||||
/* store PK as a string in raop->pk_str */
|
||||
memset(raop->pk_str, 0, sizeof(raop->pk_str));
|
||||
#ifdef PK
|
||||
strncpy(raop->pk_str, PK, 2*ED25519_KEY_SIZE);
|
||||
#else
|
||||
unsigned char public_key[ED25519_KEY_SIZE];
|
||||
pairing_get_public_key(pairing, public_key);
|
||||
char *pk_str = utils_pk_to_string(public_key, ED25519_KEY_SIZE);
|
||||
strncpy(raop->pk_str, (const char *) pk_str, 2*ED25519_KEY_SIZE);
|
||||
free(pk_str);
|
||||
#endif
|
||||
if (new_key) {
|
||||
logger_log(raop->logger, LOGGER_INFO,"*** A new Public Key has been created and stored in %s", keyfile);
|
||||
}
|
||||
|
||||
/* Set HTTP callbacks to our handlers */
|
||||
memset(&httpd_cbs, 0, sizeof(httpd_cbs));
|
||||
httpd_cbs.opaque = raop;
|
||||
httpd_cbs.conn_init = &conn_init;
|
||||
httpd_cbs.conn_request = &conn_request;
|
||||
httpd_cbs.conn_destroy = &conn_destroy;
|
||||
|
||||
/* Initialize the http daemon */
|
||||
httpd = httpd_init(raop->logger, &httpd_cbs, max_clients);
|
||||
if (!httpd) {
|
||||
logger_log(raop->logger, LOGGER_ERR, "failed to initialize http daemon");
|
||||
pairing_destroy(pairing);
|
||||
return -1;
|
||||
}
|
||||
|
||||
raop->pairing = pairing;
|
||||
raop->httpd = httpd;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
raop_destroy(raop_t *raop) {
|
||||
if (raop) {
|
||||
|
||||
@@ -68,7 +68,8 @@ typedef struct raop_callbacks_s raop_callbacks_t;
|
||||
raop_ntp_t *raop_ntp_init(logger_t *logger, raop_callbacks_t *callbacks, const char *remote, int remote_addr_len,
|
||||
unsigned short timing_rport, timing_protocol_t *time_protocol);
|
||||
|
||||
RAOP_API raop_t *raop_init(int max_clients, raop_callbacks_t *callbacks, const char *device_id, const char *keyfile);
|
||||
RAOP_API raop_t *raop_init(raop_callbacks_t *callbacks);
|
||||
RAOP_API int raop_init2(raop_t *raop, int max_clients, const char *device_id, const char *keyfile);
|
||||
RAOP_API void raop_set_log_level(raop_t *raop, int level);
|
||||
RAOP_API void raop_set_log_callback(raop_t *raop, raop_log_callback_t callback, void *cls);
|
||||
RAOP_API int raop_set_plist(raop_t *raop, const char *plist_item, const int value);
|
||||
|
||||
Reference in New Issue
Block a user