Beispiel #1
0
/* SYNTAX: CTCP <targets> <ctcp command> [<ctcp data>] */
static void cmd_ctcp(const char *data, IRC_SERVER_REC *server,
		     WI_ITEM_REC *item)
{
	const char *target;
	char *ctcpcmd, *ctcpdata;
	void *free_arg;

        CMD_IRC_SERVER(server);

	if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_GETREST,
			    &target, &ctcpcmd, &ctcpdata))
		return;
	if (strcmp(target, "*") == 0)
		target = item == NULL ? NULL : window_item_get_target(item);
	if (*target == '\0' || *ctcpcmd == '\0')
		cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);

	g_strup(ctcpcmd);
	if (*ctcpdata == '\0')
		g_string_sprintf(tmpstr, "PRIVMSG %s :\001%s\001", target, ctcpcmd);
	else {
		char *recoded;

		recoded = recode_out(SERVER(server), ctcpdata, target);
		g_string_sprintf(tmpstr, "PRIVMSG %s :\001%s %s\001", target, ctcpcmd, recoded);
		g_free(recoded);
	}

	irc_send_cmd_split(server, tmpstr->str, 2, server->max_msgs_in_cmd);

	cmd_params_free(free_arg);
}
Beispiel #2
0
int botnet_send_file(BOTNET_REC *botnet, const char *target, const char *fname)
{
	GNode *node;
	GString *str;
	char buffer[1024];
	int f, len;

	node = bot_find_path(botnet, target);
	if (node == NULL) {
		g_warning("Can't find route for target %s", target);
		return FALSE;
	}

	f = open(fname, O_RDONLY);
	if (f == -1) return FALSE;

	str = g_string_new(NULL);

	g_string_sprintf(str, "%s %s FILE %s", botnet->nick, target, g_basename(fname));
	bot_send_cmd(node->data, str->str);

	while ((len = read(f, buffer, sizeof(buffer)/2-2)) > 0) {
		escape_buffer(buffer, len);

		g_string_sprintf(str, "%s %s FILE %s", botnet->nick, target, buffer);
		bot_send_cmd(node->data, str->str);
	}

	g_string_sprintf(str, "%s %s FILE", botnet->nick, target);
	bot_send_cmd(node->data, str->str);
	g_string_free(str, TRUE);

	close(f);
	return TRUE;
}
/**
 * aos_kernel_server_list:
 * @initial_server: to list for
 * @max_row_number: max rows to be listed 
 * @usr_function: function to be executed on server response.
 * @usr_data: user data to be passed to @user_function
 * 
 * List all installed servers at af-kernel.
 * 
 * Return value: 
 **/
gboolean           aos_kernel_server_list     (gint           initial_server, 
						 gint           max_row_number,
						 AfDalDataFunc  usr_function, 
						 gpointer       usr_data)
{
	gboolean result = FALSE;
	GString * init, * rows;
	RRConnection * connection = NULL;

	connection = afdal_session_get_connection ("af-kernel", NULL);
	if (! connection)
		return FALSE;
	
	init = g_string_new (NULL);
	rows = g_string_new (NULL);

	g_string_sprintf(init, "%d", initial_server);
	g_string_sprintf(rows, "%d", max_row_number);

	result = afdal_request (connection, 
				__aos_kernel_server_list_process, 
				(AfDalFunc) usr_function, usr_data,
				"server_list", 
				"initial", COYOTE_XML_ARG_STRING, init->str, 
				"row_number", COYOTE_XML_ARG_STRING, rows->str, 
				NULL);

	g_string_free (init, TRUE);
	g_string_free (rows, TRUE);
	
	return result;
};
/**
 * aos_kernel_user_list:
 * @initial_user: to list for
 * @max_row_number: max rows to be listed 
 * @usr_function: function to be executed on server response.
 * @usr_data: user data to be passed to @user_function
 * 
 * List all available user.
 * 
 * Return value: 
 **/
