Exemplo n.º 1
0
/* SYNTAX: SERVER LIST */
static void cmd_server_list(const char *data)
{
	GString *str;
	GSList *tmp;

	str = g_string_new(NULL);
	printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, IRCTXT_SETUPSERVER_HEADER);
	for (tmp = setupservers; tmp != NULL; tmp = tmp->next) {
		IRC_SERVER_SETUP_REC *rec = tmp->data;

		if (!IS_IRC_SERVER_SETUP(rec))
                        continue;

		g_string_truncate(str, 0);
		if (rec->password != NULL)
			g_string_append(str, "(pass), ");
		if (rec->autoconnect)
			g_string_append(str, "autoconnect, ");
		if (rec->max_cmds_at_once > 0)
			g_string_sprintfa(str, "cmdmax: %d, ", rec->max_cmds_at_once);
		if (rec->cmd_queue_speed > 0)
			g_string_sprintfa(str, "cmdspeed: %d, ", rec->cmd_queue_speed);
		if (rec->own_host != NULL)
			g_string_sprintfa(str, "host: %s, ", rec->own_host);

		if (str->len > 1) g_string_truncate(str, str->len-2);
		printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, IRCTXT_SETUPSERVER_LINE,
			    rec->address, rec->port,
			    rec->chatnet == NULL ? "" : rec->chatnet,
			    str->str);
	}
	printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, IRCTXT_SETUPSERVER_FOOTER);
	g_string_free(str, TRUE);
}
Exemplo n.º 2
0
static gchar *Exonerate_Server_get_hsps(Exonerate_Server *exonerate_server,
                                        Exonerate_Server_Connection *connection){
    register gint i, j, hsp_total = 0;
    register GPtrArray *index_hsp_set_list;
    register Index_HSPset *index_hsp_set;
    register gchar *reply;
    register GString *str;
    register HSP *hsp;
    g_assert(connection->hsp_param);
    g_assert(connection->query);
    if(connection->revcomp_target
    && (connection->hsp_param->match->type != Match_Type_PROTEIN2DNA))
        return g_strdup_printf(
                "error: revcomp target only available for protein2dna matches");
    if(connection->geneseed_threshold > 0){
        if(connection->geneseed_threshold < connection->hsp_param->threshold)
            return g_strdup_printf(
                    "error: geneseed threshold must be >= hsp threshold");
        index_hsp_set_list = Index_get_HSPsets_geneseed(exonerate_server->index,
                                               connection->hsp_param,
                                               connection->query,
                                               connection->revcomp_target,
                                               connection->geneseed_threshold,
                                               connection->geneseed_repeat,
                                               connection->max_query_span,
                                               connection->max_target_span);
    } else {
        index_hsp_set_list = Index_get_HSPsets(exonerate_server->index,
                                               connection->hsp_param,
                                               connection->query,
                                               connection->revcomp_target);
        }
    if(index_hsp_set_list){
        str = g_string_sized_new(1024);
        for(i = 0; i < index_hsp_set_list->len; i++){
            index_hsp_set = index_hsp_set_list->pdata[i];
            g_assert(index_hsp_set->hsp_set->is_finalised);
            g_string_sprintfa(str, "hspset: %d", index_hsp_set->target_id);
            /**/
            hsp_total += index_hsp_set->hsp_set->hsp_list->len;
            for(j = 0; j < index_hsp_set->hsp_set->hsp_list->len; j++){
                hsp = index_hsp_set->hsp_set->hsp_list->pdata[j];
                g_string_sprintfa(str, " %d %d %d",
                        hsp->query_start, hsp->target_start, hsp->length);
                }
            g_string_sprintfa(str, "\n");
            Index_HSPset_destroy(index_hsp_set);
            }
        if(exonerate_server->verbosity > 1)
            g_message("served [%d] HSPsets containing [%d] hsps",
                      index_hsp_set_list->len, hsp_total);
        g_ptr_array_free(index_hsp_set_list, TRUE);
        reply = str->str;
        g_assert(reply);
        g_string_free(str, FALSE);
    } else {
        reply = g_strdup_printf("hspset: empty\n");
        }
    return reply;
    }
