Exemple #1
0
/*
 * Send a discovery response
 */
static gboolean
discovery_response_timeout (gpointer user_data)
{
        DiscoveryResponse *response = user_data;
        GSSDPClient *client;
        SoupDate *date;
        char *al, *date_str, *message;
        guint max_age;
        char *usn;
        GSSDPResourceGroup *self = response->resource->resource_group;
        GSSDPResourceGroupPrivate *priv;

        priv = gssdp_resource_group_get_instance_private (self);

        /* Send message */
        client = priv->client;

        max_age = priv->max_age;

        al = construct_al (response->resource);
        usn = construct_usn (response->resource->usn,
                             response->target,
                             response->resource->target);
        date = soup_date_new_from_now (0);
        date_str = soup_date_to_string (date, SOUP_DATE_HTTP);
        soup_date_free (date);

        message = g_strdup_printf (SSDP_DISCOVERY_RESPONSE,
                                   (char *) response->resource->locations->data,
                                   al ? al : "",
                                   usn,
                                   gssdp_client_get_server_id (client),
                                   max_age,
                                   response->target,
                                   date_str);

        _gssdp_client_send_message (client,
                                    response->dest_ip,
                                    response->dest_port,
                                    message,
                                    _GSSDP_DISCOVERY_RESPONSE);

        g_free (message);
        g_free (date_str);
        g_free (al);
        g_free (usn);

        discovery_response_free (response);

        return FALSE;
}
Exemple #2
0
/*
 * Send ssdp:alive message for @resource
 */
static void
resource_alive (Resource *resource)
{
        GSSDPResourceGroupPrivate *priv;
        GSSDPClient *client;
        guint max_age;
        char *al, *message;
        const char *group;
        char *dest;

        priv = gssdp_resource_group_get_instance_private
                                        (resource->resource_group);

        /* Send initial byebye if not sent already */
        send_initial_resource_byebye (resource);

        /* Send message */
        client = priv->client;

        max_age = priv->max_age;

        al = construct_al (resource);

        /* FIXME: UGLY V6 stuff */
        group = _gssdp_client_get_mcast_group (client);
        if (strchr (group, ':') != NULL)
                dest = g_strdup_printf ("[%s]", group);
        else
                dest = g_strdup (group);

        message = g_strdup_printf (SSDP_ALIVE_MESSAGE,
                                   dest,
                                   max_age,
                                   (char *) resource->locations->data,
                                   al ? al : "",
                                   gssdp_client_get_server_id (client),
                                   resource->target,
                                   resource->usn);

        queue_message (resource->resource_group, message);

        g_free (dest);
        g_free (al);
}
/*
 * Send ssdp:alive message for @resource
 */
static void
resource_alive (Resource *resource)
{
	LOGD("resource_alive");
	LOGD("resource_alive");
	LOGD("resource_alive");

        GSSDPClient *client;
        guint max_age;
        char *al, *message;

        /* Send initial byebye if not sent already */
        send_initial_resource_byebye (resource);

	LOGD("send_initial_resource_byebye");
	LOGD("send_initial_resource_byebye");
	LOGD("send_initial_resource_byebye");

        /* Send message */
        client = resource->resource_group->priv->client;

        max_age = resource->resource_group->priv->max_age;

        al = construct_al (resource);

        message = g_strdup_printf (SSDP_ALIVE_MESSAGE,
                                   max_age,
                                   (char *) resource->locations->data,
                                   al ? al : "",
                                   gssdp_client_get_server_id (client),
                                   resource->target,
                                   resource->usn);

        queue_message (resource->resource_group, message);

        g_free (al);
}