gboolean           aos_kernel_user_list     (gint           initial_user, 
					       gint           max_row_number,
					       OseaClientDataFunc  usr_function, 
					       gpointer       usr_data)
{
	gboolean result = FALSE;
	GString * init, * rows;
	RRConnection * connection = NULL;

	connection = oseaclient_session_get_connection ("os-kernel", NULL);
	if (! connection)
		return FALSE;
	
	init = g_string_new (NULL);
	rows = g_string_new (NULL);

	g_string_sprintf(init, "%d", initial_user);
	g_string_sprintf(rows, "%d", max_row_number);

	result = oseaclient_request (connection, 
				__aos_kernel_user_list_process, 
				(OseaClientFunc) usr_function, usr_data,
				"list_user", 
				"initial", OSEACOMM_XML_ARG_STRING, init->str, 
				"row_number", OSEACOMM_XML_ARG_STRING, rows->str, 
				NULL);

	g_string_free (init, TRUE);
	g_string_free (rows, TRUE);
	
	return result;
};
Beispiel #5
0
/* SYNTAX: WHOIS [<server>] [<nicks>] */
static void cmd_whois(const char *data, IRC_SERVER_REC *server,
		      WI_ITEM_REC *item)
{
	GHashTable *optlist;
	char *qserver, *query, *event_402, *str;
	void *free_arg;
	int free_nick;

        CMD_IRC_SERVER(server);

	if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTIONS,
			    "whois", &optlist, &qserver, &query))
		return;

	if (*query == '\0') {
		query = qserver;
		qserver = "";
	}
	if (*query == '\0') {
		QUERY_REC *queryitem = QUERY(item);
		if (queryitem == NULL)
			query = server->nick;
		else
			query = qserver = queryitem->name;
	}

	if (strcmp(query, "*") == 0 &&
	    g_hash_table_lookup(optlist, "yes") == NULL)
		cmd_param_error(CMDERR_NOT_GOOD_IDEA);

	event_402 = "event 402";
	if (*qserver == '\0')
		g_string_sprintf(tmpstr, "WHOIS %s", query);
	else {
		g_string_sprintf(tmpstr, "WHOIS %s %s", qserver, query);
		if (g_strcasecmp(qserver, query) == 0)
			event_402 = "whois event noserver";
	}

	/* do automatic /WHOWAS if any of the nicks wasn't found */
	query = get_redirect_nicklist(query, &free_nick);

        str = g_strconcat(qserver, " ", query, NULL);
	server_redirect_event(server, "whois", 1, str, TRUE,
                              NULL,
			      "event 318", "whois end",
			      "event 402", event_402,
			      "event 301", "whois away", /* 301 can come as a reply to /MSG, /WHOIS or /WHOWAS */
			      "event 401", "whois not found",
			      "event 311", "whois event", NULL);
        g_free(str);

	server->whois_found = FALSE;
	irc_send_cmd_split(server, tmpstr->str, 2, server->max_whois_in_cmd);

	if (free_nick) g_free(query);
	cmd_params_free(free_arg);
}
Beispiel #6
0
// save all stored preferences to file
void save_preferences (char *filepad) {
    gchar *data;
    gsize len;
	GString *label = g_string_new_len("", 20);
	int i;

    g_key_file_set_double (settings, "display", "opacity", 		conf.opacity);
    g_key_file_set_string (settings, "display", "font", 		conf.font);
    g_key_file_set_integer (settings, "display", "x", 			conf.x);
    g_key_file_set_integer (settings, "display", "y", 			conf.y);
    g_key_file_set_integer (settings, "display", "lx", 			conf.lx);
    g_key_file_set_integer (settings, "display", "ly", 			conf.ly);
    g_key_file_set_integer (settings, "display", "dx", 			conf.dx);
    g_key_file_set_integer (settings, "display", "dy", 			conf.dy);
	g_key_file_set_boolean (settings, "display", "tooltips", 	conf.tips);
    g_key_file_set_string (settings, "reader", "device", 		conf.device);
    g_key_file_set_integer (settings, "reader", "speed", 		conf.speed);
    g_key_file_set_uint64 (settings, "reader", "lijnkleur", 	conf.lijnkleur);
    g_key_file_set_uint64 (settings, "reader", "rasterkleur", 	conf.rasterkleur);
    g_key_file_set_boolean (settings, "reader", "raster", 		conf.raster);
	g_key_file_set_boolean (settings, "reader", "speech", 		conf.speech);
	g_key_file_set_integer (settings, "reader", "voice",		conf.voice);
    g_key_file_set_integer (settings, "keys", "paste0",			conf.paste[0]);
    g_key_file_set_integer (settings, "keys", "paste1",			conf.paste[1]);
    g_key_file_set_integer (settings, "keys", "backspace0",		conf.backspace[0]);
    g_key_file_set_integer (settings, "keys", "backspace1",		conf.backspace[1]);

	g_key_file_set_integer (settings, "GB1", "key",			conf.keymode[0].key);
    g_key_file_set_integer (settings, "GB1", "mode",		conf.keymode[0].mode);
    g_key_file_set_integer (settings, "BIG5", "key",		conf.keymode[1].key);
    g_key_file_set_integer (settings, "BIG5", "mode",		conf.keymode[1].mode);
    g_key_file_set_integer (settings, "DIGITS", "key", 		conf.keymode[2].key);
    g_key_file_set_integer (settings, "DIGITS", "mode", 	conf.keymode[2].mode);
    g_key_file_set_integer (settings, "LOWERCASE", "key", 	conf.keymode[3].key);
    g_key_file_set_integer (settings, "LOWERCASE", "mode", 	conf.keymode[3].mode);
    g_key_file_set_integer (settings, "UPPERCASE", "key", 	conf.keymode[4].key);
    g_key_file_set_integer (settings, "UPPERCASE", "mode",	conf.keymode[4].mode);
    g_key_file_set_integer (settings, "PUNC", "key",		conf.keymode[5].key);
    g_key_file_set_integer (settings, "PUNC", "mode",		conf.keymode[5].mode);
    g_key_file_set_integer (settings, "DEFAULT", "key",		conf.keymode[6].key);
    g_key_file_set_integer (settings, "DEFAULT", "mode", 	conf.keymode[6].mode);

	for (i=0; i<13; i++) {
		g_string_sprintf(label, "key%d", i+1);
		g_key_file_set_integer (settings, "keydefs", label->str, conf.defkey[i].key);
		g_string_sprintf(label, "label%d", i+1);
		g_key_file_set_string (settings, "keydefs", label->str, conf.defkey[i].label);
	}

    data = g_key_file_to_data (settings, &len, NULL);
    g_file_set_contents (filepad, data, len, NULL);

    g_string_free(label, TRUE);
    g_free(data);
}
Beispiel #7
0
static void statusbar_lag(SBAR_ITEM_REC *item, int ypos)
{
	IRC_SERVER_REC *server;
	GString *str;
	int size_needed, lag_unknown;
	time_t now;

	now = time(NULL);
	str = g_string_new(NULL);

	server = (IRC_SERVER_REC *) (active_win == NULL ? NULL : active_win->active_server);
	if (server == NULL || server->lag_last_check == 0)
		size_needed = 0;
	else if (server->lag_sent == 0 || now-server->lag_sent < 5) {
		lag_unknown = now-server->lag_last_check >
			MAX_LAG_UNKNOWN_TIME+settings_get_int("lag_check_time");

		if (server->lag < lag_min_show && !lag_unknown)
			size_needed = 0; /* small lag, don't display */
		else {
			g_string_sprintf(str, "%d.%02d", server->lag/1000, (server->lag % 1000)/10);
			if (lag_unknown)
				g_string_append(str, " (??)");
			size_needed = str->len+7;
		}
	} else {
		/* big lag, still waiting .. */
		g_string_sprintf(str, "%ld (??)", now-server->lag_sent);
		size_needed = str->len+7;
	}

    if (item->size != size_needed)
    {
        /* we need more (or less..) space! */
        statusbar_item_resize(item, size_needed);
        g_string_free(str, TRUE);
        return;
    }

    if (item->size != 0)
    {
	lag_last_draw = now;
	move(ypos, item->xpos);
	set_color((1 << 4)+3); addch('[');
	set_color((1 << 4)+7); addstr("Lag: ");

	set_color((1 << 4)+15); addstr(str->str);
	set_color((1 << 4)+3); addch(']');

	screen_refresh();
    }
    g_string_free(str, TRUE);
}
Beispiel #8
0
/* SYNTAX: WHOIS [<server>] [<nicks>] */
static void cmd_whois(const char *data, IRC_SERVER_REC *server,
		      WI_ITEM_REC *item)
{
	GHashTable *optlist;
	char *qserver, *query, *event_402;
	void *free_arg;
	int free_nick;

	g_return_if_fail(data != NULL);
	if (!IS_IRC_SERVER(server) || !server->connected)
		cmd_return_error(CMDERR_NOT_CONNECTED);

	if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTIONS,
			    "whois", &optlist, &qserver, &query))
		return;

	if (*query == '\0') {
		query = qserver;
		qserver = "";
	}
	if (*query == '\0') {
		QUERY_REC *queryitem = QUERY(item);
		query = queryitem != NULL ? queryitem->name : server->nick;
	}

	if (strcmp(query, "*") == 0 &&
	    g_hash_table_lookup(optlist, "yes") == NULL)
		cmd_param_error(CMDERR_NOT_GOOD_IDEA);

	event_402 = "event 402";
	if (*qserver == '\0')
		g_string_sprintf(tmpstr, "WHOIS %s", query);
	else {
		g_string_sprintf(tmpstr, "WHOIS %s %s", qserver, query);
		if (g_strcasecmp(qserver, query) == 0)
			event_402 = "whois event noserver";
	}

	server->whois_found = FALSE;
	irc_send_cmd_split(server, tmpstr->str, 2, server->max_whois_in_cmd);

	/* do automatic /WHOWAS if any of the nicks wasn't found */
	query = get_redirect_nicklist(query, &free_nick);

	server_redirect_event(SERVER(server), query, 3,
			      "event 318", "event 318", 1,
			      "event 402", event_402, -1,
			      "event 401", "whois not found", 1,
			      "event 311", "whois event", 1, NULL);
	if (free_nick) g_free(query);
	cmd_params_free(free_arg);
}
Beispiel #9
0
static void bans_ask_channel(const char *channel, IRC_SERVER_REC *server,
			     WI_ITEM_REC *item)
{
	GString *str;

	str = g_string_new(NULL);
	g_string_sprintf(str, "%s b", channel);
	signal_emit("command mode", 3, str->str, server, item);
	if (server->emode_known) {
		g_string_sprintf(str, "%s e", channel);
		signal_emit("command mode", 3, str->str, server, item);
	}
	g_string_free(str, TRUE);
}
Beispiel #10
0
/*
 * Insert possible providers on a host.
 */
