<commit_before>/*
 * protocol.c - source for RakiaProtocol
 * Copyright (C) 2007-2010 Collabora Ltd.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include "protocol.h"

#include <string.h>

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

#include <rakia/sofia-decls.h>
#include <rakia/handles.h>
#include <rakia/media-manager.h>
#include <rakia/text-manager.h>
#include <sofia-sip/su_glib.h>

#define DEBUG_FLAG TPSIP_DEBUG_CONNECTION
#include "rakia/debug.h"
#include "sip-connection.h"
#include "sip-connection-helpers.h"

#define PROTOCOL_NAME "sip"
#define ICON_NAME "im-" PROTOCOL_NAME
#define VCARD_FIELD_NAME "x-" PROTOCOL_NAME
#define ENGLISH_NAME "SIP"

G_DEFINE_TYPE (RakiaProtocol,
    rakia_protocol,
    TP_TYPE_BASE_PROTOCOL)

enum {
    PROP_SOFIA_ROOT = 1,
};

struct _RakiaProtocolPrivate
{
  su_root_t *sofia_root;
};

/* Used in the otherwise-unused offset field of the TpCMParamSpec. The first
 * one is nonzero to catch implicit zero-initialization. */
enum {
    PARAM_EASY = 1,
    PARAM_SET_SEPARATELY
};

