Index: apps/app_queue.c
===================================================================
--- apps/app_queue.c	(revision 302404)
+++ apps/app_queue.c	(working copy)
@@ -4524,6 +4524,58 @@
 	return res;
 }
 
+static int sync_to_queues(const char *queuenames, const char *interface, const char *membername, int penalty, int paused, int dump, const char *state_interface)
+{
+	int found, res = RES_OKAY, num_queues = 0, aux_count;
+	struct call_queue *q;
+	struct ao2_iterator queue_iter;
+	char **queue_name = NULL, *buf;
+
+	/* Make an array with the names of the queues we received */
+	if (!ast_strlen_zero(queuenames)) {
+		num_queues = 1;
+		aux_count = 1;
+		do {
+			if (queuenames[aux_count] == ',') num_queues++;
+		} while(queuenames[aux_count++] != '\0');
+
+		aux_count = 0;
+		queue_name = ast_calloc(num_queues, sizeof(char*));
+		buf = ast_strdupa(queuenames);
+		while ((queue_name[aux_count++] = strsep(&buf, ","))) {}
+	}
+
+	ao2_lock(queues);
+	queue_iter = ao2_iterator_init(queues, 0);
+	while ((q = ao2_t_iterator_next(&queue_iter, "Iterate over queues for memver Sync"))) {
+		found = 0;
+		if (num_queues > 0) {
+			for(aux_count=0; aux_count<num_queues; aux_count++) {
+				if(!strcmp(queue_name[aux_count], q->name)) {
+					found = 1;
+					break;
+				}
+			}
+		}
+
+		res = (found) ?
+				add_to_queue(q->name, interface, membername, penalty, paused, dump, state_interface) :
+				remove_from_queue(q->name, interface);
+
+		if(res == RES_OUTOFMEMORY) {
+			ast_log(LOG_WARNING, "Queue sync RES_OUTOFMEMORY when %s member %s from queue %s\n", (found ? "adding" : "removing"), membername, q->name);
+			break;
+		}
+	}
+	ao2_iterator_destroy(&queue_iter);
+	ao2_unlock(queues);
+
+	if (num_queues > 0)
+		ast_free(queue_name);
+
+	return (res == RES_OUTOFMEMORY) ? RES_OUTOFMEMORY : RES_OKAY;
+}
+
 static int set_member_paused(const char *queuename, const char *interface, const char *reason, int paused)
 {
 	int found = 0;
@@ -6554,6 +6606,46 @@
 	return 0;
 }
 
+static int manager_sync_queue_member(struct mansession *s, const struct message *m)
+{
+	const char *queuenames, *interface, *penalty_s, *paused_s, *membername, *state_interface;
+	int paused, penalty = 0;
+
+	queuenames = astman_get_header(m, "Queues");
+	interface = astman_get_header(m, "Interface");
+	penalty_s = astman_get_header(m, "Penalty");
+	paused_s = astman_get_header(m, "Paused");
+	membername = astman_get_header(m, "MemberName");
+	state_interface = astman_get_header(m, "StateInterface");
+
+	if (ast_strlen_zero(interface)) {
+		astman_send_error(s, m, "'Interface' not specified.");
+		return 0;
+	}
+
+	if (ast_strlen_zero(penalty_s))
+		penalty = 0;
+	else if (sscanf(penalty_s, "%30d", &penalty) != 1 || penalty < 0)
+		penalty = 0;
+
+	if (ast_strlen_zero(paused_s))
+		paused = 0;
+	else
+		paused = abs(ast_true(paused_s));
+
+	switch (sync_to_queues(queuenames, interface, membername, penalty, paused, queue_persistent_members, state_interface)) {
+	case RES_OKAY:
+		ast_queue_log(queuenames, "MANAGER", interface, "SYNCMEMBER", "%s", "");
+		astman_send_ack(s, m, "Interface synchronized to queues");
+		break;
+	case RES_OUTOFMEMORY:
+		astman_send_error(s, m, "Out of memory");
+		break;
+	}
+
+	return 0;
+}
+
 static int manager_pause_queue_member(struct mansession *s, const struct message *m)
 {
 	const char *queuename, *interface, *paused_s, *reason;
@@ -7187,6 +7279,7 @@
 	res |= ast_manager_unregister("QueueSummary");
 	res |= ast_manager_unregister("QueueAdd");
 	res |= ast_manager_unregister("QueueRemove");
+	res |= ast_manager_unregister("QueueSync");
 	res |= ast_manager_unregister("QueuePause");
 	res |= ast_manager_unregister("QueueLog");
 	res |= ast_manager_unregister("QueuePenalty");
@@ -7257,6 +7350,7 @@
 	res |= ast_manager_register("QueueSummary", 0, manager_queues_summary, "Queue Summary");
 	res |= ast_manager_register("QueueAdd", EVENT_FLAG_AGENT, manager_add_queue_member, "Add interface to queue.");
 	res |= ast_manager_register("QueueRemove", EVENT_FLAG_AGENT, manager_remove_queue_member, "Remove interface from queue.");
+	res |= ast_manager_register("QueueSync", EVENT_FLAG_AGENT, manager_sync_queue_member, "Synchronize interface to queues.");
 	res |= ast_manager_register("QueuePause", EVENT_FLAG_AGENT, manager_pause_queue_member, "Makes a queue member temporarily unavailable");
 	res |= ast_manager_register("QueueLog", EVENT_FLAG_AGENT, manager_queue_log_custom, "Adds custom entry in queue_log");
 	res |= ast_manager_register("QueuePenalty", EVENT_FLAG_AGENT, manager_queue_member_penalty, "Set the penalty for a queue member"); 