static guint
gdisp_insertHostProviders ( Kernel_T *kernel,
                            Host_T   *host )
{
    GString        *messageString    = (GString*)NULL;
    gchar          *hostUrl          = (gchar*) NULL;
    gint            providerCpt      = 0;
    gint            providersFound   = 0;

    /*
     * Look for and insert providers on the given host.
     */
    hostUrl = g_malloc0(strlen(host->hName->str) + 10);
    for (providerCpt=0; providerCpt<TSP_MAX_SERVER_NUMBER; providerCpt++) {

        sprintf(hostUrl, "//%s/:%d", host->hName->str, providerCpt);

        if (gdisp_insertProvider(kernel,hostUrl) == 0) {
            providersFound++;
        }

    }
    g_free(hostUrl);

    /*
     * Report the number of providers that have been found.
     */
    messageString = g_string_new((gchar*)NULL);
    if (providersFound == 0) {

        g_string_sprintf(messageString,
                         "No TSP provider found on host %s.",
                         host->hName->str);

    }
    else {

        g_string_sprintf(messageString,
                         "%d TSP provider(s) found on host %s.",
                         providersFound,
                         host->hName->str);

    }

    (*kernel->outputFunc)(kernel,messageString,GD_WARNING);

    return providersFound;

}
/**
 * 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_append_c (s, '>');

  /* don't return the wrapper object */
  chararray = s->str;
  g_string_free (s, FALSE);
  return chararray;
}
Beispiel #12
0
/************************************************************
* int UD_ack()                                            *
*
* Sends an acknowledgement to DBupdate and receives a reply *                                                           *
*                                                           *
* Return codes:                                             *
*                                                           *
* 0  - OK
* -1 - 
************************************************************/
int UD_ack(Transaction_t* tr) {
    GString *g_buff;
    int res, error;

    /* if we are not in update/server mode - no ack is needed - just return */
    if (IS_STANDALONE(tr->mode))
        return (0);
    if (!IS_UPDATE(tr->mode))
        return (0);

    g_buff = g_string_sized_new(STR_L);

    if (tr->succeeded == 0) { /* update failed */
        error = tr->error;
    } else
        error = 0;

    g_string_sprintf(g_buff, "%%ERROR %d\n%s\n", error, (tr->error_script)->str);
    res = SK_puts(tr->socket, g_buff->str, NULL );
    g_string_free(g_buff, TRUE);
    /* close the connection */
    /* Let DBupdate close the connection */
    /* close(tr->socket); */
    return (res);
}
/**
 * aos_kernel_server_remove:
 * @id: 
 * @usr_function: function to be executed on server response.
 * @usr_data: user data to be passed to @user_function
 * 
 * Removes from af-kernel the server identified by @id.
 * 
 * Return value: 
 **/
