コード例 #1
0
static gboolean
infinoted_plugin_document_stream_process_get_document(
  InfinotedPluginDocumentStreamStream* stream,
  const gchar** data,
  gsize* len)
{
  guint16 user_len;
  const gchar* user_name;
  guint16 doc_len;
  const gchar* doc_name;

  /* get size of user name string */
  if(*len < 2) return FALSE;
  user_len = *(guint16*)(*data);
  *data += 2; *len -= 2;

  /* get user name string */
  if(*len < user_len) return FALSE;
  user_name = *data;
  *data += user_len; *len -= user_len;

  /* get size of document string */
  if(*len < 2) return FALSE;
  doc_len = *(guint16*)(*data);
  *data += 2; *len -= 2;

  /* get document string */
  if(*len < doc_len) return FALSE;
  doc_name = *data;
  *data += doc_len; *len -= doc_len;

  /* quit connection if we already have a buffer */
  if(stream->buffer != NULL)
  {
    infinoted_plugin_document_stream_send_error(
      stream,
      "Stream is already open"
    );
  }
  else
  {
    stream->username = g_strndup(user_name, user_len);

    stream->navigate_handle = infinoted_plugin_util_navigate_to(
      INF_BROWSER(
        infinoted_plugin_manager_get_directory(stream->plugin->manager)
      ),
      doc_name,
      doc_len,
      FALSE,
      infinoted_plugin_document_stream_navigate_func,
      stream
    );
  }

  return TRUE;
}
コード例 #2
0
static void
infinoted_plugin_dbus_main_invocation(gpointer user_data)
{
  /* Main thread invocation handler */
  InfinotedPluginDbusInvocation* invocation;
  const gchar* path;
  gsize len;
  InfinotedPluginUtilNavigateData* navigate;

  invocation = (InfinotedPluginDbusInvocation*)user_data;
  invocation->plugin->invocations =
    g_slist_prepend(invocation->plugin->invocations, invocation);
  g_atomic_int_inc(&invocation->ref_count);

  /* These commands take a path as the first parameter and do not
   * require that path to be explored. */
  if(strcmp(invocation->method_name, "remove_node") == 0 ||
     strcmp(invocation->method_name, "query_acl") == 0 ||
     strcmp(invocation->method_name, "set_acl") == 0 ||
     strcmp(invocation->method_name, "check_acl") == 0)
  {
    path = g_variant_get_string(
      g_variant_get_child_value(invocation->parameters, 0),
      &len
    );

    navigate = infinoted_plugin_util_navigate_to(
      INF_BROWSER(infinoted_plugin_manager_get_directory(invocation->plugin->manager)),
      path,
      len,
      FALSE,
      infinoted_plugin_dbus_navigate_done,
      invocation
    );
    
    if(navigate != NULL)
      invocation->navigate = navigate;
  }
  /* These commands take a path as the first parameter and DO require that
   * path to be explored. */
  else if(strcmp(invocation->method_name, "explore_node") == 0 ||
          strcmp(invocation->method_name, "add_node") == 0)
  {
    path = g_variant_get_string(
      g_variant_get_child_value(invocation->parameters, 0),
      &len
    );

    navigate = infinoted_plugin_util_navigate_to(
      INF_BROWSER(infinoted_plugin_manager_get_directory(invocation->plugin->manager)),
      path,
      len,
      TRUE,
      infinoted_plugin_dbus_navigate_done,
      invocation
    );
    
    if(navigate != NULL)
      invocation->navigate = navigate;
  }
  else
  {
    g_dbus_method_invocation_return_error_literal(
      invocation->invocation,
      G_DBUS_ERROR,
      G_DBUS_ERROR_UNKNOWN_METHOD,
      "Not implemented"
    );

    infinoted_plugin_dbus_invocation_free(invocation->plugin, invocation);
  }
}