Exemplo n.º 3
0
/* SYNTAX: CHANNEL LIST */
static void cmd_channel_list(void)
{
	GString *str;
	GSList *tmp;

	str = g_string_new(NULL);
	printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, IRCTXT_CHANSETUP_HEADER);
	for (tmp = setupchannels; tmp != NULL; tmp = tmp->next) {
		CHANNEL_SETUP_REC *rec = tmp->data;

		g_string_truncate(str, 0);
		if (rec->autojoin)
			g_string_append(str, "autojoin, ");
		if (rec->botmasks != NULL && *rec->botmasks != '\0')
			g_string_sprintfa(str, "bots: %s, ", rec->botmasks);
		if (rec->autosendcmd != NULL && *rec->autosendcmd != '\0')
			g_string_sprintfa(str, "botcmd: %s, ", rec->autosendcmd);

		if (str->len > 2) g_string_truncate(str, str->len-2);
		printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, IRCTXT_CHANSETUP_LINE,
			    rec->name, rec->chatnet == NULL ? "" : rec->chatnet,
			    rec->password == NULL ? "" : rec->password, str->str);
	}
	g_string_free(str, TRUE);
	printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, IRCTXT_CHANSETUP_FOOTER);
}
Exemplo n.º 4
0
static void statusbar_push_nick(GtkStatusbar *statusbar, Nick *nick)
{
	unsigned int id;
	GString *str;
	char *text;

	id = gtk_statusbar_get_context_id(statusbar, STATUSBAR_CONTEXT);

	str = g_string_new(NULL);
	g_string_sprintfa(str, "Nick: %s", nick->nick);

	if (nick->host != NULL)
		g_string_sprintfa(str, "  -  Host: %s", nick->host);
	if (nick->realname != NULL)
		g_string_sprintfa(str, "  -  Name: %s", nick->realname);

	/* this really should be done separately to all the nick->* values,
	   at least when we add i18n support to strings above.. */
	text = g_locale_to_utf8(str->str, -1, NULL, NULL, NULL);
	if (text == NULL) {
		text = g_convert(str->str, str->len, "UTF-8", "CP1252",
				 NULL, NULL, NULL);
	}

	gtk_statusbar_pop(statusbar, id);
	gtk_statusbar_push(statusbar, id, text != NULL ? text : str->str);

	g_free(text);
	g_string_free(str, TRUE);
}
Exemplo n.º 5
0
static void proxy_dump_data_005(gpointer key, gpointer value, gpointer context)
{
	if (*(char *)value != '\0')
		g_string_sprintfa(context, "%s=%s ", (char *)key, (char *)value);
	else
		g_string_sprintfa(context, "%s ", (char *)key);
}
Exemplo n.º 6
0
/* msgs ^notices : level=msgs, xlevel=notices */
static void ignore_split_levels(const char *levels, int *level, int *xlevel)
{
	GString *slevel, *sxlevel;
	char **levellist, **tmp;

	if (*levels == '\0') return;

        slevel = g_string_new(NULL);
        sxlevel = g_string_new(NULL);

	levellist = g_strsplit(levels, " ", -1);
	for (tmp = levellist; *tmp != NULL; tmp++) {
		if (**tmp == '^')
			g_string_sprintfa(sxlevel, "%s ", (*tmp)+1);
		else if (**tmp == '-' && (*tmp)[1] == '^')
			g_string_sprintfa(sxlevel, "-%s ", (*tmp)+2);
		else
			g_string_sprintfa(slevel, "%s ", *tmp);
	}
	g_strfreev(levellist);

	*level = combine_level(*level, slevel->str);
	*xlevel = combine_level(*xlevel, sxlevel->str);

	g_string_free(slevel, TRUE);
	g_string_free(sxlevel, TRUE);
}
Exemplo n.º 7
0
char *ban_get_masks(IRC_CHANNEL_REC *channel, const char *nicks)
{
	GString *str;
	char **ban, **banlist, *realban, *ret;

	str = g_string_new(NULL);
	banlist = g_strsplit(nicks, " ", -1);
	for (ban = banlist; *ban != NULL; ban++) {
		if (strchr(*ban, '!') != NULL) {
			/* explicit ban */
			g_string_sprintfa(str, "%s ", *ban);
			continue;
		}

		/* ban nick */
		realban = ban_get_mask(channel, *ban);
		if (realban != NULL) {
			g_string_sprintfa(str, "%s ", realban);
			g_free(realban);
		}
	}
	g_strfreev(banlist);

	if (str->len > 0)
		g_string_truncate(str, str->len-1);

	ret = str->str;
	g_string_free(str, FALSE);
        return ret;
}
Exemplo n.º 8
0
static void start_tag(GString *str, const char *entity, GHashTable *attr)
{
     g_string_sprintfa(str, "<%s", entity);
     if (attr) {
	  g_hash_table_foreach(attr, (GHFunc) append_single_attr, str);
     }
     g_string_sprintfa(str, ">");
}
Exemplo n.º 9
0
/**
 * Returns a text representation of this model.
 *
 * @param self the model.
 * @return a string.
 */
