<commit_before>/*
 * protocol.c - an example Protocol
 *
 * Copyright © 2007-2010 Collabora Ltd.
 *
 * Copying and distribution of this file, with or without modification,
 * are permitted in any medium without royalty provided the copyright
 * notice and this notice are preserved.
 */

#include "protocol.h"

#include <telepathy-glib/telepathy-glib.h>

#include "conn.h"
#include "im-manager.h"

#include <string.h>

G_DEFINE_TYPE (ExampleEcho2Protocol,
    example_echo_2_protocol,
    TP_TYPE_BASE_PROTOCOL)

const gchar * const protocol_interfaces[] = {
  TP_IFACE_PROTOCOL_INTERFACE_AVATARS,
  TP_IFACE_PROTOCOL_INTERFACE_PRESENCE,
  NULL };

const gchar * const supported_avatar_mime_types[] = {
  "image/png",
  "image/jpeg",
  "image/gif",
  NULL };

struct _ExampleEcho2ProtocolPrivate
{
  TpPresenceStatusSpec *statuses;
};

static TpPresenceStatusSpec
new_status_spec (const gchar *name,
                 TpConnectionPresenceType type,
                 gboolean settable,
                 gboolean can_have_message)
{
  TpPresenceStatusSpec ret;
  TpPresenceStatusOptionalArgumentSpec *args = g_new0 (TpPresenceStatusOptionalArgumentSpec, 2);

  memset (&ret, 0, sizeof (TpPresenceStatusSpec));
  ret.name = g_strdup (name);
  ret.presence_type = type;
  ret.self = settable;
  if (can_have_message)
    {
      args[0].name = g_strdup ("message");
    }
  ret.optional_arguments = args;

  return ret;
}

static void
example_echo_2_protocol_init (
    ExampleEcho2Protocol *self)
{
  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, EXAMPLE_TYPE_ECHO_2_PROTOCOL,
      ExampleEcho2ProtocolPrivate);

  self->priv->statuses = g_new0 (TpPresenceStatusSpec, 4);
  self->priv->statuses[0] = new_status_spec ("offline", TP_CONNECTION_PRESENCE_TYPE_OFFLINE,
      FALSE, FALSE);
  self->priv->statuses[1] = new_status_spec ("dnd", TP_CONNECTION_PRESENCE_TYPE_BUSY,
      TRUE, FALSE);
  self->priv->statuses[2] = new_status_spec ("available", TP_CONNECTION_PRESENCE_TYPE_AVAILABLE,
      TRUE, TRUE);
}

static void
example_echo_2_protocol_finalize (GObject *object)
{
  ExampleEcho2Protocol *self = EXAMPLE_ECHO_2_PROTOCOL (object);
  TpPresenceStatusSpec *status = self->priv->statuses;

  for (; status->name != NULL; status++) {
      TpPresenceStatusOptionalArgumentSpec *arg =
        (TpPresenceStatusOptionalArgumentSpec *) status->optional_arguments;

      for (; arg->name != NULL; arg++) {
          g_free ((gpointer) arg->name);
      }

      g_free ((gpointer) status->name);
      g_free ((gpointer) status->optional_arguments);
  }

  ((GObjectClass *) example_echo_2_protocol_parent_class)->finalize (object);
}

static const TpCMParamSpec example_echo_2_example_params[] = {
  { "account", "s", G_TYPE_STRING,
    TP_CONN_MGR_PARAM_FLAG_REQUIRED | TP_CONN_MGR_PARAM_FLAG_REGISTER,
    NULL, /* no default */
    0, /* formerly struct offset, now unused */
    tp_cm_param_filter_string_nonempty, /* filter - empty strings disallowed */
    NULL, /* filter data, unused for our filter */
    NULL /* setter data, now unused */ },
  { NULL }
};

static const TpCMParamSpec *
get_parameters (TpBaseProtocol *self)
{
  return example_echo_2_example_params;
}

