コード例 #1
0
ファイル: urlregex.c プロジェクト: Like-all/mcabber
/* Initialization */
static void urlregex_init(void)
{
  if (settings_opt_get("url_regex")) {
#ifdef HAVE_GLIB_REGEX
    url_regex = g_regex_new(settings_opt_get("url_regex"),
                            G_REGEX_OPTIMIZE, 0, NULL);
    /* Add handler
     * We are only interested in incoming message events
     */
    urlregex_hid = hk_add_handler(urlregex_hh, HOOK_POST_MESSAGE_IN,
                                  G_PRIORITY_DEFAULT_IDLE, NULL);
#else
    scr_log_print(LPRINT_LOGNORM, "ERROR: Your glib version is too old, "
                  "cannot use url_regex.");
#endif // HAVE_GLIB_REGEX
  }
}
コード例 #2
0
ファイル: fifo_internal.c プロジェクト: weiss/mcabber
// Returns 1 in case of success, -1 on error
int fifo_init(void)
{
  const char *path = settings_opt_get("fifo_name");
  static gboolean guard_installed = FALSE;
  if (!guard_installed)
    if (!(guard_installed = settings_set_guard("fifo_name", fifo_guard)))
      scr_LogPrint(LPRINT_DEBUG, "fifo: BUG: Cannot install option guard!");
  if (path)
    return fifo_init_internal(path);
  return 1;
}
コード例 #3
0
static void mucignore_init()
{
    const gchar* ignore = settings_opt_get("mucignore");
    if (ignore) {
        mucignore = g_regex_new(ignore,
            G_REGEX_OPTIMIZE|G_REGEX_ANCHORED, G_REGEX_MATCH_ANCHORED, NULL);
        mucignore_msg_in_hid = hk_add_handler(mucignore_handle_message,
            HOOK_PRE_MESSAGE_IN, G_PRIORITY_HIGH, NULL);
    } else {
        mucignore = NULL;
    }
}
コード例 #4
0
ファイル: filetransfer.c プロジェクト: alkino/mcabber-jingle
/**
 * @brief Check if a node description with xmlns of JFT is correct 
 *
 * @param cn the jinglecontent a node description
 * @param err contain an error of the domain JINGLE_CHECK_ERROR
 * @return a gconstpointer, which is a new allocated JingleFT
 */
static gconstpointer newfrommessage(JingleContent *cn, GError **err)
{
  JingleFT *ft = NULL;
  LmMessageNode *node;
  gint64 tmpsize;
  const gchar *datestr, *sizestr;

  node = lm_message_node_get_child(cn->description, "offer");
 
  if (!node) {
    g_set_error(err, JINGLE_CHECK_ERROR, JINGLE_CHECK_ERROR_MISSING,
                "the offer element is missing");
    return NULL;
  }

  node = lm_message_node_get_child(node, "file");
  if (!node) {
    g_set_error(err, JINGLE_CHECK_ERROR, JINGLE_CHECK_ERROR_MISSING,
                "the file element is missing");
    return NULL;
  }

  if (g_strcmp0(lm_message_node_get_attribute(node, "xmlns"), NS_SI_FT)) {
    g_set_error(err, JINGLE_CHECK_ERROR, JINGLE_CHECK_ERROR_MISSING,
                "the file transfer offer has an invalid/unsupported namespace");
    return NULL;
  }

  ft = g_new0(JingleFT, 1);
  datestr  = lm_message_node_get_attribute(node, "date");
  ft->hash = (gchar *) lm_message_node_get_attribute(node, "hash");
  ft->name = (gchar *) lm_message_node_get_attribute(node, "name");
  sizestr  = lm_message_node_get_attribute(node, "size");
  ft->transmit = 0;
  ft->dir = JINGLE_FT_INCOMING;
  
  if (!ft->name || !sizestr) {
    g_set_error(err, JINGLE_CHECK_ERROR, JINGLE_CHECK_ERROR_MISSING,
                "an attribute of the file element is missing");
    g_free(ft);
    return NULL;
  }

  ft->date = from_iso8601(datestr, 1);
  tmpsize = g_ascii_strtoll(sizestr, NULL, 10);

  // the size attribute is a xs:integer an therefore can be negative.
  if (tmpsize < 0) {
    g_set_error(err, JINGLE_CHECK_ERROR, JINGLE_CHECK_ERROR_BADVALUE,
                "the offered file has a negative size");
    g_free(ft);
    return NULL;
  }
  ft->size = tmpsize;

  ft->name = g_path_get_basename(ft->name);
  
  if (settings_opt_get("jingle_ft_dir") != NULL)
    ft->name = g_build_filename(settings_opt_get("jingle_ft_dir"), ft->name, NULL);
  else
    ft->name = g_build_filename("/tmp", ft->name, NULL);

  if (!g_strcmp0(ft->name, ".")) {
    g_set_error(err, JINGLE_CHECK_ERROR, JINGLE_CHECK_ERROR_BADVALUE,
                "the offered file has an invalid filename");
    g_free(ft->name);
    g_free(ft);
    return NULL;
  }

  // check if the md5 hash is valid ([a-fA-F0-9){32})
  if (ft->hash != NULL && (strlen(ft->hash) != 32 || !_is_md5_hash(ft->hash))) {
    g_set_error(err, JINGLE_CHECK_ERROR, JINGLE_CHECK_ERROR_BADVALUE,
                "the offered file has an invalid hash");
    g_free(ft->name);
    g_free(ft);
    return NULL;
  }
  ft->hash = g_strndup(ft->hash, 32);

  {
    JingleFTInfo *jfti = g_new0(JingleFTInfo, 1);
    jfti->index = _next_index();
    jfti->jft = ft;
    info_list = g_slist_append(info_list, jfti);
  }

  return (gconstpointer) ft;
}
コード例 #5
0
ファイル: xmpp_iqrequest.c プロジェクト: weiss/mcabber
                                    LM_MESSAGE_SUB_TYPE_GET);
  for (i = 0; iq_request_handlers[i].xmlns &&
              strcmp(iq_request_handlers[i].xmlns, xmlns) != 0 ; ++i)
       ;
  query = lm_message_node_add_child(iq->node,
                                    iq_request_handlers[i].querytag,
                                    NULL);
  lm_message_node_set_attribute(query, "xmlns", xmlns);

  if (!g_strcmp0(xmlns, NS_PING)) {     // Create handler for ping queries
    struct timeval *now = g_new(struct timeval, 1);
    gettimeofday(now, NULL);
    data = (gpointer)now;
    notifier = g_free;
  } else if (!g_strcmp0(xmlns, NS_DISCO_INFO)) {
    gchar *servername = get_servername(settings_opt_get("jid"),
                                       settings_opt_get("server"));
    lm_message_node_set_attribute(iq->node, "to", servername);
    g_free(servername);
  }

  handler = lm_message_handler_new(iq_request_handlers[i].handler,
                                   data, notifier);

  lm_connection_send_with_reply(lconnection, iq, handler, &error);
  lm_message_handler_unref(handler);
  lm_message_unref(iq);

  if (error) {
    scr_LogPrint(LPRINT_LOGNORM, "Error sending IQ request: %s.", error->message);
    g_error_free(error);