char *
to_string (struct naadsm_model_t_ *self)
{
  GString *s;
  gboolean already_names;
  unsigned int i;
  char *substring, *chararray;
  local_data_t *local_data;

  local_data = (local_data_t *) (self->model_data);
  s = g_string_new (NULL);
  g_string_append_printf (s, "<%s for ", MODEL_NAME);
  already_names = FALSE;
  for (i = 0; i < local_data->production_types->len; i++)
    if (local_data->production_type[i] == TRUE)
      {
        if (already_names)
          g_string_append_printf (s, ",%s",
                                  (char *) g_ptr_array_index (local_data->production_types, i));
        else
          {
            g_string_append_printf (s, "%s",
                                    (char *) g_ptr_array_index (local_data->production_types, i));
            already_names = TRUE;
          }
      }

  substring = PDF_dist_to_string (local_data->latent_period);
  g_string_sprintfa (s, "\n  latent-period=%s\n", substring);
  g_free (substring);

  substring = PDF_dist_to_string (local_data->infectious_subclinical_period);
  g_string_sprintfa (s, "  infectious-subclinical-period=%s\n", substring);
  g_free (substring);

  substring = PDF_dist_to_string (local_data->infectious_clinical_period);
  g_string_sprintfa (s, "  infectious-clinical-period=%s\n", substring);
  g_free (substring);

  substring = PDF_dist_to_string (local_data->immunity_period);
  g_string_sprintfa (s, "  immunity-period=%s", substring);
  g_free (substring);

  if (local_data->prevalence != NULL)
    {
      substring = REL_chart_to_string (local_data->prevalence);
      g_string_append_printf (s, "\n  prevalence=%s", substring);
      g_free (substring);
    }

  g_string_append_c (s, '>');

  /* don't return the wrapper object */
  chararray = s->str;
  g_string_free (s, FALSE);
  return chararray;
}
Exemplo n.º 10
0
static void
enter_dir (MsOle *ole)
{
	char *newpath, *ptr, *p;

	p = arg_data [arg_cur++];

	if (!p) {
		printf ("Takes a directory argument\n");
		return;
	}

	if (!g_strcasecmp (p, "..")) {
		guint lp;
		char **tmp;
		GString *newp = g_string_new ("");

		tmp = g_strsplit (cur_dir, "/", -1);
		lp  = 0;
		if (!tmp[lp])
			return;

		while (tmp[lp+1]) {
			g_string_sprintfa (newp, "%s/", tmp[lp]);
			lp++;
		}
		g_free (cur_dir);
		cur_dir = newp->str;
		g_string_free (newp, FALSE);
	} else {
		MsOleStat s;
		MsOleErr  result;

		ptr = get_regexp_name (p, cur_dir, ole);
		if (!ptr)
			return;

		newpath = g_strconcat (cur_dir, ptr, "/", NULL);

		result = ms_ole_stat (&s, ole, newpath, "");
		if (result == MS_OLE_ERR_EXIST) {
			printf ("Storage '%s' not found\n", ptr);
			g_free (newpath);
			return;
		}
		if (result != MS_OLE_ERR_OK) {
			g_warning ("internal error");
			g_free (newpath);
			return;
		}
		if (s.type == MsOleStreamT) {
			printf ("Trying to enter a stream. (%d)\n", s.type);
			g_free (newpath);
			return;
		}

		g_free (cur_dir);
		cur_dir = newpath;
	}
}
/**
 * Returns a text representation of this model.
 *
 * @param self the model.
 * @return a string.
 */