gboolean           aos_kernel_server_remove   (gint id,
						 AfDalNulFunc   usr_function,
						 gpointer       usr_data)
{
	GString * identifier = NULL;
	gboolean  result;
	RRConnection * connection = NULL;

	connection = afdal_session_get_connection ("af-kernel", NULL);
	if (! connection)
		return FALSE;
	
	identifier = g_string_new (NULL);
	
	g_string_sprintf (identifier, "%d", id);
	
	result = afdal_request (connection, afdal_request_process_nul_data, (AfDalFunc) usr_function, usr_data,
				"server_remove", 
				"id", COYOTE_XML_ARG_STRING, identifier->str,
				NULL);
	
	g_string_free (identifier, TRUE);
	
	return result;
};
Beispiel #14
0
static void cmd_perl(const char *data)
{
	dSP;
	GString *code;
	char *uses;
        SV *sv;

	ENTER;
	SAVETMPS;

	PUSHMARK(SP);

	code = g_string_new(NULL);

	uses = perl_get_use_list();
	g_string_sprintf(code, "sub { use Irssi;%s\n%s }", uses, data);

	sv = perl_eval_pv(code->str, TRUE);
	perl_call_sv(sv, G_VOID|G_NOARGS|G_EVAL|G_DISCARD);

        g_free(uses);
	g_string_free(code, TRUE);

	SPAGAIN;

	if (SvTRUE(ERRSV)) {
		STRLEN n_a;

		signal_emit("gui dialog", 2, "error", SvPV(ERRSV, n_a));
	}

	PUTBACK;
	FREETMPS;
	LEAVE;
}
Beispiel #15
0
/* SYNTAX: NOTICE <targets> <message> */
static void cmd_notice(const char *data, IRC_SERVER_REC *server,
		       WI_ITEM_REC *item)
{
	const char *target, *msg;
	char *recoded;
	void *free_arg;

        CMD_IRC_SERVER(server);

	if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST,
			    &target, &msg))
		return;
	if (strcmp(target, "*") == 0)
		target = item == NULL ? NULL : window_item_get_target(item);
	if (*target == '\0' || *msg == '\0')
		cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);

	recoded = recode_out(SERVER(server), msg, target);
	g_string_sprintf(tmpstr, "NOTICE %s :%s", target, recoded);
	g_free(recoded);

	irc_send_cmd_split(server, tmpstr->str, 2, server->max_msgs_in_cmd);

	cmd_params_free(free_arg);
}
void SetString(GString **ptr, char *line) {
	if (ptr <= 0) { return; }
	if (*ptr <= 0) {
		*ptr = g_string_new(line);
		return;
	}
	g_string_sprintf(*ptr, line);
}
Beispiel #17
0
static gboolean sig_incoming(SERVER_REC *server, gchar *line)
{
    g_return_val_if_fail(line != NULL, FALSE);

    /* send server event to all clients */
    g_string_sprintf(next_line, "%s\n", line);
    return TRUE;
}
Beispiel #18
0
/**
 * http_ftp_login:
 * @self: HttpProxy instance
 * @user: username to log in with
 * @passwd: password for @user
 *
 * Log in to the FTP server using credentials in @user and @passwd.
 **/
