[Redbutton-devel] SF.net SVN: redbutton: [172] redbutton-browser/trunk
Brought to you by:
skilvington
|
From: <ski...@us...> - 2007-01-11 11:10:34
|
Revision: 172
http://svn.sourceforge.net/redbutton/?rev=172&view=rev
Author: skilvington
Date: 2007-01-11 03:10:32 -0800 (Thu, 11 Jan 2007)
Log Message:
-----------
allow local backends to retune
Modified Paths:
--------------
redbutton-browser/trunk/MHEGBackend.c
redbutton-browser/trunk/utils.c
redbutton-browser/trunk/utils.h
Modified: redbutton-browser/trunk/MHEGBackend.c
===================================================================
--- redbutton-browser/trunk/MHEGBackend.c 2007-01-10 21:25:52 UTC (rev 171)
+++ redbutton-browser/trunk/MHEGBackend.c 2007-01-11 11:10:32 UTC (rev 172)
@@ -73,6 +73,7 @@
{
/* backend is on a different host, srg_loc is the remote host[:port] */
b->fns = &remote_backend_fns;
+ b->base_dir = NULL;
if(parse_addr(srg_loc, &b->addr.sin_addr, &b->addr.sin_port) < 0)
fatal("Unable to resolve host %s", srg_loc);
verbose("Remote backend at %s:%u", inet_ntoa(b->addr.sin_addr), ntohs(b->addr.sin_port));
@@ -81,7 +82,7 @@
{
/* backend and frontend on same host, srg_loc is the base directory */
b->fns = &local_backend_fns;
- b->base_dir = srg_loc;
+ b->base_dir = safe_strdup(srg_loc);
verbose("Local backend; carousel file root '%s'", srg_loc);
}
@@ -96,6 +97,8 @@
&& remote_command(b, true, "quit\n") != NULL)
fclose(b->be_sock);
+ safe_free(b->base_dir);
+
return;
}
@@ -358,9 +361,35 @@
void
local_retune(MHEGBackend *t, OctetString *service)
{
-/* TODO */
-fatal("TODO: Retune local backend to '%.*s' (service_id %u)", service->size, service->data, si_get_service_id(service));
+ unsigned int service_id;
+ char service_str[64];
+ char *slash;
+ int prefix_len;
+ /* extract the service_id */
+ service_id = si_get_service_id(service);
+ snprintf(service_str, sizeof(service_str), "%u", service_id);
+
+ /*
+ * base_dir is: [path/to/services/]<service_id>
+ * so we just need to replace the last filename component with the new service_id
+ */
+ slash = strrchr(t->base_dir, '/');
+ if(slash == NULL)
+ {
+ /* no preceeding path */
+ t->base_dir = safe_realloc(t->base_dir, strlen(service_str) + 1);
+ strcpy(t->base_dir, service_str);
+ }
+ else
+ {
+ prefix_len = (slash - t->base_dir) + 1;
+ t->base_dir = safe_realloc(t->base_dir, prefix_len + strlen(service_str) + 1);
+ strcpy(t->base_dir + prefix_len, service_str);
+ }
+
+ verbose("Retune: new service gateway is '%s'", t->base_dir);
+
return;
}
Modified: redbutton-browser/trunk/utils.c
===================================================================
--- redbutton-browser/trunk/utils.c 2007-01-10 21:25:52 UTC (rev 171)
+++ redbutton-browser/trunk/utils.c 2007-01-11 11:10:32 UTC (rev 172)
@@ -206,6 +206,24 @@
return;
}
+/*
+ * safe_strdup(NULL) == NULL
+ */
+
+char *
+safe_strdup(const char *src)
+{
+ char *dst;
+
+ if(src == NULL)
+ return NULL;
+
+ dst = (char *) safe_malloc(strlen(src) + 1);
+ strcpy(dst, src);
+
+ return dst;
+}
+
void
error(char *message, ...)
{
Modified: redbutton-browser/trunk/utils.h
===================================================================
--- redbutton-browser/trunk/utils.h 2007-01-10 21:25:52 UTC (rev 171)
+++ redbutton-browser/trunk/utils.h 2007-01-11 11:10:32 UTC (rev 172)
@@ -45,6 +45,8 @@
void *safe_realloc(void *, size_t);
void safe_free(void *);
+char *safe_strdup(const char *);
+
void error(char *, ...);
void fatal(char *, ...);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|