0
0
mirror of https://gitlab.xiph.org/xiph/icecast-server.git synced 2025-06-30 22:18:19 -04:00

style changes

svn path=/trunk/icecast/; revision=4316
This commit is contained in:
oddsock 2003-02-02 16:48:15 +00:00
parent 2848150fb3
commit 0fba6babb1
5 changed files with 448 additions and 475 deletions

View File

@ -17,162 +17,159 @@
#include <curl/easy.h> #include <curl/easy.h>
#define CATMODULE "CURL" #define CATMODULE "geturl"
static CurlConnection curlConnections[NUM_CONNECTIONS]; static curl_connection curl_connections[NUM_CONNECTIONS];
static int nunConnections = NUM_CONNECTIONS;
mutex_t _curl_mutex; mutex_t _curl_mutex;
size_t size_t
WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) curl_write_memory_callback(void *ptr, size_t size, size_t nmemb, void *data)
{ {
register int realsize = size * nmemb; register int realsize = size * nmemb;
struct MemoryStruct *mem = (struct MemoryStruct *)data; struct curl_memory_struct *mem = (struct curl_memory_struct *)data;
if ((realsize + mem->size) < YP_RESPONSE_SIZE-1) { if ((realsize + mem->size) < YP_RESPONSE_SIZE-1) {
strncat(mem->memory, ptr, realsize); strncat(mem->memory, ptr, realsize);
} }
return realsize; return realsize;
} }
size_t size_t
HeaderMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) curl_header_memory_callback(void *ptr, size_t size, size_t nmemb, void *data)
{ {
char *p1 = 0; char *p1 = 0;
char *p2 = 0; char *p2 = 0;
int copylen = 0; int copylen = 0;
register int realsize = size * nmemb; register int realsize = size * nmemb;
struct MemoryStruct2 *mem = (struct MemoryStruct2 *)data; struct curl_memory_struct2 *mem = (struct curl_memory_struct2 *)data;
if (!strncmp(ptr, "SID: ", strlen("SID: "))) { if (!strncmp(ptr, "SID: ", strlen("SID: "))) {
p1 = (char *)ptr + strlen("SID: "); p1 = (char *)ptr + strlen("SID: ");
p2 = strchr((const char *)p1, '\r'); p2 = strchr((const char *)p1, '\r');
memset(mem->sid, '\000', sizeof(mem->sid)); memset(mem->sid, '\000', sizeof(mem->sid));
if (p2) { if (p2) {
if (p2-p1 > sizeof(mem->sid)-1) { if (p2-p1 > sizeof(mem->sid)-1) {
copylen = sizeof(mem->sid)-1; copylen = sizeof(mem->sid)-1;
} }
else { else {
copylen = p2-p1; copylen = p2-p1;
} }
strncpy(mem->sid, p1, copylen); strncpy(mem->sid, p1, copylen);
} }
else { else {
strncpy(mem->sid, p1, sizeof(mem->sid)-1); strncpy(mem->sid, p1, sizeof(mem->sid)-1);
strcpy(mem->sid, p1); strcpy(mem->sid, p1);
} }
} }
if (!strncmp(ptr, "YPMessage: ", strlen("YPMessage: "))) { if (!strncmp(ptr, "YPMessage: ", strlen("YPMessage: "))) {
p1 = (char *)ptr + strlen("YPMessage: "); p1 = (char *)ptr + strlen("YPMessage: ");
p2 = strchr((const char *)p1, '\r'); p2 = strchr((const char *)p1, '\r');
memset(mem->message, '\000', sizeof(mem->message)); memset(mem->message, '\000', sizeof(mem->message));
if (p2) { if (p2) {
if (p2-p1 > sizeof(mem->message)-1) { if (p2-p1 > sizeof(mem->message)-1) {
copylen = sizeof(mem->message)-1; copylen = sizeof(mem->message)-1;
} }
else { else {
copylen = p2-p1; copylen = p2-p1;
} }
strncpy(mem->message, p1, copylen); strncpy(mem->message, p1, copylen);
} }
else { else {
strncpy(mem->message, p1, sizeof(mem->message)-1); strncpy(mem->message, p1, sizeof(mem->message)-1);
strcpy(mem->message, p1); strcpy(mem->message, p1);
} }
} }
if (!strncmp(ptr, "TouchFreq: ", strlen("TouchFreq: "))) { if (!strncmp(ptr, "TouchFreq: ", strlen("TouchFreq: "))) {
p1 = (char *)ptr + strlen("TouchFreq: "); p1 = (char *)ptr + strlen("TouchFreq: ");
mem->touchFreq = atoi(p1); mem->touch_freq = atoi(p1);
} }
if (!strncmp(ptr, "YPResponse: ", strlen("YPResponse: "))) { if (!strncmp(ptr, "YPResponse: ", strlen("YPResponse: "))) {
p1 = (char *)ptr + strlen("YPResponse: "); p1 = (char *)ptr + strlen("YPResponse: ");
mem->response = atoi(p1); mem->response = atoi(p1);
} }
return realsize; return realsize;
} }
int curl_initialize() int curl_initialize()
{ {
int i = 0; int i = 0;
thread_mutex_create(&_curl_mutex); thread_mutex_create(&_curl_mutex);
memset(&curlConnections, '\000', sizeof(curlConnections));
for (i=0;i<NUM_CONNECTIONS;i++) {
curlConnections[i].curl_handle = curl_easy_init();
curl_easy_setopt(curlConnections[i].curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
curl_easy_setopt(curlConnections[i].curl_handle, CURLOPT_WRITEHEADER, (void *)&(curlConnections[i].headerresult));
curl_easy_setopt(curlConnections[i].curl_handle, CURLOPT_HEADERFUNCTION, HeaderMemoryCallback);
curl_easy_setopt(curlConnections[i].curl_handle, CURLOPT_FILE, (void *)&(curlConnections[i].result));
}
return(1);
memset(&curl_connections, '\000', sizeof(curl_connections));
for (i=0; i<NUM_CONNECTIONS; i++) {
curl_connections[i].curl_handle = curl_easy_init();
curl_easy_setopt(curl_connections[i].curl_handle,
CURLOPT_WRITEFUNCTION, curl_write_memory_callback);
curl_easy_setopt(curl_connections[i].curl_handle,
CURLOPT_WRITEHEADER, (void *)&(curl_connections[i].header_result));
curl_easy_setopt(curl_connections[i].curl_handle,
CURLOPT_HEADERFUNCTION, curl_header_memory_callback);
curl_easy_setopt(curl_connections[i].curl_handle,
CURLOPT_FILE, (void *)&(curl_connections[i].result));
}
return(1);
} }
void curl_shutdown() void curl_shutdown()
{ {
int i = 0; int i = 0;
for (i=0;i<NUM_CONNECTIONS;i++) { for (i=0; i<NUM_CONNECTIONS; i++) {
curl_easy_cleanup(curlConnections[i].curl_handle); curl_easy_cleanup(curl_connections[i].curl_handle);
memset(&(curlConnections[i]), '\000', sizeof(curlConnections[i])); memset(&(curl_connections[i]), '\000', sizeof(curl_connections[i]));
} }
} }
int curl_get_connection()
int getCurlConnection()
{ {
int found = 0; int found = 0;
int curlConnection = -1; int curl_connection = -1;
int i = 0; int i = 0;
while (!found) { while (!found) {
thread_mutex_lock(&_curl_mutex); thread_mutex_lock(&_curl_mutex);
for (i=0;i<NUM_CONNECTIONS;i++) { for (i=0; i<NUM_CONNECTIONS; i++) {
if (!curlConnections[i].inUse) { if (!curl_connections[i].in_use) {
found = 1; found = 1;
curlConnections[i].inUse = 1; curl_connections[i].in_use = 1;
curlConnection = i; curl_connection = i;
break; break;
} }
} }
thread_mutex_unlock(&_curl_mutex); thread_mutex_unlock(&_curl_mutex);
#ifdef WIN32 #ifdef WIN32
Sleep(200); Sleep(200);
#else #else
usleep(200); usleep(200);
#endif #endif
} }
return(curlConnection); return(curl_connection);
} }
int releaseCurlConnection(int which) int curl_release_connection(int which)
{ {
thread_mutex_lock(&_curl_mutex); thread_mutex_lock(&_curl_mutex);
curlConnections[which].inUse = 0; curl_connections[which].in_use = 0;
memset(&(curlConnections[which].result), '\000', sizeof(curlConnections[which].result)); memset(&(curl_connections[which].result), '\000',
memset(&(curlConnections[which].headerresult), '\000', sizeof(curlConnections[which].headerresult)); sizeof(curl_connections[which].result));
thread_mutex_unlock(&_curl_mutex); memset(&(curl_connections[which].header_result), '\000',
sizeof(curl_connections[which].header_result));
return 1; thread_mutex_unlock(&_curl_mutex);
return 1;
}
void curl_print_header_result(struct curl_memory_struct2 *mem) {
DEBUG1("SID -> (%s)", mem->sid);
DEBUG1("Message -> (%s)", mem->message);
DEBUG1("Touch Freq -> (%d)", mem->touch_freq);
DEBUG1("Response -> (%d)", mem->response);
} }
void printHeaderResult(struct MemoryStruct2 *mem) { CURL *curl_get_handle(int which)
DEBUG1("SID -> (%s)", mem->sid);
DEBUG1("Message -> (%s)", mem->message);
DEBUG1("Touch Freq -> (%d)", mem->touchFreq);
DEBUG1("Response -> (%d)", mem->response);
}
CURL *getCurlHandle(int which)
{ {
return curlConnections[which].curl_handle; return curl_connections[which].curl_handle;
} }
struct MemoryStruct *getCurlResult(int which) struct curl_memory_struct *curl_get_result(int which)
{ {
return &(curlConnections[which].result); return &(curl_connections[which].result);
} }
struct MemoryStruct2 *getCurlHeaderResult(int which) struct curl_memory_struct2 *curl_get_header_result(int which)
{ {
return &(curlConnections[which].headerresult); return &(curl_connections[which].header_result);
} }

View File

@ -13,33 +13,33 @@
#define YP_RESPONSE_SIZE 2046 #define YP_RESPONSE_SIZE 2046
#define YP_SID_SIZE 255 #define YP_SID_SIZE 255
struct MemoryStruct { struct curl_memory_struct {
char memory[YP_RESPONSE_SIZE]; char memory[YP_RESPONSE_SIZE];
size_t size; size_t size;
}; };
struct MemoryStruct2 { struct curl_memory_struct2 {
char sid[YP_SID_SIZE]; char sid[YP_SID_SIZE];
char message[YP_RESPONSE_SIZE]; char message[YP_RESPONSE_SIZE];
int touchFreq; int touch_freq;
int response; int response;
size_t size; size_t size;
}; };
typedef struct tag_CurlConnection { typedef struct tag_curl_connection {
struct MemoryStruct result; struct curl_memory_struct result;
struct MemoryStruct2 headerresult; struct curl_memory_struct2 header_result;
CURL *curl_handle; CURL *curl_handle;
int inUse; int in_use;
} CurlConnection; } curl_connection;
int curl_initialize(); int curl_initialize();
void curl_shutdown(); void curl_shutdown();
CURL *getCurlHandle(int which); CURL *curl_get_handle(int which);
struct MemoryStruct *getCurlResult(int which); struct curl_memory_struct *curl_get_result(int which);
struct MemoryStruct2 *getCurlHeaderResult(int which); struct curl_memory_struct2 *curl_get_header_result(int which);
void printHeaderResult(struct MemoryStruct2 *mem); void curl_print_header_result(struct curl_memory_struct2 *mem);
int getCurlConnection(); int curl_get_connection();
int releaseCurlConnection(int which); int curl_release_connection(int which);
#endif #endif

View File

@ -57,7 +57,7 @@ source_t *source_create(client_t *client, connection_t *con, http_parser_t *pars
src->listeners = 0; src->listeners = 0;
for (i=0;i<config_get_config()->num_yp_directories;i++) { for (i=0;i<config_get_config()->num_yp_directories;i++) {
if (config_get_config()->yp_url[i]) { if (config_get_config()->yp_url[i]) {
src->ypdata[src->num_yp_directories] = create_ypdata(); src->ypdata[src->num_yp_directories] = yp_create_ypdata();
src->ypdata[src->num_yp_directories]->yp_url = config_get_config()->yp_url[i]; src->ypdata[src->num_yp_directories]->yp_url = config_get_config()->yp_url[i];
src->ypdata[src->num_yp_directories]->yp_url_timeout = config_get_config()->yp_url_timeout[i]; src->ypdata[src->num_yp_directories]->yp_url_timeout = config_get_config()->yp_url_timeout[i];
src->ypdata[src->num_yp_directories]->yp_touch_freq = 0; src->ypdata[src->num_yp_directories]->yp_touch_freq = 0;
@ -117,9 +117,9 @@ int source_free_source(void *key)
avl_tree_free(source->pending_tree, _free_client); avl_tree_free(source->pending_tree, _free_client);
avl_tree_free(source->client_tree, _free_client); avl_tree_free(source->client_tree, _free_client);
source->format->free_plugin(source->format); source->format->free_plugin(source->format);
for (i=0;i<source->num_yp_directories;i++) { for (i=0; i<source->num_yp_directories; i++) {
destroy_ypdata(source->ypdata[i]); yp_destroy_ypdata(source->ypdata[i]);
} }
free(source); free(source);
return 1; return 1;

626
src/yp.c
View File

@ -12,364 +12,340 @@
#include "source.h" #include "source.h"
#include "config.h" #include "config.h"
#define CATMODULE "YP" #define CATMODULE "yp"
int yp_submit_url(int curlCon, char *yp_url, char *pURL, char *type) int yp_submit_url(int curl_con, char *yp_url, char *url, char *type)
{ {
int ret = 0; int ret = 0;
curl_easy_setopt(getCurlHandle(curlCon), CURLOPT_URL, yp_url); curl_easy_setopt(curl_get_handle(curl_con), CURLOPT_URL, yp_url);
curl_easy_setopt(getCurlHandle(curlCon), CURLOPT_POSTFIELDS, pURL); curl_easy_setopt(curl_get_handle(curl_con), CURLOPT_POSTFIELDS, url);
curl_easy_setopt(getCurlHandle(curlCon), CURLOPT_TIMEOUT, config_get_config()->yp_url_timeout); curl_easy_setopt(curl_get_handle(curl_con), CURLOPT_TIMEOUT, config_get_config()->yp_url_timeout);
/* get it! */ /* get it! */
memset(getCurlResult(curlCon), '\000', sizeof(struct MemoryStruct)); memset(curl_get_result(curl_con), '\000', sizeof(struct curl_memory_struct));
memset(getCurlHeaderResult(curlCon), '\000', sizeof(struct MemoryStruct2)); memset(curl_get_header_result(curl_con), '\000', sizeof(struct curl_memory_struct2));
curl_easy_perform(getCurlHandle(curlCon)); curl_easy_perform(curl_get_handle(curl_con));
printHeaderResult(getCurlHeaderResult(curlCon)); curl_print_header_result(curl_get_header_result(curl_con));
if (getCurlHeaderResult(curlCon)->response == ACK) { if (curl_get_header_result(curl_con)->response == ACK) {
INFO2("Successfull ACK from %s (%s)", type, yp_url); INFO2("Successfull ACK from %s (%s)", type, yp_url);
ret = 1; ret = 1;
} }
else { else {
if (strlen(getCurlHeaderResult(curlCon)->message) > 0) { if (strlen(curl_get_header_result(curl_con)->message) > 0) {
ERROR3("Got a NAK from %s(%s) (%s)", type,getCurlHeaderResult(curlCon)->message, yp_url); ERROR3("Got a NAK from %s(%s) (%s)", type,curl_get_header_result(curl_con)->message, yp_url);
} }
else { else {
ERROR2("Got a NAK from %s(Unknown) (%s)", type, yp_url); ERROR2("Got a NAK from %s(Unknown) (%s)", type, yp_url);
} }
ret = 0; ret = 0;
} }
return ret; return ret;
} }
void *yp_touch_thread(void *arg) void *yp_touch_thread(void *arg)
{ {
yp_touch((source_t *)arg); yp_touch((source_t *)arg);
thread_exit(0); thread_exit(0);
return NULL; return NULL;
} }
int yp_remove(void *psource) int yp_remove(void *psource)
{ {
char *pURL = NULL; char *url = NULL;
int pURLsize = 0; int url_size = 0;
int ret = 0; int ret = 0;
int curlCon = 0; int curl_con = 0;
char *p1 = NULL; char *p1 = NULL;
int i = 0; int i = 0;
int regenSID = 0; int regen_sid = 0;
long currentTime = 0; long current_time = 0;
source_t *source = (source_t *)psource; source_t *source = (source_t *)psource;
currentTime = time(&currentTime); current_time = time(&current_time);
for (i=0;i<source->num_yp_directories;i++) {
source->ypdata[i]->yp_last_touch = currentTime;
if (source->ypdata[i]->sid == 0) {
return 0;
}
else {
if (strlen(source->ypdata[i]->sid) == 0) {
return 0;
}
}
if (source->ypdata) { for (i=0; i<source->num_yp_directories; i++) {
pURLsize = strlen("action=remove&sid=") + 1; source->ypdata[i]->yp_last_touch = current_time;
pURLsize += strlen(source->ypdata[i]->sid); if (source->ypdata[i]->sid == 0) {
pURLsize += 1024; return 0;
}
pURL = (char *)malloc(pURLsize); else {
memset(pURL, '\000', pURLsize); if (strlen(source->ypdata[i]->sid) == 0) {
sprintf(pURL, "action=remove&sid=%s", return 0;
source->ypdata[i]->sid); }
}
curlCon = getCurlConnection(); if (source->ypdata) {
if (curlCon < 0) { url_size = strlen("action=remove&sid=") + 1;
ERROR0("Unable to get auth connection"); url_size += strlen(source->ypdata[i]->sid);
} url_size += 1024;
else { url = (char *)malloc(url_size);
memset(url, '\000', url_size);
/* specify URL to get */ sprintf(url, "action=remove&sid=%s",
ret = yp_submit_url(curlCon, source->ypdata[i]->yp_url, pURL, "yp_remove"); source->ypdata[i]->sid);
} curl_con = curl_get_connection();
if (curl_con < 0) {
if (pURL) { ERROR0("Unable to get auth connection");
free(pURL); }
} else {
/* specify URL to get */
releaseCurlConnection(curlCon); ret = yp_submit_url(curl_con, source->ypdata[i]->yp_url, url, "yp_remove");
} }
} if (url) {
free(url);
return 1; }
curl_release_connection(curl_con);
}
}
return 1;
} }
int yp_touch(void *psource) int yp_touch(void *psource)
{ {
char *pURL = NULL; char *url = NULL;
int pURLsize = 0; int url_size = 0;
int ret = 0; int ret = 0;
int curlCon = 0; int curl_con = 0;
char *p1 = NULL; char *p1 = NULL;
int i = 0; int i = 0;
int regen_sid = 0;
long current_time = 0;
source_t *source = (source_t *)psource;
int regenSID = 0; current_time = time(&current_time);
long currentTime = 0; for (i=0; i<source->num_yp_directories; i++) {
source_t *source = (source_t *)psource; source->ypdata[i]->yp_last_touch = current_time;
if (source->ypdata[i]->sid == 0) {
regen_sid = 1;
}
else {
if (strlen(source->ypdata[i]->sid) == 0) {
regen_sid = 1;
}
}
if (regen_sid) {
if (!yp_add(source, i)) {
return 0;
}
}
if (source->ypdata) {
url_size = strlen("action=touch&sid=&st=&listeners=") + 1;
if (source->ypdata[i]->current_song) {
url_size += strlen(source->ypdata[i]->current_song);
}
else {
source->ypdata[i]->current_song = (char *)malloc(1);
memset(source->ypdata[i]->current_song, '\000', 1);
}
if (source->ypdata[i]->sid) {
url_size += strlen(source->ypdata[i]->sid);
}
else {
source->ypdata[i]->sid = (char *)malloc(1);
memset(source->ypdata[i]->sid, '\000', 1);
}
url_size += 1024;
url = (char *)malloc(url_size);
memset(url, '\000', url_size);
sprintf(url, "action=touch&sid=%s&st=%s&listeners=%d",
source->ypdata[i]->sid,
source->ypdata[i]->current_song,
source->listeners);
currentTime = time(&currentTime); curl_con = curl_get_connection();
if (curl_con < 0) {
for (i=0;i<source->num_yp_directories;i++) { ERROR0("Unable to get auth connection");
}
source->ypdata[i]->yp_last_touch = currentTime; else {
/* specify URL to get */
if (source->ypdata[i]->sid == 0) { ret = yp_submit_url(curl_con, source->ypdata[i]->yp_url, url, "yp_touch");
regenSID = 1; }
} if (url) {
else { free(url);
if (strlen(source->ypdata[i]->sid) == 0) { }
regenSID = 1; curl_release_connection(curl_con);
} }
} }
return 1;
if (regenSID) {
if (!yp_add(source, i)) {
return 0;
}
}
if (source->ypdata) {
pURLsize = strlen("action=touch&sid=&st=&listeners=") + 1;
if (source->ypdata[i]->current_song) {
pURLsize += strlen(source->ypdata[i]->current_song);
}
else {
source->ypdata[i]->current_song = (char *)malloc(1);
memset(source->ypdata[i]->current_song, '\000', 1);
}
if (source->ypdata[i]->sid) {
pURLsize += strlen(source->ypdata[i]->sid);
}
else {
source->ypdata[i]->sid = (char *)malloc(1);
memset(source->ypdata[i]->sid, '\000', 1);
}
pURLsize += 1024;
pURL = (char *)malloc(pURLsize);
memset(pURL, '\000', pURLsize);
sprintf(pURL, "action=touch&sid=%s&st=%s&listeners=%d",
source->ypdata[i]->sid,
source->ypdata[i]->current_song,
source->listeners);
curlCon = getCurlConnection();
if (curlCon < 0) {
ERROR0("Unable to get auth connection");
}
else {
/* specify URL to get */
ret = yp_submit_url(curlCon, source->ypdata[i]->yp_url, pURL, "yp_touch");
}
if (pURL) {
free(pURL);
}
releaseCurlConnection(curlCon);
}
}
return 1;
} }
int yp_add(void *psource, int which) int yp_add(void *psource, int which)
{ {
char *pURL = NULL; char *url = NULL;
int pURLsize = 0; int url_size = 0;
int ret = 0; int ret = 0;
int curlCon = 0; int curl_con = 0;
char *p1 = NULL; char *p1 = NULL;
int i = 0; int i = 0;
int ok = 0;
source_t *source = (source_t *)psource;
int ok = 0; for (i=0; i<source->num_yp_directories; i++) {
source_t *source = (source_t *)psource; if (which != -1) {
if (i == which) {
for (i=0;i<source->num_yp_directories;i++) { ok = 1;
if (which != -1) { }
if (i == which) { else {
ok = 1; ok = 0;
} }
else { }
ok = 0; else {
} ok = 1;
} }
else {
ok = 1;
}
if (ok) { if (ok) {
if (source->ypdata[i]) { if (source->ypdata[i]) {
pURLsize = strlen("action=add&sn=&genre=&cpswd=&desc=&url=&listenurl=&type=&b=") + 1; url_size = strlen("action=add&sn=&genre=&cpswd=&desc=&url=&listenurl=&type=&b=") + 1;
if (source->ypdata[i]->server_name) { if (source->ypdata[i]->server_name) {
pURLsize += strlen(source->ypdata[i]->server_name); url_size += strlen(source->ypdata[i]->server_name);
} }
else { else {
source->ypdata[i]->server_name = (char *)malloc(1); source->ypdata[i]->server_name = (char *)malloc(1);
memset(source->ypdata[i]->server_name, '\000', 1); memset(source->ypdata[i]->server_name, '\000', 1);
} }
if (source->ypdata[i]->server_desc) { if (source->ypdata[i]->server_desc) {
pURLsize += strlen(source->ypdata[i]->server_desc); url_size += strlen(source->ypdata[i]->server_desc);
} }
else { else {
source->ypdata[i]->server_desc = (char *)malloc(1); source->ypdata[i]->server_desc = (char *)malloc(1);
memset(source->ypdata[i]->server_desc, '\000', 1); memset(source->ypdata[i]->server_desc, '\000', 1);
} }
if (source->ypdata[i]->server_genre) { if (source->ypdata[i]->server_genre) {
pURLsize += strlen(source->ypdata[i]->server_genre); url_size += strlen(source->ypdata[i]->server_genre);
} }
else { else {
source->ypdata[i]->server_genre = (char *)malloc(1); source->ypdata[i]->server_genre = (char *)malloc(1);
memset(source->ypdata[i]->server_genre, '\000', 1); memset(source->ypdata[i]->server_genre, '\000', 1);
} }
if (source->ypdata[i]->cluster_password) { if (source->ypdata[i]->cluster_password) {
pURLsize += strlen(source->ypdata[i]->cluster_password); url_size += strlen(source->ypdata[i]->cluster_password);
} }
else { else {
source->ypdata[i]->cluster_password = (char *)malloc(1); source->ypdata[i]->cluster_password = (char *)malloc(1);
memset(source->ypdata[i]->cluster_password, '\000', 1); memset(source->ypdata[i]->cluster_password, '\000', 1);
} }
if (source->ypdata[i]->server_url) { if (source->ypdata[i]->server_url) {
pURLsize += strlen(source->ypdata[i]->server_url); url_size += strlen(source->ypdata[i]->server_url);
} }
else { else {
source->ypdata[i]->server_url = (char *)malloc(1); source->ypdata[i]->server_url = (char *)malloc(1);
memset(source->ypdata[i]->server_url, '\000', 1); memset(source->ypdata[i]->server_url, '\000', 1);
} }
if (source->ypdata[i]->listen_url) { if (source->ypdata[i]->listen_url) {
pURLsize += strlen(source->ypdata[i]->listen_url); url_size += strlen(source->ypdata[i]->listen_url);
} }
else { else {
source->ypdata[i]->listen_url = (char *)malloc(1); source->ypdata[i]->listen_url = (char *)malloc(1);
memset(source->ypdata[i]->listen_url, '\000', 1); memset(source->ypdata[i]->listen_url, '\000', 1);
} }
if (source->ypdata[i]->server_type) { if (source->ypdata[i]->server_type) {
pURLsize += strlen(source->ypdata[i]->server_type); url_size += strlen(source->ypdata[i]->server_type);
} }
else { else {
source->ypdata[i]->server_type = (char *)malloc(1); source->ypdata[i]->server_type = (char *)malloc(1);
memset(source->ypdata[i]->server_type, '\000', 1); memset(source->ypdata[i]->server_type, '\000', 1);
} }
if (source->ypdata[i]->bitrate) { if (source->ypdata[i]->bitrate) {
pURLsize += strlen(source->ypdata[i]->bitrate); url_size += strlen(source->ypdata[i]->bitrate);
} }
else { else {
source->ypdata[i]->bitrate = (char *)malloc(1); source->ypdata[i]->bitrate = (char *)malloc(1);
memset(source->ypdata[i]->bitrate, '\000', 1); memset(source->ypdata[i]->bitrate, '\000', 1);
} }
if (source->ypdata[i]->current_song) { if (source->ypdata[i]->current_song) {
pURLsize += strlen(source->ypdata[i]->current_song); url_size += strlen(source->ypdata[i]->current_song);
} }
else { else {
source->ypdata[i]->current_song = (char *)malloc(1); source->ypdata[i]->current_song = (char *)malloc(1);
memset(source->ypdata[i]->current_song, '\000', 1); memset(source->ypdata[i]->current_song, '\000', 1);
} }
pURLsize += 1024; url_size += 1024;
pURL = (char *)malloc(pURLsize); url = (char *)malloc(url_size);
memset(pURL, '\000', pURLsize); memset(url, '\000', url_size);
sprintf(pURL, "action=add&sn=%s&genre=%s&cpswd=%s&desc=%s&url=%s&listenurl=%s&type=%s&b=%s", sprintf(url, "action=add&sn=%s&genre=%s&cpswd=%s&desc=%s&url=%s&listenurl=%s&type=%s&b=%s",
source->ypdata[i]->server_name, source->ypdata[i]->server_name,
source->ypdata[i]->server_genre, source->ypdata[i]->server_genre,
source->ypdata[i]->cluster_password, source->ypdata[i]->cluster_password,
source->ypdata[i]->server_desc, source->ypdata[i]->server_desc,
source->ypdata[i]->server_url, source->ypdata[i]->server_url,
source->ypdata[i]->listen_url, source->ypdata[i]->listen_url,
source->ypdata[i]->server_type, source->ypdata[i]->server_type,
source->ypdata[i]->bitrate); source->ypdata[i]->bitrate);
curlCon = getCurlConnection(); curl_con = curl_get_connection();
if (curlCon < 0) { if (curl_con < 0) {
ERROR0("Unable to get auth connection"); ERROR0("Unable to get auth connection");
} }
else { else {
/* specify URL to get */
ret = yp_submit_url(curl_con, source->ypdata[i]->yp_url, url, "yp_add");
/* specify URL to get */ if (ret) {
ret = yp_submit_url(curlCon, source->ypdata[i]->yp_url, pURL, "yp_add"); if (strlen(curl_get_header_result(curl_con)->sid) > 0) {
if (source->ypdata) {
if (ret) { if (source->ypdata[i]->sid) {
if (strlen(getCurlHeaderResult(curlCon)->sid) > 0) { free(source->ypdata[i]->sid);
if (source->ypdata) { source->ypdata[i]->sid = NULL;
if (source->ypdata[i]->sid) { }
free(source->ypdata[i]->sid); source->ypdata[i]->sid = (char *)malloc(strlen(curl_get_header_result(curl_con)->sid) +1);
source->ypdata[i]->sid = NULL; memset(source->ypdata[i]->sid, '\000', strlen(curl_get_header_result(curl_con)->sid) +1);
} strcpy(source->ypdata[i]->sid, curl_get_header_result(curl_con)->sid);
source->ypdata[i]->sid = (char *)malloc(strlen(getCurlHeaderResult(curlCon)->sid) +1); source->ypdata[i]->yp_touch_freq = curl_get_header_result(curl_con)->touch_freq;
memset(source->ypdata[i]->sid, '\000', strlen(getCurlHeaderResult(curlCon)->sid) +1); }
strcpy(source->ypdata[i]->sid, getCurlHeaderResult(curlCon)->sid); }
source->ypdata[i]->yp_touch_freq = getCurlHeaderResult(curlCon)->touchFreq; }
} }
} if (url) {
} free(url);
} }
curl_release_connection(curl_con);
if (pURL) { }
free(pURL); }
} }
return 1;
releaseCurlConnection(curlCon);
}
}
}
return 1;
} }
ypdata_t *create_ypdata() ypdata_t *yp_create_ypdata()
{ {
ypdata_t *tmp; ypdata_t *tmp;
tmp = (ypdata_t *)malloc(sizeof(ypdata_t));
memset(tmp, '\000', sizeof(ypdata_t));
return(tmp);
tmp = (ypdata_t *)malloc(sizeof(ypdata_t));
memset(tmp, '\000', sizeof(ypdata_t));
return(tmp);
} }
void destroy_ypdata(ypdata_t *ypdata) void yp_destroy_ypdata(ypdata_t *ypdata)
{ {
if (ypdata) { if (ypdata) {
if (ypdata->sid) { if (ypdata->sid) {
free(ypdata->sid); free(ypdata->sid);
} }
if (ypdata->server_name) { if (ypdata->server_name) {
free(ypdata->server_name); free(ypdata->server_name);
} }
if (ypdata->server_desc) { if (ypdata->server_desc) {
free(ypdata->server_desc); free(ypdata->server_desc);
} }
if (ypdata->server_genre) { if (ypdata->server_genre) {
free(ypdata->server_genre); free(ypdata->server_genre);
} }
if (ypdata->cluster_password) { if (ypdata->cluster_password) {
free(ypdata->cluster_password); free(ypdata->cluster_password);
} }
if (ypdata->server_url) { if (ypdata->server_url) {
free(ypdata->server_url); free(ypdata->server_url);
} }
if (ypdata->listen_url) { if (ypdata->listen_url) {
free(ypdata->listen_url); free(ypdata->listen_url);
} }
if (ypdata->current_song) { if (ypdata->current_song) {
free(ypdata->current_song); free(ypdata->current_song);
} }
if (ypdata->bitrate) { if (ypdata->bitrate) {
free(ypdata->bitrate); free(ypdata->bitrate);
} }
if (ypdata->server_type) { if (ypdata->server_type) {
free(ypdata->server_type); free(ypdata->server_type);
} }
free(ypdata); free(ypdata);
} }
} }

View File

@ -25,8 +25,8 @@ void *yp_touch_thread(void *arg);
int yp_add(void *psource, int which); int yp_add(void *psource, int which);
int yp_touch(void *psource); int yp_touch(void *psource);
int yp_remove(void *psource); int yp_remove(void *psource);
ypdata_t *create_ypdata(); ypdata_t *yp_create_ypdata();
void destroy_ypdata(ypdata_t *ypdata); void yp_destroy_ypdata(ypdata_t *ypdata);
#endif #endif