static gboolean
http_ftp_login(HttpProxy *self, const gchar *user, const gchar *passwd)
{
  gchar response_msg[1024];
  gint status;

  if (!http_ftp_communicate(self, "USER", user, &status, response_msg, sizeof(response_msg)))
    return FALSE;

  if (status == 230)
    {
      /* no password required */
      return TRUE;
    }
  else if (status != 331)
    {
      /* no password required */
      g_string_sprintf(self->error_info, "Unhandled status code returned to login request (%d, %s)", status, response_msg);
      /*LOG
        This message indicates that the FTP server returned an unknown
        status code in response to our login request.
      */
      z_proxy_log(self, HTTP_ERROR, 4, "FTP server returned an unhandled status code for the login request; ftp_status='%d'", status);
      return FALSE;
    }

  if (!http_ftp_communicate(self, "PASS", passwd, &status, response_msg, sizeof(response_msg)))
    return FALSE;

  if (status == 230)
    {
      /* logged in */
      return TRUE;
    }
  else
    {
      g_string_sprintf(self->error_info, "Error logging in (%d, %s)", status, response_msg);
      /*LOG
        This message indicates that the FTP refused our authentication
        attempt.
      */
      z_proxy_log(self, HTTP_ERROR, 4, "Error logging in; user='******', ftp_status='%d', ftp_response='%s'", user, status, response_msg);
      return FALSE;
    }
}
Beispiel #19
0
static void replaygain_preamp_cb(GtkWidget *widget, gpointer data)
{
	GString *gstring = g_string_new("");
	(void)widget, (void)data; /* unused arguments */
	flac_cfg.output.replaygain.preamp = (int) floor(GTK_ADJUSTMENT(replaygain_preamp)->value + 0.5);

	g_string_sprintf(gstring, "%i dB", flac_cfg.output.replaygain.preamp);
	gtk_label_set_text(GTK_LABEL(replaygain_preamp_label), _(gstring->str));
}
Beispiel #20
0
static void create_names_start(GString *str, IRC_CHANNEL_REC *channel,
			       CLIENT_REC *client)
{
	g_string_sprintf(str, ":%s 353 %s %c %s :",
			 client->proxy_address, client->nick,
			 channel_mode_is_set(channel, 'p') ? '*' :
			 channel_mode_is_set(channel, 's') ? '@' : '=',
			 channel->name);
}
Beispiel #21
0
/**
 * http_ftp_initiate_passive_data:
 * @self: HttpProxy instance
 *
 * This function is called to initiate a passive data connection to the FTP
 * server. If it returns FALSE an active connection might still be
 * attempted. (however it is currently unimplemented).
 *
 * It currently creates the ZAttach object only does not start the actual
 * connection, it is done somewhat later in the http_ftp_complete_data()
 * function.
 **/