static TpCMParamSpec rakia_params[] = {
    /* Account (a sip: URI)
     *
     * FIXME: validate account SIP URI properly, using appropriate RFCs */
    { "account", DBUS_TYPE_STRING_AS_STRING, G_TYPE_STRING,
      TP_CONN_MGR_PARAM_FLAG_REQUIRED | TP_CONN_MGR_PARAM_FLAG_REGISTER,
      NULL, PARAM_SET_SEPARATELY, tp_cm_param_filter_string_nonempty, NULL },

    /* Username to register with, if different than in the account URI */
    { "auth-user", DBUS_TYPE_STRING_AS_STRING, G_TYPE_STRING,
      0, NULL, PARAM_EASY },

    /* Password */
    { "password", DBUS_TYPE_STRING_AS_STRING, G_TYPE_STRING,
      TP_CONN_MGR_PARAM_FLAG_SECRET, NULL, PARAM_EASY },

    /* Display name for self */
    { "alias", DBUS_TYPE_STRING_AS_STRING, G_TYPE_STRING, 0, NULL, PARAM_EASY,
      /* setting a 0-length alias makes no sense */
      tp_cm_param_filter_string_nonempty, NULL },

    /* Registrar */
    { "registrar", DBUS_TYPE_STRING_AS_STRING, G_TYPE_STRING, 0, NULL,
      PARAM_EASY },

    /* Used to compose proxy URI */
    { "proxy-host", DBUS_TYPE_STRING_AS_STRING, G_TYPE_STRING, 0, NULL,
      PARAM_SET_SEPARATELY },
    { "port", DBUS_TYPE_UINT16_AS_STRING, G_TYPE_UINT,
      TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT, GUINT_TO_POINTER(SIP_DEFAULT_PORT),
      PARAM_SET_SEPARATELY, tp_cm_param_filter_uint_nonzero },
    { "transport", DBUS_TYPE_STRING_AS_STRING, G_TYPE_STRING,
      TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT, "auto", PARAM_SET_SEPARATELY },

    /* Enables loose routing as per RFC 3261 */
    { "loose-routing", DBUS_TYPE_BOOLEAN_AS_STRING, G_TYPE_BOOLEAN,
      TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT, GUINT_TO_POINTER(FALSE),
      PARAM_EASY },

    /* Used to enable proactive NAT traversal techniques */
    { "discover-binding", DBUS_TYPE_BOOLEAN_AS_STRING, G_TYPE_BOOLEAN,
      TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT, GUINT_TO_POINTER(TRUE),
      PARAM_EASY },

    /* Mechanism used for connection keepalive maintenance */
    { "keepalive-mechanism", DBUS_TYPE_STRING_AS_STRING, G_TYPE_STRING,
      TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT, "auto", PARAM_SET_SEPARATELY },

    /* Keep-alive interval */
    { "keepalive-interval", DBUS_TYPE_UINT32_AS_STRING, G_TYPE_UINT,
      TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT, GUINT_TO_POINTER(0), PARAM_EASY },

    /* Use SRV DNS lookup to discover STUN server
     * (defaults to true unless stun-server is set) */
    { "discover-stun", DBUS_TYPE_BOOLEAN_AS_STRING, G_TYPE_BOOLEAN,
      0, NULL, PARAM_SET_SEPARATELY },

    /* STUN server */
    { "stun-server", DBUS_TYPE_STRING_AS_STRING, G_TYPE_STRING, 0, NULL,
      PARAM_SET_SEPARATELY },

    /* STUN port */
    { "stun-port", DBUS_TYPE_UINT16_AS_STRING, G_TYPE_UINT,
      TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT,
      GUINT_TO_POINTER(TPSIP_DEFAULT_STUN_PORT), PARAM_EASY,
      tp_cm_param_filter_uint_nonzero },

    /* If the session content cannot be modified once initially set up */
    { "immutable-streams", DBUS_TYPE_BOOLEAN_AS_STRING, G_TYPE_BOOLEAN,
      TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT, GUINT_TO_POINTER(FALSE),
      PARAM_EASY },

    /* Local IP address to use, workaround purposes only */
    { "local-ip-address", DBUS_TYPE_STRING_AS_STRING, G_TYPE_STRING,
      0, NULL, PARAM_EASY },<commit_msg>Comment doc that STUN is used for media only<commit_after>/*
 * protocol.c - source for RakiaProtocol
 * Copyright (C) 2007-2010 Collabora Ltd.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include "protocol.h"

#include <string.h>

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

#include <rakia/sofia-decls.h>
#include <rakia/handles.h>
#include <rakia/media-manager.h>
#include <rakia/text-manager.h>
#include <sofia-sip/su_glib.h>

#define DEBUG_FLAG TPSIP_DEBUG_CONNECTION
#include "rakia/debug.h"
#include "sip-connection.h"
#include "sip-connection-helpers.h"

#define PROTOCOL_NAME "sip"
#define ICON_NAME "im-" PROTOCOL_NAME
#define VCARD_FIELD_NAME "x-" PROTOCOL_NAME
#define ENGLISH_NAME "SIP"

G_DEFINE_TYPE (RakiaProtocol,
    rakia_protocol,
    TP_TYPE_BASE_PROTOCOL)

enum {
    PROP_SOFIA_ROOT = 1,
};

struct _RakiaProtocolPrivate
{
  su_root_t *sofia_root;
};

/* Used in the otherwise-unused offset field of the TpCMParamSpec. The first
 * one is nonzero to catch implicit zero-initialization. */
enum {
    PARAM_EASY = 1,
    PARAM_SET_SEPARATELY
};

static TpCMParamSpec rakia_params[] = {
    /* Account (a sip: URI)
     *
     * FIXME: validate account SIP URI properly, using appropriate RFCs */
    { "account", DBUS_TYPE_STRING_AS_STRING, G_TYPE_STRING,
      TP_CONN_MGR_PARAM_FLAG_REQUIRED | TP_CONN_MGR_PARAM_FLAG_REGISTER,
      NULL, PARAM_SET_SEPARATELY, tp_cm_param_filter_string_nonempty, NULL },

    /* Username to register with, if different than in the account URI */
    { "auth-user", DBUS_TYPE_STRING_AS_STRING, G_TYPE_STRING,
      0, NULL, PARAM_EASY },

    /* Password */
    { "password", DBUS_TYPE_STRING_AS_STRING, G_TYPE_STRING,
      TP_CONN_MGR_PARAM_FLAG_SECRET, NULL, PARAM_EASY },

    /* Display name for self */
    { "alias", DBUS_TYPE_STRING_AS_STRING, G_TYPE_STRING, 0, NULL, PARAM_EASY,
      /* setting a 0-length alias makes no sense */
      tp_cm_param_filter_string_nonempty, NULL },

    /* Registrar */
    { "registrar", DBUS_TYPE_STRING_AS_STRING, G_TYPE_STRING, 0, NULL,
      PARAM_EASY },

    /* Used to compose proxy URI */
    { "proxy-host", DBUS_TYPE_STRING_AS_STRING, G_TYPE_STRING, 0, NULL,
      PARAM_SET_SEPARATELY },
    { "port", DBUS_TYPE_UINT16_AS_STRING, G_TYPE_UINT,
      TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT, GUINT_TO_POINTER(SIP_DEFAULT_PORT),
      PARAM_SET_SEPARATELY, tp_cm_param_filter_uint_nonzero },
    { "transport", DBUS_TYPE_STRING_AS_STRING, G_TYPE_STRING,
      TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT, "auto", PARAM_SET_SEPARATELY },

    /* Enables loose routing as per RFC 3261 */
    { "loose-routing", DBUS_TYPE_BOOLEAN_AS_STRING, G_TYPE_BOOLEAN,
      TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT, GUINT_TO_POINTER(FALSE),
      PARAM_EASY },

    /* Used to enable proactive NAT traversal techniques */
    { "discover-binding", DBUS_TYPE_BOOLEAN_AS_STRING, G_TYPE_BOOLEAN,
      TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT, GUINT_TO_POINTER(TRUE),
      PARAM_EASY },

    /* Mechanism used for connection keepalive maintenance */
    { "keepalive-mechanism", DBUS_TYPE_STRING_AS_STRING, G_TYPE_STRING,
      TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT, "auto", PARAM_SET_SEPARATELY },

    /* Keep-alive interval */
    { "keepalive-interval", DBUS_TYPE_UINT32_AS_STRING, G_TYPE_UINT,
      TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT, GUINT_TO_POINTER(0), PARAM_EASY },

    /* Use SRV DNS lookup to discover STUN server for media NAT traversal
     * (defaults to true unless stun-server is set) */
    { "discover-stun", DBUS_TYPE_BOOLEAN_AS_STRING, G_TYPE_BOOLEAN,
      0, NULL, PARAM_SET_SEPARATELY },

    /* STUN server for media NAT traversal */
    { "stun-server", DBUS_TYPE_STRING_AS_STRING, G_TYPE_STRING, 0, NULL,
      PARAM_SET_SEPARATELY },

    /* STUN port */
    { "stun-port", DBUS_TYPE_UINT16_AS_STRING, G_TYPE_UINT,
      TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT,
      GUINT_TO_POINTER(TPSIP_DEFAULT_STUN_PORT), PARAM_EASY,
      tp_cm_param_filter_uint_nonzero },

    /* If the session content cannot be modified once initially set up */
    { "immutable-streams", DBUS_TYPE_BOOLEAN_AS_STRING, G_TYPE_BOOLEAN,
      TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT, GUINT_TO_POINTER(FALSE),
      PARAM_EASY },

    /* Local IP address to use, workaround purposes only */
    { "local-ip-address", DBUS_TYPE_STRING_AS_STRING, G_TYPE_STRING,
      0, NULL, PARAM_EASY },
{'fraction_non_alphanumeric': 0.08946380961785326, 'fraction_numerical': 0.008294657845363878, 'mean_word_length': 4.133299543841865, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '6133649', 'n_tokens_mistral': 3780, 'n_tokens_neox': 3623, 'n_words': 850}