static void
delete_port_mapping_cb (GUPnPService *service,
    GUPnPServiceAction *action,
    gpointer user_data)
{
  guint requested_external_port = GPOINTER_TO_UINT (user_data);
  gchar *remote_host = NULL;
  guint external_port = 0;
  gchar *proto = NULL;

  gupnp_service_action_get (action,
      "NewRemoteHost", G_TYPE_STRING, &remote_host,
      "NewExternalPort", G_TYPE_UINT, &external_port,
      "NewProtocol", G_TYPE_STRING, &proto,
      NULL);

  g_assert (remote_host != NULL);
  if (requested_external_port || !return_conflict)
    g_assert (external_port == INTERNAL_PORT);
  else
    g_assert (external_port != INTERNAL_PORT);
  g_assert (proto && !strcmp (proto, "UDP"));

  gupnp_service_action_return (action);

  g_free (remote_host);
  g_free (proto);

  GSource* src = g_idle_source_new ();
  g_source_set_callback (src, loop_quit, NULL, NULL);
  g_source_attach (src, g_main_context_get_thread_default ());
}
예제 #2
0
파일: light-server.c 프로젝트: Ham22/gupnp
G_END_DECLS
/*
 * Action handlers
 */

/* SetTarget */
G_MODULE_EXPORT void
set_target_cb (GUPnPService          *service,
               GUPnPServiceAction    *action,
               G_GNUC_UNUSED gpointer user_data)
{
  gboolean target;

  /* Get the new target value */
  gupnp_service_action_get (action,
                            "NewTargetValue", G_TYPE_BOOLEAN, &target,
                            NULL);

  /* If the new target doesn't match the current status, change the status and
     emit a notification that the status has changed. */
  if (target != status) {
    status = target;
    gupnp_service_notify (service,
                          "Status", G_TYPE_BOOLEAN, status,
                          NULL);

    if (!quiet)
    {
      g_print ("The light is now %s.\n", status ? "on" : "off");
    }
  }

  /* Return success to the client */
  gupnp_service_action_return (action);
}
예제 #3
0
// Helper to check for valid instance ids
gboolean
check_instance_id (GUPnPServiceAction *action)
{
    guint instance_id;
    gupnp_service_action_get (action,
                              "InstanceID", G_TYPE_UINT, &instance_id, NULL);
    if (instance_id != 0) 
    {
        gupnp_service_action_return_error (action, 718, "Invalid InstanceID");
        return FALSE;
    }
    return TRUE;
}
static void
add_port_mapping_cb (GUPnPService *service,
    GUPnPServiceAction *action,
    gpointer user_data)
{
  guint requested_external_port = GPOINTER_TO_UINT (user_data);
  gchar *remote_host = NULL;
  guint external_port = 0;
  gchar *proto = NULL;
  guint internal_port = 0;
  gchar *internal_client = NULL;
  gboolean enabled = -1;
  gchar *desc = NULL;
  guint lease = 0;

  gupnp_service_action_get (action,
      "NewRemoteHost", G_TYPE_STRING, &remote_host,
      "NewExternalPort", G_TYPE_UINT, &external_port,
      "NewProtocol", G_TYPE_STRING, &proto,
      "NewInternalPort", G_TYPE_UINT, &internal_port,
      "NewInternalClient", G_TYPE_STRING, &internal_client,
      "NewEnabled", G_TYPE_BOOLEAN, &enabled,
      "NewPortMappingDescription", G_TYPE_STRING, &desc,
      "NewLeaseDuration", G_TYPE_UINT, &lease,
      NULL);

  g_assert (external_port);
  g_assert (remote_host && !strcmp (remote_host, ""));
  g_assert (proto && (!strcmp (proto, "UDP") || !strcmp (proto, "TCP")));
  g_assert (internal_port == INTERNAL_PORT);
  g_assert (internal_client && !strcmp (internal_client, "192.168.4.22"));
  g_assert (enabled == TRUE);
  g_assert (desc != NULL);
  g_assert (lease == 10);

  g_free (remote_host);
  g_free (proto);
  g_free (internal_client);
  g_free (desc);

  if (requested_external_port)
    g_assert (external_port == requested_external_port);


  if (return_conflict && external_port == INTERNAL_PORT)
    gupnp_service_action_return_error (action, 718, "ConflictInMappingEntry");
  else
    gupnp_service_action_return (action);
}
예제 #5
0
G_MODULE_EXPORT
void
on_set_target (GUPnPService       *service,
               GUPnPServiceAction *action,
               gpointer            user_data)
{
        gboolean status;

        gupnp_service_action_get (action,
                                  "newTargetValue",
                                  G_TYPE_BOOLEAN,
                                  &status,
                                  NULL);
        gupnp_service_action_return (action);

        set_status (status);
}
예제 #6
0
G_MODULE_EXPORT
void
on_set_load_level_target (GUPnPService       *service,
                          GUPnPServiceAction *action,
                          gpointer            user_data)
{
        guint load_level;

        gupnp_service_action_get (action,
                                  "newLoadlevelTarget",
                                  G_TYPE_UINT,
                                  &load_level,
                                  NULL);
        gupnp_service_action_return (action);

        if (load_level > 100)
                load_level = 100;

        set_load_level (load_level);
}
예제 #7
0
파일: rawudp-upnp.c 프로젝트: zsx/ossbuild
static void
delete_port_mapping_cb (GUPnPService *service,
    GUPnPServiceAction *action,
    gpointer user_data)
{
  gchar *remote_host = NULL;
  guint external_port = 0;
  gchar *proto = NULL;

  gupnp_service_action_get (action,
      "NewRemoteHost", G_TYPE_STRING, &remote_host,
      "NewExternalPort", G_TYPE_UINT, &external_port,
      "NewProtocol", G_TYPE_STRING, &proto,
      NULL);

  ts_fail_if (remote_host == NULL, "remote host NULL on remove");
  ts_fail_unless (external_port, "external port wrong on remove");
  ts_fail_unless (proto && !strcmp (proto, "UDP"), "proto wrong on remove");

  gupnp_service_action_return (action);
}
예제 #8
0
파일: rawudp-upnp.c 프로젝트: zsx/ossbuild
static void
add_port_mapping_cb (GUPnPService *service,
    GUPnPServiceAction *action,
    gpointer user_data)
{
  gchar *remote_host = NULL;
  guint external_port = 0;
  gchar *proto = NULL;
  guint internal_port = 0;
  gchar *internal_client = NULL;
  gboolean enabled = -1;
  gchar *desc = NULL;
  guint lease = 0;

  gupnp_service_action_get (action,
      "NewRemoteHost", G_TYPE_STRING, &remote_host,
      "NewExternalPort", G_TYPE_UINT, &external_port,
      "NewProtocol", G_TYPE_STRING, &proto,
      "NewInternalPort", G_TYPE_UINT, &internal_port,
      "NewInternalClient", G_TYPE_STRING, &internal_client,
      "NewEnabled", G_TYPE_BOOLEAN, &enabled,
      "NewPortMappingDescription", G_TYPE_STRING, &desc,
      "NewLeaseDuration", G_TYPE_UINT, &lease,
      NULL);

  ts_fail_unless (remote_host && !strcmp (remote_host, ""), "Remote host invalid");
  ts_fail_unless (external_port == internal_port, "External and internal ports different");
  ts_fail_unless (proto && (!strcmp (proto, "UDP") || !strcmp (proto, "TCP")));
  ts_fail_unless (enabled == TRUE, "enable is not true");
  ts_fail_unless (desc != NULL, "no desc");

  g_free (remote_host);
  g_free (proto);
  g_free (internal_client);
  g_free (desc);

  gupnp_service_action_return (action);
  added_mapping = TRUE;
}
G_MODULE_EXPORT void
getCurrentConnectionInfo(GUPnPService *service, GUPnPServiceAction *action, gpointer userData) {
	UpnpConnectionManagerServicePrivate *priv = UPNP_CONNECTION_MANAGER_SERVICE_GET_PRIVATE(UPNP_CONNECTION_MANAGER_SERVICE(userData));
	gchar *CurrentConnectionIDs;
	gint  RcsID = priv->rcsID;
	gint  AVTransportID = priv->avTransportID;
	gchar *ProtocolInfo = priv->protocolInfo;
	gchar *ConnectionManager = priv->connectionManager;
	gint  ConnectionID = priv->connectionID;
	gchar *Direction = priv->direction;
	gchar *Status = priv->connectionStatus;

	gupnp_service_action_get(action,
							 "ConnectionIDs", G_TYPE_STRING, &CurrentConnectionIDs,
							 NULL);
	gupnp_service_action_set(action,
							 "RcsID", G_TYPE_INT, RcsID,
							 NULL);
	gupnp_service_action_set(action,
							 "AVTransportID", G_TYPE_INT, AVTransportID,
							 NULL);
	gupnp_service_action_set(action,
							 "ProtocolInfo", G_TYPE_STRING, ProtocolInfo,
							 NULL);
	gupnp_service_action_set(action,
							 "ConnectionManager", G_TYPE_STRING, ConnectionManager,
							 NULL);
	gupnp_service_action_set(action,
							 "ConnectionID", G_TYPE_INT, ConnectionID,
							 NULL);
	gupnp_service_action_set(action,
							 "Direction", G_TYPE_STRING, Direction,
							 NULL);
	gupnp_service_action_set(action,
							 "Status", G_TYPE_STRING, Status,
							 NULL);
	gupnp_service_action_return(action);
}