static gboolean
http_ftp_initiate_passive_data(HttpProxy *self)
{
  gchar response_msg[1024];
  gint status;
  gchar *start, *end;
  gint i;
  gint ftp_pasv_endpoint[6];
  gchar ip[16];
  ZSockAddr *peer;
  ZAttachParams params;

  if (!http_ftp_communicate(self, "PASV", NULL, &status, response_msg, sizeof(response_msg)))
    return FALSE;

  if (status != 227)
    return FALSE;

  start = strchr(response_msg, '(');

  if (!start)
    {
      /* hmm no '(' in PASV response */
      return FALSE;
    }

  start++;

  for (i = 0; i < 6; i++)
    {
      ftp_pasv_endpoint[i] = strtol(start, &end, 10);

      if ((i < 5 && *end != ',') ||
          (i == 5 && *end != ')'))
        {
          g_string_sprintf(self->error_info, "Response to PASV is invalid; response='%s'", response_msg);
          return FALSE;
        }

      start = end + 1;
    }

  g_snprintf(ip, sizeof(ip), "%d.%d.%d.%d", ftp_pasv_endpoint[0], ftp_pasv_endpoint[1], ftp_pasv_endpoint[2], ftp_pasv_endpoint[3]);
  peer = z_sockaddr_inet_new(ip, 256 * ftp_pasv_endpoint[4] + ftp_pasv_endpoint[5]);

  memset(&params, 0, sizeof(params));
  params.timeout = 30000;

  self->ftp_data_attach = z_attach_new(&self->super, ZD_PROTO_TCP, NULL, peer, &params, NULL, NULL, NULL);
  z_sockaddr_unref(peer);
  /* attach not started yet */

  return TRUE;
}
Beispiel #22
0
/* verify that all settings in config file for `module' are actually found
   from /SET list */
void settings_check_module(const char *module)
{
        SETTINGS_REC *set;
	CONFIG_NODE *node, *parent;
        GString *errors;
	GSList *tmp, *next;
        int count;

        g_return_if_fail(module != NULL);

	node = iconfig_node_traverse("settings", FALSE);
	node = node == NULL ? NULL : config_node_section(node, module, -1);
	if (node == NULL) return;

        errors = g_string_new(NULL);
	g_string_sprintf(errors, "Unknown settings in configuration "
			 "file for module %s:", module);

        count = 0;
	parent = node;
	tmp = config_node_first(node->value);
	for (; tmp != NULL; tmp = next) {
		node = tmp->data;
		next = config_node_next(tmp);

		set = g_hash_table_lookup(settings, node->key);
		if (backwards_compatibility(module, node, parent))
			continue;

		if (set == NULL || strcmp(set->module, module) != 0) {
			g_string_sprintfa(errors, " %s", node->key);
                        count++;
		}
	}
	if (count > 0) {
		if (gslist_find_icase_string(last_invalid_modules,
					     module) == NULL) {
                        /* mark this module having invalid settings */
			last_invalid_modules =
				g_slist_append(last_invalid_modules,
					       g_strdup(module));
		}
		if (fe_initialized)
                        signal_emit("settings errors", 1, errors->str);
		else {
			if (last_errors == NULL)
				last_errors = g_string_new(NULL);
			else
				g_string_append_c(last_errors, '\n');
                        g_string_append(last_errors, errors->str);
		}
	}
        g_string_free(errors, TRUE);
}
Beispiel #23
0
/* Update status label */
void Window::Update( bool noUpdate )
{
	if( active || noUpdate )
	{
		if( !noUpdate )
			++ seconds;
		
		GString* temp = g_string_new( NULL );
		g_string_sprintf( temp, "<span size=\"x-large\">%lu days %02lu:%02lu:%02lu</span>", seconds / ( 24 * 3600 ), ( seconds / 3600 ) % 24, ( seconds / 60 ) % 60, seconds % 60 );
		gtk_label_set_markup( GTK_LABEL( pgStatus ), temp->str );
	}
}
Beispiel #24
0
/**
 * Returns a text representation of this model.
 *
 * @param self the model.
 * @return a string.
 */