char *
to_string (struct naadsm_model_t_ *self)
{
  GString *s;
  gboolean already_names;
  unsigned int i;
  char *chararray;
  local_data_t *local_data;

  local_data = (local_data_t *) (self->model_data);
  s = g_string_new (NULL);
  g_string_sprintf (s, "<%s for ", MODEL_NAME);
  already_names = FALSE;
  for (i = 0; i < local_data->production_types->len; i++)
    if (local_data->production_type[i] == TRUE)
      {
        if (already_names)
          g_string_append_printf (s, ",%s",
                                  (char *) g_ptr_array_index (local_data->production_types, i));
        else
          {
            g_string_append_printf (s, "%s",
                                    (char *) g_ptr_array_index (local_data->production_types, i));
            already_names = TRUE;
          }
      }

  g_string_sprintfa (s, "\n  priority=%i>", local_data->priority);

  /* don't return the wrapper object */
  chararray = s->str;
  g_string_free (s, FALSE);
  return chararray;
}
Exemplo n.º 12
0
/* connected to server, autojoin to channels. */
static void event_connected(IRC_SERVER_REC *server)
{
	GString *chans;
	GSList *tmp;

	g_return_if_fail(server != NULL);

	if (server->connrec->reconnection)
		return;

	/* join to the channels marked with autojoin in setup */
	chans = g_string_new(NULL);
	for (tmp = setupchannels; tmp != NULL; tmp = tmp->next) {
		SETUP_CHANNEL_REC *rec = tmp->data;

		if (!rec->autojoin || !ircnet_match(rec->ircnet, server->connrec->ircnet))
			continue;

		g_string_sprintfa(chans, "%s,", rec->name);
	}

	if (chans->len > 0) {
		g_string_truncate(chans, chans->len-1);
		channels_join(server, chans->str, TRUE);
	}

	g_string_free(chans, TRUE);
}
Exemplo n.º 13
0
static char *get_nicks(IRC_CHANNEL_REC *channel,
		       const char *data, int op, int voice)
{
        GString *str;
	char **matches, **match, *ret;

	g_return_val_if_fail(channel != NULL, NULL);
	g_return_val_if_fail(data != NULL, NULL);
	if (*data == '\0') return NULL;

	str = g_string_new(NULL);
	matches = g_strsplit(data, " ", -1);
	for (match = matches; *match != NULL; match++) {
		if (strchr(*match, '*') == NULL &&
		    strchr(*match, '?') == NULL) {
			/* no wildcards */
                        g_string_sprintfa(str, "%s ", *match);
		} else {
                        get_wildcard_nicks(str, *match, channel, op, voice);
		}
	}

        if (str->len > 0) g_string_truncate(str, str->len-1);
	ret = str->str;
	g_string_free(str, FALSE);
	return ret;
}
Exemplo n.º 14
0
/* 
 * Returns the text to be displayed in a log message, if any.
 */
