]> git.tue.mpg.de Git - paraslash.git/commitdiff
sender: add a hook to resolve target names
authorGerrit Renker <grenker@cscs.ch>
Sun, 13 Jun 2010 09:30:47 +0000 (11:30 +0200)
committerAndre Noll <maan@systemlinux.org>
Tue, 22 Jun 2010 23:16:43 +0000 (01:16 +0200)
This adds a function pointer to interpret and resolve a given URL string in
a target-specific manner, filling in the target's defaults if omitted.

The hook is used for the add/delete commands, currently implemented for UDP.

command.c
dccp_send.c
http_send.c
send.h
udp_send.c

index 42fa3e7584e7f622b7137730edcbfb5f07cbfd0f..bcbbc3406def48eba64adeb31eecd81997f634b2 100644 (file)
--- a/command.c
+++ b/command.c
@@ -191,10 +191,10 @@ static int check_sender_args(int argc, char * const * argv, struct sender_comman
 int com_sender(struct rc4_context *rc4c, int argc, char * const * argv)
 {
        int i, ret;
+       char *msg = NULL;
        struct sender_command_data scd;
 
        if (argc < 2) {
-               char *msg = NULL;
                for (i = 0; senders[i].name; i++) {
                        char *tmp = make_message("%s%s\n",
                                msg? msg : "", senders[i].name);
@@ -207,7 +207,6 @@ int com_sender(struct rc4_context *rc4c, int argc, char * const * argv)
        }
        ret = check_sender_args(argc, argv, &scd);
        if (ret < 0) {
-               char *msg;
                if (scd.sender_num < 0)
                        return ret;
                msg = senders[scd.sender_num].help();
@@ -215,6 +214,16 @@ int com_sender(struct rc4_context *rc4c, int argc, char * const * argv)
                free(msg);
                return ret;
        }
+
+       switch (scd.cmd_num) {
+       case SENDER_ADD:
+       case SENDER_DELETE:
+               assert(senders[scd.sender_num].resolve_target);
+               ret = senders[scd.sender_num].resolve_target(argv[3], &scd);
+               if (ret < 0)
+                       return ret;
+       }
+
        for (i = 0; i < 10; i++) {
                mutex_lock(mmd_mutex);
                if (mmd->sender_cmd_data.cmd_num >= 0) {
index 6cfdfbbeddccb42cd46a5d4b8c06aec24a0427ec..41aaf234da6ce89da2e25ce30871405f663cac38 100644 (file)
@@ -219,6 +219,7 @@ void dccp_send_init(struct sender *s)
        s->pre_select = dccp_pre_select;
        s->post_select = dccp_post_select;
        s->shutdown_clients = dccp_shutdown_clients;
+       s->resolve_target = NULL;
        s->help = generic_sender_help;
        s->client_cmds[SENDER_ON] = dccp_com_on;
        s->client_cmds[SENDER_OFF] = dccp_com_off;
index e8b22cf9958959b48d3d84855aeaf45cb1a5cf62..e376c4646cc92554dda73cd906d34f9d2f8e7155 100644 (file)
@@ -251,6 +251,7 @@ void http_send_init(struct sender *s)
        s->pre_select = http_pre_select;
        s->post_select = http_post_select;
        s->shutdown_clients = http_shutdown_clients;
+       s->resolve_target = NULL;
        s->help = generic_sender_help;
        s->client_cmds[SENDER_ON] = http_com_on;
        s->client_cmds[SENDER_OFF] = http_com_off;
diff --git a/send.h b/send.h
index df0cd1cb0612c1f3e52078e1d3478423566c8152..5f874521ce281e1801ab3d3682619bb872e33d13 100644 (file)
--- a/send.h
+++ b/send.h
@@ -87,6 +87,15 @@ struct sender {
         * pointer means this command is not implemented by this sender.
         */
        int (*client_cmds[NUM_SENDER_CMDS])(struct sender_command_data*);
+       /**
+        * Resolve target-specific URL string
+        *
+        * This method must be defined if the sender supports the add/delete
+        * subcommands. It interprets a string specifying a target URL in a
+        * sender-specific fashion (e.g. embedded FEC string). It can also
+        * fill in sender-specific defaults if necessary.
+        */
+       int (*resolve_target)(const char *, struct sender_command_data *);
 };
 
 /** Describes one client, connected to a paraslash sender. */
index 24ebf5848ed3c2de5d671de98dab142ce9018581..adac6a8db1e8e66bb2e68441c870390f59756324 100644 (file)
@@ -187,6 +187,28 @@ static void udp_shutdown_targets(void)
                }
 }
 
+static int udp_resolve_target(const char *url, struct sender_command_data *scd)
+{
+       const char *result;
+       int ret, port;
+
+       ret = parse_fec_url(url, scd);
+       if (ret)
+               return ret;
+       port = scd->port > 0 ? scd->port : conf.udp_default_port_arg;
+
+       ret = para_connect_simple(IPPROTO_UDP, scd->host, port);
+       if (ret < 0)
+               return ret;
+
+       result = remote_name(ret);
+       close(ret);
+
+       if (!parse_url(result, scd->host, sizeof(scd->host), &scd->port))
+               return -E_ADDRESS_LOOKUP;
+       return 1;
+}
+
 static int udp_com_on(__a_unused struct sender_command_data *scd)
 {
        sender_status = SENDER_ON;
@@ -427,6 +449,7 @@ void udp_send_init(struct sender *s)
        s->pre_select = NULL;
        s->post_select = NULL;
        s->shutdown_clients = udp_shutdown_targets;
+       s->resolve_target = udp_resolve_target;
        s->client_cmds[SENDER_ON] = udp_com_on;
        s->client_cmds[SENDER_OFF] = udp_com_off;
        s->client_cmds[SENDER_DENY] = NULL;