char *
to_string (struct ergadm_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_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  appraisal (per unit)=%g\n", local_data->appraisal);
  g_string_sprintfa (s, "  euthanasia (per animal)=%g\n", local_data->euthanasia);
  g_string_sprintfa (s, "  indemnification (per animal)=%g\n", local_data->indemnification);
  g_string_sprintfa (s, "  carcass-disposal (per animal)=%g\n", local_data->carcass_disposal);
  g_string_sprintfa (s, "  cleaning-disinfecting (per unit)=%g\n",
                     local_data->cleaning_disinfecting);

  substring = REL_chart_to_string (local_data->visiting);
  g_string_sprintfa (s, "  visiting=%s\n", substring);
  free (substring);

  substring = REL_chart_to_string (local_data->testing);
  g_string_sprintfa (s, "  testing=%s\n", substring);
  free (substring);

  g_string_sprintfa (s, "  vaccination-fixed (per unit)=%g\n", local_data->vaccination_fixed);
  g_string_sprintfa (s, "  vaccination (per animal)=%g\n", local_data->vaccination);
  g_string_sprintfa (s, "  baseline-capacity=%u\n", local_data->baseline_capacity);
  g_string_sprintfa (s, "  additional-vaccination (per animal)=%g>", local_data->extra_vaccination);

  /* don't return the wrapper object */
  chararray = s->str;
  g_string_free (s, FALSE);
  return chararray;
}
Beispiel #25
0
/* SYNTAX: CTCP <targets> <ctcp command> [<ctcp data>] */
static void cmd_ctcp(const char *data, IRC_SERVER_REC *server)
{
	char *target, *ctcpcmd, *ctcpdata;
	void *free_arg;

	g_return_if_fail(data != NULL);
	if (!IS_IRC_SERVER(server) || !server->connected)
		cmd_return_error(CMDERR_NOT_CONNECTED);

	if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_GETREST, &target, &ctcpcmd, &ctcpdata))
		return;
	if (*target == '\0' || *ctcpcmd == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);

	g_strup(ctcpcmd);
	if (*ctcpdata == '\0')
		g_string_sprintf(tmpstr, "PRIVMSG %s :\001%s\001", target, ctcpcmd);
	else
		g_string_sprintf(tmpstr, "PRIVMSG %s :\001%s %s\001", target, ctcpcmd, ctcpdata);
	irc_send_cmd_split(server, tmpstr->str, 2, server->max_msgs_in_cmd);

	cmd_params_free(free_arg);
}
Beispiel #26
0
static void salida_imprimir(const char *value, GladeXML *xml) {
  if(value) {
    GString *valor = g_string_new("");
    g_string_sprintf(valor, "%s\n", (char *)value);
    GtkWidget* texto =  glade_xml_get_widget(xml, "txt_salida");
    GtkTextIter iter;
    GtkTextBuffer * buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(texto));
    gtk_text_buffer_get_iter_at_offset(buffer, &iter, -1);
    gtk_text_buffer_insert(buffer, &iter, valor->str, -1);
    g_string_free(valor, TRUE);
    gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(texto), &iter, 0.0, FALSE, 1.0, 1.0);
  }
}
Beispiel #27
0
/** 
 * log_stamp_format:
 * @stamp: Timestamp to format
 * @target: Target storage for formatted timestamp
 * @ts_format: Specifies basic timestamp format (TS_FMT_BSD, TS_FMT_ISO)
 * @zone_offset: Specifies custom zone offset if @tz_convert == TZ_CNV_CUSTOM
 *
 * Emits the formatted version of @stamp into @target as specified by
 * @ts_format and @tz_convert. 
 **/