GString *GetLogString(GLogLevelFlags log_level, const gchar *message)
{
  GString *text;
  gchar TimeBuf[80];
  gint i;
  time_t tim;
  struct tm *timep;

  text = g_string_new("");
  if (Log.Timestamp) {
    tim = time(NULL);
    timep = localtime(&tim);
    strftime(TimeBuf, 80, Log.Timestamp, timep);
    TimeBuf[79] = '\0';
    g_string_append(text, TimeBuf);
  }

  for (i = 0; i < MAXLOG; i++)
    if (log_level & (1 << (G_LOG_LEVEL_USER_SHIFT + i))) {
      if (i > Log.Level) {
        g_string_free(text, TRUE);
        return NULL;
      }
      g_string_sprintfa(text, "%d: ", i);
    }
  g_string_append(text, message);
  return text;
}
Exemplo n.º 15
0
static char *reverse_controls(const char *str)
{
	GString *out;
        char *ret;

	out = g_string_new(NULL);

	while (*str != '\0') {
		if ((unsigned char) *str < 32 ||
		    (term_type == TERM_TYPE_8BIT &&
		     (unsigned char) (*str & 0x7f) < 32)) {
			/* control char */
			g_string_sprintfa(out, "%%8%c%%8",
					  'A'-1 + (*str & 0x7f));
		} else {
			g_string_append_c(out, *str);
		}

		str++;
	}

	ret = out->str;
        g_string_free(out, FALSE);
	return ret;
}
Exemplo n.º 16
0
static gchar *gui_window_line2text(LINE_REC *line)
{
    GString *str;
    gint color;
    gchar *ret, *ptr, *tmp;

    g_return_val_if_fail(line != NULL, NULL);

    str = g_string_new(NULL);

    color = 0;
    for (ptr = line->text; ; ptr++)
    {
	if (*ptr != 0)
	{
	    g_string_append_c(str, *ptr);
	    continue;
	}

	ptr++;
	if ((*ptr & 0x80) == 0)
	{
	    /* set color */
	    color = *ptr;
	    g_string_sprintfa(str, "\003%c%c", (color & 0x07)+1, ((color & 0xf0) >> 4)+1);
	    if (color & 0x08) g_string_sprintfa(str, "\002");
	}
	else switch ((guchar) *ptr)
Exemplo n.º 17
0
static void
result_append(GString *result, const gchar *sstr, gssize len, gboolean escape)
{
  gint i;
  const guchar *ustr = (const guchar *) sstr;
  
  if (len < 0)
    len = strlen(sstr);
  
  if (escape)
    {
      for (i = 0; i < len; i++)
        {
          if (ustr[i] == '\'' || ustr[i] == '"' || ustr[i] == '\\')
            {
              g_string_append_c(result, '\\');
              g_string_append_c(result, ustr[i]);
            }
          else if (ustr[i] < ' ')
            {
              g_string_sprintfa(result, "\\%03o", ustr[i]);
            }
          else
            g_string_append_c(result, ustr[i]);
        }
    }
  else
    g_string_append_len(result, sstr, len);
}
Exemplo n.º 18
0
void ban_remove(IRC_CHANNEL_REC *channel, const char *bans)
{
	GString *str;
	GSList *tmp;
	char **ban, **banlist;

	g_return_if_fail(bans != NULL);

	str = g_string_new(NULL);
	banlist = g_strsplit(bans, " ", -1);
	for (ban = banlist; *ban != NULL; ban++) {
		for (tmp = channel->banlist; tmp != NULL; tmp = tmp->next) {
			BAN_REC *rec = tmp->data;

			if (match_wildcards(*ban, rec->ban))
				g_string_sprintfa(str, "%s ", rec->ban);
		}
	}
	g_strfreev(banlist);

	if (str->len > 0)
		channel_set_singlemode(channel->server, channel->name,
				       str->str, "-b");
	g_string_free(str, TRUE);
}
Exemplo n.º 19
0
/* This is called automatically when a drag is initiated 
 * It build a URI list of the selected filenames to set as the drag data
 */
static void
clist_drag_data_get(GtkWidget            *widget,
                    GdkDragContext       *context,
                    GtkSelectionData     *data,
                    guint                info_arg,
                    guint                time,
                    FileView             *view)
{
  FileInfo *info;
  GList *base, *tmp;
  GString *uri_list = g_string_sized_new(PATH_MAX);

  disable_refresh();
  base = tmp = get_selection(view);
  
  for (; tmp != NULL; tmp = tmp->next)
  {
    info = tmp->data;
    g_string_sprintfa(uri_list, "file:%s/%s\r\n", view->dir, info->filename);
  }

  gtk_selection_data_set(data, data->target, 8, uri_list->str, uri_list->len);
  g_string_free(uri_list, TRUE);
  g_list_free(base);
  reenable_refresh();
}
Exemplo n.º 20
0
char *bits2level(int bits)
{
	GString *str;
	char *ret;
	int n;

	if (bits == 0)
		return g_strdup("");

	if (bits == MSGLEVEL_ALL)
		return g_strdup("ALL");

	str = g_string_new(NULL);
	if (bits & MSGLEVEL_NEVER)
		g_string_append(str, "NEVER ");

	for (n = 0; levels[n] != NULL; n++) {
		if (bits & (1L << n))
			g_string_sprintfa(str, "%s ", levels[n]);
	}
        if (str->len > 0)
		g_string_truncate(str, str->len-1);

	ret = str->str;
	g_string_free(str, FALSE);

	return ret;
}
Exemplo n.º 21
0
static void run_editor (MMConversation *mmconv)
{
	GError *spawn_error = NULL;
	GString *session_id;
	gchar * args[4];
	args[0] = (gchar *)purple_prefs_get_string("/plugins/gtk/musicmessaging/editor_path");
	
	args[1] = "-session_id";
	session_id = g_string_new("");
	g_string_sprintfa(session_id, "%d", mmconv_from_conv_loc(mmconv->conv));
	args[2] = session_id->str;
	
	args[3] = NULL;
	
	if (!(g_spawn_async (".", args, NULL, 4, NULL, NULL, &(mmconv->pid), &spawn_error)))
	{
		purple_notify_error(plugin_pointer, _("Error Running Editor"),
				  _("The following error has occurred:"), spawn_error->message);
		mmconv->started = FALSE;
	}
	else
	{
		mmconv->started = TRUE;
	}
}
Exemplo n.º 22
0
/* search for online people, print them and update offline list */
static void print_notify_onserver(IRC_SERVER_REC *server, GSList *nicks,
				  GSList **offline, const char *desc)
{
	GSList *tmp;
	GString *str;

	g_return_if_fail(server != NULL);
	g_return_if_fail(offline != NULL);
	g_return_if_fail(desc != NULL);

	str = g_string_new(NULL);
	for (tmp = nicks; tmp != NULL; tmp = tmp->next) {
		char *nick = tmp->data;

		if (!notifylist_ison_server(server, nick))
			continue;

		g_string_sprintfa(str, "%s, ", nick);
		*offline = g_slist_remove(*offline, nick);
	}

	if (str->len > 0) {
		g_string_truncate(str, str->len-2);
		printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_NOTIFY_ONLINE, desc, str->str);
	}

	g_string_free(str, TRUE);
}
Exemplo n.º 23
0
/* try to send as many nicks in one WHOIS as possible */
static void whois_list_send(IRC_SERVER_REC *server, GSList *nicks)
{
	GSList *tmp;
	GString *str;
	char *nick;
        int count;

	str = g_string_new(NULL);
	count = 0;

	for (tmp = nicks; tmp != NULL; tmp = tmp->next) {
		nick = tmp->data;

		count++;
		g_string_sprintfa(str, "%s,", nick);

		if (count >= server->max_whois_in_cmd) {
			g_string_truncate(str, str->len-1);
			whois_send(server, str->str, str->str);
                        count = 0;
		}
	}

	if (str->len > 0) {
		g_string_truncate(str, str->len-1);
		whois_send(server, str->str, str->str);
	}

	g_string_free(str, TRUE);
}
Exemplo n.º 24
0
static int get_wildcard_nicks(GString *output, const char *mask,
			      IRC_CHANNEL_REC *channel, int op, int voice)
{
	GSList *nicks, *tmp;
        int count;

	g_return_val_if_fail(output != NULL, 0);
	g_return_val_if_fail(mask != NULL, 0);
	g_return_val_if_fail(IS_IRC_CHANNEL(channel), 0);

        count = 0;
	nicks = nicklist_find_multiple(CHANNEL(channel), mask);
	for (tmp = nicks; tmp != NULL; tmp = tmp->next) {
		NICK_REC *rec = tmp->data;

		if ((op == 1 && !rec->op) || (op == 0 && rec->op) ||
		    (voice == 1 && !rec->voice) || (voice == 0 && rec->voice))
			continue;

		if (g_strcasecmp(rec->nick, channel->server->nick) == 0)
			continue;

		g_string_sprintfa(output, "%s ", rec->nick);
                count++;
	}
	g_slist_free(nicks);

        return count;
}
Exemplo n.º 25
0
static char *get_nicks(IRC_SERVER_REC *server, WI_ITEM_REC *item,
		       const char *data, int op, int voice,
		       IRC_CHANNEL_REC **ret_channel)
{
        IRC_CHANNEL_REC *channel;
        GString *str;
        GHashTable *optlist;
	char **matches, **match, *ret, *channame, *nicks;
	void *free_arg;
        int count, max_modes;

	if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST |
			    PARAM_FLAG_OPTIONS | PARAM_FLAG_OPTCHAN_NAME,
			    item, "op", &optlist, &channame, &nicks))
		return NULL;

	if (*nicks == '\0')
		return NULL;

	channel = irc_channel_find(server, channame);
	if (channel == NULL) {
		cmd_params_free(free_arg);
		return NULL;
	}

	str = g_string_new(NULL);
	matches = g_strsplit(nicks, " ", -1);
	for (match = matches; *match != NULL; match++) {
		if (strchr(*match, '*') == NULL &&
		    strchr(*match, '?') == NULL) {
			/* no wildcards */
                        g_string_sprintfa(str, "%s ", *match);
		} else {
			count = get_wildcard_nicks(str, *match, channel,
						   op, voice);
                        max_modes = settings_get_int("max_wildcard_modes");
			if (max_modes > 0 && count > max_modes &&
			    g_hash_table_lookup(optlist, "yes") == NULL) {
                                /* too many matches */
				g_string_free(str, TRUE);
				cmd_params_free(free_arg);

				signal_emit("error command", 1,
					    GINT_TO_POINTER(CMDERR_NOT_GOOD_IDEA));
				signal_stop();
                                return NULL;
			}
		}
	}

        if (str->len > 0) g_string_truncate(str, str->len-1);
	ret = str->str;
	g_string_free(str, FALSE);

	cmd_params_free(free_arg);

	*ret_channel = channel;
	return ret;
}
Exemplo n.º 26
0
static void
_concat_nvpairs_helper(const gchar *name, const gchar *value, gsize value_len, gpointer user_data)
{
  GString *concatenated = (GString *) user_data;

  g_string_sprintfa(concatenated, "%s=%s\n", name, value);
  assert_gint(value_len, strlen(value), "foreach() length mismatch");
}
Exemplo n.º 27
0
void channel_set_mode(IRC_SERVER_REC *server, const char *channel,
		      const char *mode)
{
	char *modestr, *curmode, *orig, type, prevtype;
	GString *tmode, *targs;
	int count;

	g_return_if_fail(IS_IRC_SERVER(server));
	g_return_if_fail(channel != NULL && mode != NULL);

	tmode = g_string_new(NULL);
	targs = g_string_new(NULL);
	count = 0;

	orig = modestr = g_strdup(mode);

        type = '+'; prevtype = '\0';
	curmode = cmd_get_param(&modestr);
	for (; *curmode != '\0'; curmode++) {
		if (*curmode == '+' || *curmode == '-') {
			type = *curmode;
			continue;
		}

		if (count == server->max_modes_in_cmd &&
		    HAS_MODE_ARG(type, *curmode)) {
			irc_send_cmdv(server, "MODE %s %s%s",
				      channel, tmode->str, targs->str);

			count = 0; prevtype = '\0';
			g_string_truncate(tmode, 0);
			g_string_truncate(targs, 0);
		}

		if (type != prevtype) {
			prevtype = type;
			g_string_append_c(tmode, type);
		}
		g_string_append_c(tmode, *curmode);

		if (HAS_MODE_ARG(type, *curmode)) {
			char *arg;

			count++;
			arg = cmd_get_param(&modestr);
			if (*arg != '\0') g_string_sprintfa(targs, " %s", arg);
		}
	}

	if (tmode->len > 0) {
		irc_send_cmdv(server, "MODE %s %s%s",
			      channel, tmode->str, targs->str);
	}

	g_string_free(tmode, TRUE);
	g_string_free(targs, TRUE);
	g_free(orig);
}
Exemplo n.º 28
0
static void server_rejoin_channels(IRC_SERVER_REC *server)
{
	GSList *tmp, *next;
	GString *channels, *keys;
	int use_keys;

	g_return_if_fail(IS_IRC_SERVER(server));

	channels = g_string_new(NULL);
	keys = g_string_new(NULL);

        use_keys = FALSE;
	for (tmp = server->rejoin_channels; tmp != NULL; tmp = next) {
		REJOIN_REC *rec = tmp->data;
		next = tmp->next;

		if (rec->joining) {
			/* we missed the join (failed) message,
			   remove from rejoins.. */
			rejoin_destroy(server, rec);
			continue;
		}

		rec->joining = TRUE;
		g_string_sprintfa(channels, "%s,", rec->channel);
		if (rec->key == NULL)
			g_string_append(keys, "x,");
		else {
			g_string_sprintfa(keys, "%s,", rec->key);
                        use_keys = TRUE;
		}
	}

	if (channels->len > 0) {
                g_string_truncate(channels, channels->len-1);
                g_string_truncate(keys, keys->len-1);

		if (use_keys) g_string_sprintfa(channels, " %s", keys->str);
		server->channels_join(SERVER(server), channels->str, TRUE);
	}

	g_string_free(channels, TRUE);
	g_string_free(keys, TRUE);
}
Exemplo n.º 29
0
static char *get_nicks(IRC_CHANNEL_REC *channel,
		       const char *data, int op, int voice)
{
        GString *str;
	GSList *nicks, *tmp;
	char **matches, **match, *ret;

	g_return_val_if_fail(channel != NULL, NULL);
	g_return_val_if_fail(data != NULL, NULL);
	if (*data == '\0') return NULL;

	str = g_string_new(NULL);
	matches = g_strsplit(data, " ", -1);
	for (match = matches; *match != NULL; match++) {
		if (strchr(*match, '*') == NULL && strchr(*match, '?') == NULL) {
			/* no wildcards */
                        g_string_sprintfa(str, "%s ", *match);
			continue;
		}

		/* wildcards */
		nicks = nicklist_find_multiple(CHANNEL(channel), data);
		for (tmp = nicks; tmp != NULL; tmp = tmp->next) {
			NICK_REC *rec = tmp->data;

			if ((op == 1 && !rec->op) || (op == 0 && rec->op) ||
			    (voice == 1 && !rec->voice) || (voice == 0 && rec->voice))
				continue;

			if (g_strcasecmp(rec->nick, channel->server->nick) == 0)
				continue;

			g_string_sprintfa(str, "%s ", rec->nick);
		}
		g_slist_free(nicks);
	}

        if (str->len > 0) g_string_truncate(str, str->len-1);
	ret = str->str;
	g_string_free(str, FALSE);
	return ret;
}
Exemplo n.º 30
0
/* show the notify list, displaying who is on which net */
static void cmd_notify_show(void)
{
	GSList *nicks, *offline, *tmp;
	IRC_SERVER_REC *server;

	if (notifies == NULL)
		return;

	/* build a list containing only the nicks */
	nicks = NULL;
	for (tmp = notifies; tmp != NULL; tmp = tmp->next) {
		NOTIFYLIST_REC *rec = tmp->data;

		nicks = mask_add_once(nicks, rec->mask);
	}
	offline = g_slist_copy(nicks);

        /* print the notifies on specific ircnets */
	for (tmp = ircnets; tmp != NULL; tmp = tmp->next) {
                IRCNET_REC *rec = tmp->data;

		server = (IRC_SERVER_REC *) server_find_ircnet(rec->name);
		if (server == NULL) continue;

		print_notify_onserver(server, nicks, &offline, rec->name);
	}

	/* print the notifies on servers without a specified ircnet */
	for (tmp = servers; tmp != NULL; tmp = tmp->next) {
		server = tmp->data;

		if (server->connrec->ircnet != NULL)
			continue;
		print_notify_onserver(server, nicks, &offline, server->tag);
	}

	/* print offline people */
	if (offline != NULL) {
		GString *str;

		str = g_string_new(NULL);
		for (tmp = offline; tmp != NULL; tmp = tmp->next)
			g_string_sprintfa(str, "%s, ", (char *) tmp->data);

		g_string_truncate(str, str->len-2);
		printformat(NULL,NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_NOTIFY_OFFLINE, str->str);
		g_string_free(str, TRUE);

		g_slist_free(offline);
	}

	g_slist_foreach(nicks, (GFunc) g_free, NULL);
	g_slist_free(nicks);
}