static TpBaseConnection *
new_connection (TpBaseProtocol *protocol,<commit_msg>echo2 cm: Properly create TpPresenceStatusSpec with "canHaveMessage" set.<commit_after>/*
 * protocol.c - an example Protocol
 *
 * Copyright © 2007-2010 Collabora Ltd.
 *
 * Copying and distribution of this file, with or without modification,
 * are permitted in any medium without royalty provided the copyright
 * notice and this notice are preserved.
 */

#include "protocol.h"

#include <telepathy-glib/telepathy-glib.h>

#include "conn.h"
#include "im-manager.h"

#include <string.h>

G_DEFINE_TYPE (ExampleEcho2Protocol,
    example_echo_2_protocol,
    TP_TYPE_BASE_PROTOCOL)

const gchar * const protocol_interfaces[] = {
  TP_IFACE_PROTOCOL_INTERFACE_AVATARS,
  TP_IFACE_PROTOCOL_INTERFACE_PRESENCE,
  NULL };

const gchar * const supported_avatar_mime_types[] = {
  "image/png",
  "image/jpeg",
  "image/gif",
  NULL };

struct _ExampleEcho2ProtocolPrivate
{
  TpPresenceStatusSpec *statuses;
};

static TpPresenceStatusSpec
new_status_spec (const gchar *name,
                 TpConnectionPresenceType type,
                 gboolean settable,
                 gboolean can_have_message)
{
  TpPresenceStatusSpec ret;
  TpPresenceStatusOptionalArgumentSpec *args = g_new0 (TpPresenceStatusOptionalArgumentSpec, 2);

  memset (&ret, 0, sizeof (TpPresenceStatusSpec));
  ret.name = g_strdup (name);
  ret.presence_type = type;
  ret.self = settable;
  if (can_have_message)
    {
      args[0].name = g_strdup ("message");
      args[0].dtype = g_strdup ("s");
    }
  ret.optional_arguments = args;

  return ret;
}

static void
example_echo_2_protocol_init (
    ExampleEcho2Protocol *self)
{
  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, EXAMPLE_TYPE_ECHO_2_PROTOCOL,
      ExampleEcho2ProtocolPrivate);

  self->priv->statuses = g_new0 (TpPresenceStatusSpec, 4);
  self->priv->statuses[0] = new_status_spec ("offline", TP_CONNECTION_PRESENCE_TYPE_OFFLINE,
      FALSE, FALSE);
  self->priv->statuses[1] = new_status_spec ("dnd", TP_CONNECTION_PRESENCE_TYPE_BUSY,
      TRUE, FALSE);
  self->priv->statuses[2] = new_status_spec ("available", TP_CONNECTION_PRESENCE_TYPE_AVAILABLE,
      TRUE, TRUE);
}

static void
example_echo_2_protocol_finalize (GObject *object)
{
  ExampleEcho2Protocol *self = EXAMPLE_ECHO_2_PROTOCOL (object);
  TpPresenceStatusSpec *status = self->priv->statuses;

  for (; status->name != NULL; status++) {
      TpPresenceStatusOptionalArgumentSpec *arg =
        (TpPresenceStatusOptionalArgumentSpec *) status->optional_arguments;

      for (; arg->name != NULL; arg++) {
          g_free ((gpointer) arg->name);
          g_free ((gpointer) arg->dtype);
      }

      g_free ((gpointer) status->name);
      g_free ((gpointer) status->optional_arguments);
  }

  ((GObjectClass *) example_echo_2_protocol_parent_class)->finalize (object);
}

static const TpCMParamSpec example_echo_2_example_params[] = {
  { "account", "s", G_TYPE_STRING,
    TP_CONN_MGR_PARAM_FLAG_REQUIRED | TP_CONN_MGR_PARAM_FLAG_REGISTER,
    NULL, /* no default */
    0, /* formerly struct offset, now unused */
    tp_cm_param_filter_string_nonempty, /* filter - empty strings disallowed */
    NULL, /* filter data, unused for our filter */
    NULL /* setter data, now unused */ },
  { NULL }
};

static const TpCMParamSpec *
get_parameters (TpBaseProtocol *self)
{
  return example_echo_2_example_params;
}

static TpBaseConnection *
new_connection (TpBaseProtocol *protocol,
{'fraction_non_alphanumeric': 0.10507355148604022, 'fraction_numerical': 0.009606724707295107, 'mean_word_length': 4.271360759493671, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3374911', 'n_tokens_mistral': 2295, 'n_tokens_neox': 2200, 'n_words': 464}