void
log_stamp_append_format(LogStamp *stamp, GString *target, gint ts_format, glong zone_offset, gint frac_digits)
{
  glong target_zone_offset = 0;
  struct tm *tm, tm_storage;
  char buf[8];
  time_t t;
  
  if (zone_offset != -1)
    target_zone_offset = zone_offset;
  else
    target_zone_offset = stamp->zone_offset;

  t = stamp->time.tv_sec + target_zone_offset;
  if (!(tm = gmtime_r(&t, &tm_storage))) 
    {
      /* this should never happen */
      g_string_sprintf(target, "%d", (int) stamp->time.tv_sec);
      msg_error("Error formatting time stamp, gmtime() failed",
                evt_tag_int("stamp", (int) t),
                NULL);
    } 
  else 
    {
      switch (ts_format)
        {
        case TS_FMT_BSD:
          g_string_append_printf(target, "%s %2d %02d:%02d:%02d", month_names_abbrev[tm->tm_mon], tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
          log_stamp_append_frac_digits(stamp, target, frac_digits);
          break;
        case TS_FMT_ISO:
          g_string_append_printf(target, "%d-%02d-%02dT%02d:%02d:%02d", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
          log_stamp_append_frac_digits(stamp, target, frac_digits);
          format_zone_info(buf, sizeof(buf), target_zone_offset);
          g_string_append(target, buf);
          break;
        case TS_FMT_FULL:
          g_string_append_printf(target, "%d %s %2d %02d:%02d:%02d", tm->tm_year + 1900, month_names_abbrev[tm->tm_mon], tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
          log_stamp_append_frac_digits(stamp, target, frac_digits);
          break;
        case TS_FMT_UNIX:
          g_string_append_printf(target, "%d", (int) stamp->time.tv_sec);
          log_stamp_append_frac_digits(stamp, target, frac_digits);
          break;
        default:
          g_assert_not_reached();
          break;
        }
    }
}
Beispiel #28
0
/**
 * Returns a text representation of this model.
 *
 * @param self the model.
 * @return a string.
 */
char *
to_string (struct ergadm_model_t_ *self)
{
    GString *s;
    char *chararray;

    s = g_string_new (NULL);
    g_string_sprintf (s, "<%s>", MODEL_NAME);

    /* don't return the wrapper object */
    chararray = s->str;
    g_string_free (s, FALSE);
    return chararray;
}
Beispiel #29
0
void funcion_error(const char *nombre, const char *modulo, const char *textos) {
  if(xml && nombre && textos && modulo) {
    GString *valor = g_string_new("");
    g_string_sprintf(valor, "%s [%s]: %s\n", strdup(nombre), strdup(modulo), strdup(textos));
    // Sacar la salida por pantalla hace fácil redirigir el resultado de depuración
    // a un archivo de texto: pipeline --timer=500 vision.xml > vision.log
    printf("%s", valor->str);
    GtkWidget* texto =  glade_xml_get_widget(xml, "txt_error");
    GtkTextIter iter;
    GtkTextBuffer * buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(texto));
    gtk_text_buffer_get_iter_at_offset(buffer, &iter, -1);
    gtk_text_buffer_insert(buffer, &iter, valor->str, -1);
    g_string_free(valor, TRUE);
    gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(texto), &iter, 0.0, FALSE, 1.0, 1.0);
  }
}
Beispiel #30
0
static void sig_nicklist_new(CHANNEL_REC *channel, NICK_REC *nick)
{
	NICK_REC *firstnick;
	GString *newnick;
	char *nickhost, *p;
	int n;

	if (nick->host == NULL)
                return;

	firstnick = g_hash_table_lookup(channel->nicks, nick->nick);
	if (firstnick->next == NULL)
		return;

	if (nick == channel->ownnick) {
		/* own nick is being added, might be a nick change and
		   someone else having the original nick already in use.. */
		nick = printnick_find_original(firstnick->next);
		if (nick == NULL)
                        return; /* nope, we have it */
	}

	/* identical nick already exists, have to change it somehow.. */
	p = strchr(nick->host, '@');
	if (p == NULL) p = nick->host; else p++;

	nickhost = g_strdup_printf("%s@%s", nick->nick, p);
	p = strchr(nickhost+strlen(nick->nick), '.');
	if (p != NULL) *p = '\0';

	if (!printnick_exists(firstnick, nick, nickhost)) {
                /* use nick@host */
		g_hash_table_insert(printnicks, nick, nickhost);
                return;
	}

	newnick = g_string_new(NULL);
        n = 2;
	do {
		g_string_sprintf(newnick, "%s%d", nickhost, n);
                n++;
	} while (printnick_exists(firstnick, nick, newnick->str));

	g_hash_table_insert(printnicks, nick, newnick->str);
	g_string_free(newnick, FALSE);
        g_free(nickhost);
}