コード例 #1
0
ファイル: hashs.c プロジェクト: dupgit/sauvegarde
/**
 * makes a GSList of hash_data_t * element where 'hash' field is base64
 * decoded hashs from a string containning base64 * encoded hashs that
 * must be separated by commas.
 * @param the string containing base64 encoded hashs such as : *
 *        "cCoCVkt/AABf04jn2+rfDmqJaln6P2A9uKolBjEFJV4=", "0G8MaPZ/AADNyaPW7ZP2s0BI4hAdZZIE2xO1EwdOzhE="
 *        for instance.
 * @returns a GSList of hash_data_t * where each elements contains a
 *          base64 decoded hash (binary form).
 */
GList *make_hash_data_list_from_string(gchar *hash_string)
{
    guint i = 0;
    gchar **hashs = NULL;
    gchar *a_hash = NULL;
    hash_data_t *hash_data = NULL;
    GList *hash_list = NULL;
    gsize len = 0;

    if (hash_string != NULL)
        {
            /* hash list generation */
            hashs = g_strsplit(hash_string, ",", -1);

            while (hashs[i] != NULL)
                {
                    a_hash = g_strndup(g_strchug(hashs[i] + 1), strlen(g_strchug(hashs[i])) - 2);

                    /* we have to base64 decode it to insert it into the hash_data_t * structure
                     * and then into the meta_data one.
                     */
                    hash_data = new_hash_data_t_as_is(NULL, 0, g_base64_decode(a_hash, &len), COMPRESS_NONE_TYPE, 0);
                    hash_list = g_list_prepend(hash_list, hash_data);
                    free_variable(a_hash);
                    i = i + 1;
                }

            g_strfreev(hashs);

            hash_list = g_list_reverse(hash_list);
        }

    return hash_list;
}
コード例 #2
0
ファイル: main.c プロジェクト: abligh/ocfs2-tools
static char *get_line(FILE *stream, int no_prompt)
{
	char *line;
	static char buf[1024];
	int i;

	if (stream) {
		while (1) {
			if (!fgets(buf, sizeof(buf), stream))
				return NULL;
			line = buf;
			i = strlen(line);
			if (i)
				buf[i - 1] = '\0';
			g_strchug(line);
			if (strlen(line))
				break;
		}
	} else {
		if (no_prompt)
			line = readline(NULL);
		else
			line = readline(PROMPT);

		if (line && *line) {
			g_strchug(line);
			add_history(line);
		}
	}

	return line;
}
コード例 #3
0
ファイル: misc.c プロジェクト: elmo2k3/had
/* the following function is a "copy&paste" from mpd */
int buffer2array(char *buffer, char *array[], const int max)
{
    int i = 0;
    char *c = buffer;

    while (*c != '\0' && i < max) {
        if (*c == '\"') {
            array[i++] = ++c;
            while (*c != '\0') {
                if (*c == '\"') {
                    *(c++) = '\0';
                    break;
                }
                else if (*(c++) == '\\' && *c != '\0') {
                    memmove(c - 1, c, strlen(c) + 1);
                }
            }
        } else {
            c = g_strchug(c);
            if (*c == '\0')
                return i;

            array[i++] = c++;

            while (!g_ascii_isspace(*c) && *c != '\0')
                ++c;
        }
        if (*c == '\0')
            return i;
        *(c++) = '\0';

        c = g_strchug(c);
    }
    return i;
}
コード例 #4
0
ファイル: message-gen.c プロジェクト: karfai/portfolio
static void interpret_header(GSList** stack, gchar** args)
{
    GMimeObject* o = GMIME_OBJECT((*stack)->data);
    if ( 0 == g_strcmp0("Date", args[0]) && GMIME_IS_MESSAGE(o) ) {
        g_mime_message_set_date_as_string(GMIME_MESSAGE(o), g_strchug(args[1]));
    } else {
        g_mime_object_set_header(o, args[0], g_strchug(args[1]));
    }
}
コード例 #5
0
ファイル: configfile.c プロジェクト: sedwards/xmms3
static ConfigLine *xmms_cfg_create_string(ConfigSection * section, char * key, char * value)
{
	ConfigLine *line;

	line = g_malloc0(sizeof (ConfigLine));
	line->key = g_strchug(g_strchomp(g_strdup(key)));
	line->value = g_strchug(g_strchomp(g_strdup(value)));
	section->lines = g_list_append(section->lines, line);

	return line;
}
コード例 #6
0
/*
* Move off fields page.
* return: TRUE if OK to move off page.
*/
static gboolean imp_ldif_file_move() {
	gboolean retVal = FALSE;
	gchar *sName;
	gchar *sFile;
	gchar *sMsg = NULL;
	gboolean errFlag = FALSE;

	sFile = gtk_editable_get_chars( GTK_EDITABLE(impldif_dlg.file_entry), 0, -1 );
	g_strchug( sFile ); g_strchomp( sFile );

	sName = gtk_editable_get_chars( GTK_EDITABLE(impldif_dlg.name_entry), 0, -1 );
	g_strchug( sName ); g_strchomp( sName );

	g_free( impldif_dlg.nameBook );
	g_free( impldif_dlg.fileName );
	impldif_dlg.nameBook = sName;
	impldif_dlg.fileName = sFile;

	gtk_entry_set_text( GTK_ENTRY(impldif_dlg.file_entry), sFile );
	gtk_entry_set_text( GTK_ENTRY(impldif_dlg.name_entry), sName );

	if( *sFile == '\0'|| strlen( sFile ) < 1 ) {
		sMsg = _( "Please select a file." );
		gtk_widget_grab_focus(impldif_dlg.file_entry);
		errFlag = TRUE;
	}

	if( *sName == '\0'|| strlen( sName ) < 1 ) {
		if( ! errFlag ) sMsg = _( "Address book name must be supplied." );
		gtk_widget_grab_focus(impldif_dlg.name_entry);
		errFlag = TRUE;
	}

	if( ! errFlag ) {
		gchar *sFSFile;
		/* Read attribute list */
		sFSFile = conv_filename_from_utf8( sFile );
		ldif_set_file( _ldifFile_, sFSFile );
		g_free( sFSFile );
		if( ldif_read_tags( _ldifFile_ ) == MGU_SUCCESS ) {
			/* Load fields */
			/* ldif_print_file( _ldifFile_, stdout ); */
			imp_ldif_load_fields( _ldifFile_ );
			retVal = TRUE;
		}
		else {
			sMsg = _( "Error reading LDIF fields." );
		}
	}
	imp_ldif_status_show( sMsg );

	return retVal;
}
コード例 #7
0
/*
 * MateCORBA_option_rc_parse:
 * @rcfile: the path of the matecorbarc file.
 * @option_list: the #MateCORBA_options to parse from the file.
 *
 * Parses @rcfile for any of the options in @option_list. The syntax
 * of rcfile is simple : 'option=value'.
 *
 * Note: leading or trailing whitespace is allowed for both the option 
 *       and its value.
 */
static void
MateCORBA_option_rc_parse (const gchar         *rcfile,
		       const MateCORBA_option  *option_list)
{
	gchar  line [1024];
	FILE  *fh;

	fh = g_fopen (rcfile, "r");
	if (!fh)
		return;

#ifdef DEBUG
	fprintf (stderr, "Parsing file %s for options\n", rcfile);
#endif

	while (fgets (line, sizeof (line), fh)) {
		const MateCORBA_option  *option = NULL;
		gchar              **strvec;
		gchar               *key;
		gchar               *value;

		if (line [0] == '#')
			continue;

		strvec = g_strsplit (line, "=", 3);

		if (!strvec || !strvec[0] || !strvec[1])
			continue;

		key = g_strchomp (g_strchug (strvec[0]));

                for (option = option_list; option->name; option++)
			if (!strcmp (key, option->name))
				break;

		if (!option->name) {
			option = NULL;
			continue;
		}

		value = g_strchomp (g_strchug (strvec[1]));

		MateCORBA_option_set (option, value);

		g_strfreev (strvec);
	}

	fclose (fh);
}
コード例 #8
0
static void
gfig_read_parameter_string (gchar       **text,
                            gint          nitems,
                            const gchar  *name,
                            gchar        **style_entry)
{
  gint  n = 0;
  gchar *ptr;
  gchar *tmpstr;

  *style_entry = NULL;

  while (n < nitems)
    {
      ptr = strchr (text[n], ':');
      if (ptr)
        {
          tmpstr = g_strndup (text[n], ptr - text[n]);
          ptr++;
          if (!strcmp (tmpstr, name))
            {
              *style_entry = g_strdup (g_strchug (ptr));
              g_free (tmpstr);
              return;
            }
          g_free (tmpstr);
        }
      ++n;
    }

  g_message ("Parameter '%s' not found", name);
}
コード例 #9
0
ファイル: scrobbler-journal.c プロジェクト: alip/mpdcron
void journal_read(const char *path, GQueue *queue)
{
	FILE *file;
	char line[1024];
	struct record record;

	journal_file_empty = true;

	file = fopen(path, "r");
	if (file == NULL) {
		if (errno != ENOENT)
			/* ENOENT is ignored silently, because the
			 * user might be starting mpdcron for the
			 * first time */
			g_warning("Failed to load %s: %s",
					path, g_strerror(errno));
		return;
	}

	record_clear(&record);

	while (fgets(line, sizeof(line), file) != NULL) {
		char *key, *value;

		key = g_strchug(line);
		if (*key == 0 || *key == '#')
			continue;

		value = strchr(key, '=');
		if (value == NULL || value == key)
			continue;

		*value++ = 0;

		key = g_strchomp(key);
		value = g_strstrip(value);

		if (!strcmp("a", key)) {
			journal_commit_record(queue, &record);
			record.artist = g_strdup(value);
		} else if (!strcmp("t", key))
			record.track = g_strdup(value);
		else if (!strcmp("b", key))
			record.album = g_strdup(value);
		else if (!strcmp("n", key))
			record.number = g_strdup(value);
		else if (!strcmp("m", key))
			record.mbid = g_strdup(value);
		else if (!strcmp("i", key))
			record.time = parse_timestamp(value);
		else if (!strcmp("l", key))
			record.length = atoi(value);
		else if (strcmp("o", key) == 0 && value[0] == 'R')
			record.source = "R";
	}

	fclose(file);

	journal_commit_record(queue, &record);
}
コード例 #10
0
ファイル: events.c プロジェクト: gnehzr/uzbl
/*
 * build event string and send over the supported interfaces
 * custom_event == NULL indicates an internal event
*/
void
send_event(int type, const gchar *details, const gchar *custom_event) {
    GString *event_message = g_string_new("");
    gchar *buf, *p_val = NULL;

    /* expand shell vars */
    if(details) {
        buf = g_strdup(details);
        p_val = parseenv(buf ? g_strchug(buf) : " ");
        g_free(buf);
    }

    /* check for custom events */
    if(custom_event) {
        g_string_printf(event_message, "EVENT [%s] %s %s\n",
                uzbl.state.instance_name, custom_event, p_val);
    }
    /* check wether we support the internal event */
    else if(type < LAST_EVENT) {
        g_string_printf(event_message, "EVENT [%s] %s %s\n",
                uzbl.state.instance_name, event_table[type], p_val);
    }

    if(event_message->str) {
        if(uzbl.state.events_stdout)
            send_event_stdout(event_message);
        send_event_socket(event_message);

        g_string_free(event_message, TRUE);
    }
    g_free(p_val);
}
コード例 #11
0
static void
gfig_read_parameter_int (gchar       **text,
                         gint          nitems,
                         const gchar  *name,
                         gint         *style_entry)
{
  gint  n = 0;
  gchar *ptr;
  gchar *tmpstr;

  *style_entry = 0;

  while (n < nitems)
    {
      ptr = strchr (text[n], ':');
      if (ptr)
        {
          tmpstr = g_strndup (text[n], ptr - text[n]);
          ptr++;
          if (!strcmp (tmpstr, name))
            {
              *style_entry = atoi (g_strchug (ptr));
              g_free (tmpstr);
              return;
            }
          g_free (tmpstr);
        }
      ++n;
    }
}
コード例 #12
0
ファイル: jpilot.c プロジェクト: moreorless/claws-mail
/**
 * Load list with character strings of custom label names. Only none blank
 * names are loaded.
 * \param pilotFile  JPilot control data.
 * \param labelList List of label names to load.
 * \return List of label names loaded. Should be freed when done.
 */
GList *jpilot_load_custom_label( JPilotFile *pilotFile, GList *labelList ) {
	gint i;
	char convertBuff[JPILOT_LEN_LABEL];

	g_return_val_if_fail( pilotFile != NULL, NULL );

	if( pilotFile->readMetadata ) {
		struct AddressAppInfo *ai = & pilotFile->addrInfo;
		for( i = 0; i < NUM_CUSTOM_LABEL; i++ ) {
			gchar *labelName = ai->labels[i+IND_CUSTOM_LABEL];
			if( labelName ) {
				g_strchomp( labelName );
				g_strchug( labelName );
				if( *labelName != '\0' ) {
					if( convert_charcode ) {
						conv_sjistoeuc( convertBuff, JPILOT_LEN_LABEL, labelName );
						labelName = convertBuff;
					}
					labelList = g_list_append( labelList, g_strdup( labelName ) );
				}
			}
		}
	}
	return labelList;
}
コード例 #13
0
ファイル: helpers.c プロジェクト: BackupTheBerlios/qrc-svn
void gcom_nick_to_gaym(char *nick)
{
    int i = 0;

    if (!nick) {
        return;
    }

    /**
     * If there is a "|" in the first position, it must be removed.
     */
    if (nick[0] == '|') {
        nick[0] = ' ';
        nick = g_strchug(nick);
    }

    /**
     * Any remaining "|" must be replaced with "."
     */
    for (i = 0; i < strlen(nick); i++) {
        if (nick[i] == '|') {
            nick[i] = '.';
        }
    }
    return;
}
コード例 #14
0
ファイル: msgwindow.c プロジェクト: 15ramky/geany
/* try to parse the file and line number where the error occurred described in string
 * and when something useful is found, it stores the line number in *line and the
 * relevant file with the error in *filename.
 * *line will be -1 if no error was found in string.
 * *filename must be freed unless it is NULL. */
void msgwin_parse_compiler_error_line(const gchar *string, const gchar *dir,
		gchar **filename, gint *line)
{
	GeanyFiletype *ft;
	gchar *trimmed_string, *utf8_dir;

	*filename = NULL;
	*line = -1;

	if (G_UNLIKELY(string == NULL))
		return;

	if (dir == NULL)
		utf8_dir = utils_get_utf8_from_locale(build_info.dir);
	else
		utf8_dir = g_strdup(dir);
	g_return_if_fail(utf8_dir != NULL);

	trimmed_string = g_strdup(string);
	g_strchug(trimmed_string); /* remove possible leading whitespace */

	ft = filetypes[build_info.file_type_id];

	/* try parsing with a custom regex */
	if (!filetypes_parse_error_message(ft, trimmed_string, filename, line))
	{
		/* fallback to default old-style parsing */
		parse_compiler_error_line(trimmed_string, filename, line);
	}
	make_absolute(filename, utf8_dir);
	g_free(trimmed_string);
	g_free(utf8_dir);
}
コード例 #15
0
ファイル: shabdarth.c プロジェクト: dpk22dev/shabdarth
void
on_find_clicked ( )
{

	GtkTextBuffer *buffer;
	
	buffer = gtk_text_view_get_buffer ( mydata.meaning_text_view );	
	gtk_text_buffer_set_text ( buffer, "",-1);

	char *word, *entry_word;
	entry_word = gtk_entry_get_text ( mydata.input_word );
	
	word = g_strchomp( g_strchug( g_strdown( entry_word ) ) );
	//g_string_ascii_down () instead for comp
	
/*
	********** convert data. to mydata. **************
	gchar *message = g_strdup_printf("Finding word %s", word);	
	gtk_statusbar_pop( mydata.statusbar, mydata.statusbar_context_id );
//	data.statusbar_context_id = gtk_statusbar_get_context_id ( data.statusbar,"on_find_clicked");
	gtk_statusbar_push( data.statusbar, data.statusbar_context_id, message);
*/	
	if( strlen(word) != 0 )
		find_meaning_put_gui( word );
	//gtk_widget_show( data.window );	
	//gtk_statusbar_pop( data.statusbar, data.statusbar_context_id );
	//gtk_statusbar_push( data.statusbar, data.statusbar_context_id,"Fill or choose a word" );
	
}
コード例 #16
0
ファイル: editldap_basedn.c プロジェクト: SpOOnman/claws
gchar *edit_ldap_basedn_selection( const gchar *hostName, const gint port, gchar *baseDN, const gint tov,
	       const gchar* bindDN, const gchar *bindPW, int ssl, int tls ) {
	gchar *retVal = NULL;

	ldapedit_basedn_cancelled = FALSE;
	if( ! ldapedit_basedn.window ) edit_ldap_bdn_create();
	gtk_widget_grab_focus(ldapedit_basedn.ok_btn);
	gtk_widget_show(ldapedit_basedn.window);
	manage_window_set_transient(GTK_WINDOW(ldapedit_basedn.window));
	gtk_window_set_modal(GTK_WINDOW(ldapedit_basedn.window), TRUE);
	edit_ldap_bdn_status_show( "" );
	edit_ldap_bdn_load_data( hostName, port, tov, bindDN, bindPW, ssl, tls );
	gtk_widget_show(ldapedit_basedn.window);

	gtk_entry_set_text(GTK_ENTRY(ldapedit_basedn.basedn_entry), baseDN);

	gtk_main();
	gtk_widget_hide(ldapedit_basedn.window);
	gtk_window_set_modal(GTK_WINDOW(ldapedit_basedn.window), FALSE);
	if( ldapedit_basedn_cancelled ) return NULL;
	if( ldapedit_basedn_bad_server ) return NULL;

	retVal = gtk_editable_get_chars( GTK_EDITABLE(ldapedit_basedn.basedn_entry), 0, -1 );
	g_strchomp( retVal ); g_strchug( retVal );
	if( *retVal == '\0' ) {
		g_free( retVal );
		retVal = NULL;
	}
	return retVal;
}
コード例 #17
0
ファイル: zif-utils.c プロジェクト: hughsie/zif
/**
 * zif_load_multiline_key_file: (skip)
 * @filename: The repo file to load
 * @error: A #GError, or %NULL
 *
 * The source.repo files are not standard GKeyFiles as they can contain
 * multiple lines for a key value, e.g.
 *
 * [multiline1]
 * name=Multiline1
 * baseurl=http://download1.fedoraproject.org/
 *	http://download2.fedoraproject.org/
 * enabled=true
 *
 * Return value: A #GKeyFile, or %NULL
 *
 * Since: 0.2.4
 **/
GKeyFile *
zif_load_multiline_key_file (const gchar *filename,
			     GError **error)
{
	gboolean ret;
	gchar *data = NULL;
	gchar **lines = NULL;
	GKeyFile *file = NULL;
	gsize len;
	GString *string = NULL;
	guint i;

	/* load file */
	ret = g_file_get_contents (filename, &data, &len, error);
	if (!ret)
		goto out;

	/* split into lines */
	string = g_string_new ("");
	lines = g_strsplit (data, "\n", -1);
	for (i = 0; lines[i] != NULL; i++) {
		/* if a line starts with whitespace, then append it on
		 * the previous line */
		g_strdelimit (lines[i], "\t", ' ');
		if (lines[i][0] == ' ' && string->len > 0) {
			g_string_set_size (string, string->len - 1);
			g_string_append_printf (string,
						";%s\n",
						g_strchug (lines[i]));
		} else {
			g_string_append_printf (string,
						"%s\n",
						lines[i]);
		}
	}

	/* remove final newline */
	if (string->len > 0)
		g_string_set_size (string, string->len - 1);

	/* load modified lines */
	file = g_key_file_new ();
	ret = g_key_file_load_from_data (file,
					 string->str,
					 -1,
					 G_KEY_FILE_KEEP_COMMENTS,
					 error);
	if (!ret) {
		g_key_file_free (file);
		file = NULL;
		goto out;
	}
out:
	if (string != NULL)
		g_string_free (string, TRUE);
	g_free (data);
	g_strfreev (lines);
	return file;
}
コード例 #18
0
ファイル: g_util.c プロジェクト: EEmmanuel7/quetoo
/*
 * @brief
 */
g_gameplay_t G_GameplayByName(const char *c) {
	g_gameplay_t gameplay = GAME_DEATHMATCH;

	if (!c || *c == '\0')
		return gameplay;

	char *lower = g_ascii_strdown(c, -1);

	if (g_str_has_prefix(g_strchug(lower), "insta")) {
		gameplay = GAME_INSTAGIB;
	} else if (g_str_has_prefix(g_strchug(lower), "arena")) {
		gameplay = GAME_ARENA;
	}

	g_free(lower);
	return gameplay;
}
コード例 #19
0
ファイル: lookuptables.c プロジェクト: Torture/MegaTunix
/*!
 \brief load_table() physically handles loading the table datafrom disk, 
 populating and array and sotring a pointer to that array in the lookuptables
 hashtable referenced by the table_name passed
 \param table_name (gchar *) key to lookuptables hashtable
 \param filename (gchar *) filename to load table data from
 \returns TRUE on success, FALSE on failure
 */
gboolean load_table(gchar *table_name, gchar *filename)
{
	GIOStatus status;
	GIOChannel *iochannel;
	gboolean done = FALSE;
	gchar * str = NULL;
	gchar * tmp = NULL;
	gchar * end = NULL;
	GString *a_line; 
	LookupTable *lookuptable = NULL;
	gint tmparray[2048]; /* bad idea being static!!*/
	gchar ** vector = NULL;
	gint i = 0;

	iochannel = g_io_channel_new_file(filename,"r", NULL);
	status = g_io_channel_seek_position(iochannel,0,G_SEEK_SET,NULL);
	if (status != G_IO_STATUS_NORMAL)
	{
		dbg_func(CRITICAL,g_strdup(__FILE__": load_lookuptables()\n\tError seeking to beginning of the file\n"));
	}
	while (!done)	
	{
		a_line = g_string_new("\0");
		status = g_io_channel_read_line_string(iochannel, a_line, NULL, NULL);
		if (status == G_IO_STATUS_EOF)
			done = TRUE;
		else
		{
		/*	str = g_strchug(g_strdup(a_line->str));*/
			str = g_strchug(a_line->str);
			if (g_str_has_prefix(str,"DB"))
			{
				str+=2; /* move 2 places in	*/
				end = g_strrstr(str,"T");
				tmp = g_strndup(str,end-str);
				tmparray[i]=atoi(tmp);
				g_free(tmp);
				i++;
			}
		}
		g_string_free(a_line,TRUE);
	}
	g_io_channel_shutdown(iochannel,TRUE,NULL);
	g_io_channel_unref(iochannel);

	vector = g_strsplit(filename,PSEP,-1);
	lookuptable = g_new0(LookupTable, 1);
	lookuptable->array = g_memdup(&tmparray,i*sizeof(gint));
	lookuptable->filename = g_strdup(vector[g_strv_length(vector)-1]);
	g_strfreev(vector);
	if (!lookuptables)
		lookuptables = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,dealloc_lookuptable);
	g_hash_table_insert(lookuptables,g_strdup(table_name),lookuptable);
	/*g_hash_table_foreach(lookuptables,dump_lookuptables,NULL);*/

	return TRUE;
}
コード例 #20
0
PurpleCmdRet flist_timeout_cmd(PurpleConversation *convo, const gchar *cmd, gchar **args, gchar **error, void *data) {
    PurpleConnection *pc = purple_conversation_get_gc(convo);
    FListAccount *fla = pc->proto_data;
    gchar **split; guint count;
    const gchar *character, *time, *reason;
    gulong time_parsed; gchar *endptr;
    JsonObject *json;
    FListFlags flags;

    flags = flist_get_flags(fla, NULL, fla->proper_character);
    if(!(flags & (FLIST_FLAG_ADMIN | FLIST_FLAG_GLOBAL_OP))) {
        *error = g_strdup(_("You must be a global operator to timeban."));
        return PURPLE_CMD_STATUS_FAILED;
    }

    split = g_strsplit(args[0], ",", 3);
    count = g_strv_length(split);

    if(count < 3) {
        g_strfreev(split);
        *error = g_strdup(_("You must enter a character, a time, and a reason."));
        return PURPLE_CMD_STATUS_WRONG_ARGS;
    }

    character = split[0];
    time = g_strchug(split[1]);
    reason = g_strchug(split[2]);

    time_parsed = strtoul(time, &endptr, 10);
    if(time_parsed == 0 || endptr != time + strlen(time)) {
        g_strfreev(split);
        *error = g_strdup(_("You must enter a valid length of time."));
        return PURPLE_CMD_STATUS_WRONG_ARGS;
    }
    
    json = json_object_new();
    json_object_set_string_member(json, "character", character);
    json_object_set_string_member(json, "reason", reason);
    json_object_set_int_member(json, "time", time_parsed);
    flist_request(pc, FLIST_GLOBAL_TIMEOUT, json);
    json_object_unref(json);
    g_strfreev(split);
    return PURPLE_CMD_STATUS_OK;
}
コード例 #21
0
ファイル: query_builder.c プロジェクト: jerryjj/midgard-core
/**
 * midgard_query_builder_new():
 * @mgd: #MidgardConnection instance
 * @classname: any #MidgardDBObjectClass derived class' name
 *
 * Returns: new #MidgardQueryBuilder instance or %NULL if target class is not registered in GType system 
 * or it's not #MidgardDBObjectClass class derived one.
 */
MidgardQueryBuilder *midgard_query_builder_new(
        MidgardConnection *mgd, const gchar *classname)
{
        g_assert(mgd != NULL);
        g_assert(classname != NULL);

	GType class_type = g_type_from_name(classname);

	if(!__type_is_valid(class_type)) {

		g_warning("Can not initialize Midgard Query Builder for '%s'. It's not registered GType system class", classname);
		MIDGARD_ERRNO_SET(mgd, MGD_ERR_INVALID_OBJECT);
		return NULL;
	}

        MidgardQueryBuilder *builder = 
		g_object_new(MIDGARD_TYPE_QUERY_BUILDER, NULL);
	
	builder->priv = midgard_query_builder_private_new();

        builder->priv->mgd = mgd;
        builder->priv->type = g_type_from_name(classname);
	builder->priv->include_deleted = FALSE;
        builder->priv->error = 0;	
	
	MidgardDBObjectClass *klass = 
		(MidgardDBObjectClass*) g_type_class_peek(class_type);

	if (klass->dbpriv == NULL) {
		
		g_warning("Given %s class has no storage definitions", g_type_name(class_type));
		g_object_unref(builder);
		return NULL;
	}

	builder->priv->schema = klass->dbpriv->storage_data;
       	
	gchar **tables = g_strsplit(midgard_core_class_get_tables(MIDGARD_DBOBJECT_CLASS(klass)), ",", 0);
	guint i = 0;
	while(tables[i] != NULL) {	
		midgard_core_qb_add_table(builder, 
				(const gchar *)g_strchug(tables[i]));
		i++;
	}
	g_strfreev(tables);

        builder->priv->offset = 0;
        builder->priv->limit = G_MAXUINT;

        if (builder->priv->type && builder->priv->schema) {
                return builder;
        } else {
		g_object_unref(builder);
                return NULL;
        }
}
コード例 #22
0
ファイル: psppire-data-editor.c プロジェクト: RobertDash/pspp
/* Update the data_ref_entry with the reference of the active cell */
static gint
update_data_ref_entry (const PsppireSheet *sheet,
		       gint row, gint col,
		       gint old_row, gint old_col,
		       gpointer data)
{
  PsppireDataEditor *de = data;

  PsppireDataStore *data_store =
    PSPPIRE_DATA_STORE (psppire_sheet_get_model (sheet));

  if (data_store)
    {
      const struct variable *var =
	psppire_dict_get_variable (data_store->dict, col);

      if ( var )
	{
	  gchar *text = g_strdup_printf ("%d: %s", row + FIRST_CASE_NUMBER,
					 var_get_name (var));


	  gtk_entry_set_text (GTK_ENTRY (de->cell_ref_entry), text);

	  g_free (text);
	}
      else
	goto blank_entry;

      if ( var )
	{
	  gchar *text =
	    psppire_data_store_get_string (data_store, row,
					   var_get_dict_index(var));

	  if ( ! text )
	    goto blank_entry;

	  g_strchug (text);

	  gtk_entry_set_text (GTK_ENTRY (de->datum_entry), text);

	  g_free (text);
	}
      else
	goto blank_entry;

    }

  return FALSE;

 blank_entry:
  gtk_entry_set_text (GTK_ENTRY (de->datum_entry), "");

  return FALSE;
}
コード例 #23
0
/**
 * mcm_utils_format_date_time:
 **/
gchar *
mcm_utils_format_date_time (const struct tm *created)
{
	gchar buffer[256];

	/* TRANSLATORS: this is the profile creation date strftime format */
	strftime (buffer, sizeof(buffer), _("%B %e %Y, %I:%M:%S %p"), created);

	return g_strdup (g_strchug (buffer));
}
コード例 #24
0
ファイル: match.c プロジェクト: CardinalSins/hexchat
void find_match_char(char *buffer, char *match, char *result)
{
	char *position;
	g_strchug(buffer);
	if(strstr(buffer, match) == strstr(buffer, buffer))
	{
		position = strpbrk(buffer, delims);
		if (position != NULL)
		{
			position += 1;
			strcpy(result, position);
			position = strstr(result, "\n");
			*(position) = '\0';
			g_strchug(result);
		}
		else
			strcpy(result, "\0");
	}
}
コード例 #25
0
ファイル: importpine.c プロジェクト: SpOOnman/claws
static void imp_pine_ok( GtkWidget *widget, gboolean *cancelled ) {
	gchar *sName;
	gchar *sFile;
	gchar *sMsg = NULL;
	gboolean errFlag = FALSE;

	sFile = gtk_editable_get_chars( GTK_EDITABLE(imppine_dlg.file_entry), 0, -1 );
	g_strchug( sFile ); g_strchomp( sFile );
	gtk_entry_set_text( GTK_ENTRY(imppine_dlg.file_entry), sFile );

	sName = gtk_editable_get_chars( GTK_EDITABLE(imppine_dlg.name_entry), 0, -1 );
	g_strchug( sName ); g_strchomp( sName );
	gtk_entry_set_text( GTK_ENTRY(imppine_dlg.name_entry), sName );

	if( *sFile == '\0'|| strlen( sFile ) < 1 ) {
		sMsg = _( "Please select a file." );
		errFlag = TRUE;
	}

	if( *sName == '\0'|| strlen( sName ) < 1 ) {
		if( ! errFlag ) sMsg = _( "Address book name must be supplied." );
		errFlag = TRUE;
	}

	if( errFlag ) {
		imp_pine_status_show( sMsg );
	}
	else {
		/* Import the file */
		if( imp_pine_import_file( sName, sFile ) ) {
			*cancelled = FALSE;
			gtk_main_quit();
		}
		else {
			imp_pine_status_show( _( "Error importing Pine file." ) );
		}
	}

	g_free( sFile );
	g_free( sName );

}
コード例 #26
0
static gboolean
parse_key_data (gchar *line, SeahorseSSHKeyData *data)
{
    gchar* space;
    guchar *bytes;
    gboolean ret;
    gsize len;
    
    /* Get the type */
    space = strchr (line, ' ');
    if (space == NULL)
        return FALSE;
    *space = '\0';
    data->algo = parse_algo (line);
    *space = ' ';
    if (data->algo == SSH_ALGO_UNK)
        return FALSE;
    
    line = space + 1;
    if (!*line)
        return FALSE;
    
    /* Prepare for decoding */
    g_strchug (line);
    space = strchr (line, ' ');
    if (space)
        *space = 0;
    g_strchomp (line);
        
    /* Decode it, and parse binary stuff */
    bytes = g_base64_decode (line, &len);
    ret = parse_key_blob (bytes, len, data);
    g_free (bytes);
    
    if (!ret)
        return FALSE;
    
    /* The number of bits */
    data->length = calc_bits (data->algo, len);
    
    /* And the rest is the comment */
    if (space) {
        *space = ' ';
        ++space;
        
        /* If not utf8 valid, assume latin 1 */
        if (!g_utf8_validate (space, -1, NULL))
            data->comment = g_convert (space, -1, "UTF-8", "ISO-8859-1", NULL, NULL, NULL);
        else
            data->comment = g_strdup (space);
    }
    
    return TRUE;
}
コード例 #27
0
ファイル: address-book-ldif.c プロジェクト: GNOME/balsa
static gchar*
value_spec_to_string(gchar* str)
{
    gchar *res;
    if(str[0] == ':') {
        gsize out_len;

        res = (gchar *) g_base64_decode(g_strchug(str + 1), &out_len);
    } else
	res = g_strdup(g_strstrip(str));
    return res;
}
コード例 #28
0
ファイル: expldifdlg.c プロジェクト: SpOOnman/claws
/**
 * Test whether we can move off distinguished name page.
 * \return <i>TRUE</i> if OK to move off page.
 */
static gboolean exp_ldif_move_dn( void ) {
	gboolean retVal = FALSE;
	gboolean errFlag = FALSE;
	gchar *suffix;
	gint id;

	/* Set suffix */
	suffix = gtk_editable_get_chars( GTK_EDITABLE(expldif_dlg.entrySuffix), 0, -1 );
	g_strchug( suffix ); g_strchomp( suffix );

	/* Set RDN format */
	id = combobox_get_active_data(GTK_COMBO_BOX(expldif_dlg.optmenuRDN));
	exportldif_set_rdn( _exportCtl_, id );

	exportldif_set_suffix( _exportCtl_, suffix );
	exportldif_set_use_dn( _exportCtl_,
		gtk_toggle_button_get_active(
			GTK_TOGGLE_BUTTON( expldif_dlg.checkUseDN ) ) );
	exportldif_set_exclude_email( _exportCtl_,
		gtk_toggle_button_get_active(
			GTK_TOGGLE_BUTTON( expldif_dlg.checkEMail ) ) );

	if( *suffix == '\0' || strlen( suffix ) < 1 ) {
		AlertValue aval;

		aval = alertpanel(
			_( "Suffix was not supplied" ),
			_(
				"A suffix is required if data is to be used " \
				"for an LDAP server. Are you sure you wish " \
				"to proceed without a suffix?"
			 ),
			GTK_STOCK_NO, GTK_STOCK_YES, NULL );
		if( aval != G_ALERTALTERNATE ) {
			gtk_widget_grab_focus( expldif_dlg.entrySuffix );
			errFlag = TRUE;
		}
	}

	if( ! errFlag ) {
		/* Process export */
		exportldif_process( _exportCtl_, _addressCache_ );
		if( _exportCtl_->retVal == MGU_SUCCESS ) {
			retVal = TRUE;
		}
		else {
			export_ldif_status_show( _( "Error creating LDIF file" ) );
		}
	}

	return retVal;
}
コード例 #29
0
ファイル: helper.c プロジェクト: RobertDash/pspp
/* Formats a value according to VAR's print format and strips white space
   appropriately for VAR's type.  That is, if VAR is numeric, strips leading
   white space (because numbers are right-justified within their fields), and
   if VAR is string, strips trailing white space (because spaces pad out string
   values on the right).

   Returns an allocated string.  The returned string must be freed when no
   longer required. */
gchar *
value_to_text (union value v, const struct variable *var)
{
  gchar *s;

  s = data_out (&v, var_get_encoding (var), var_get_print_format (var));
  if (var_is_numeric (var))
    g_strchug (s);
  else
    g_strchomp (s);

  return s;
}
コード例 #30
0
ファイル: mgutils.c プロジェクト: moreorless/claws-mail
/*
* Test and reformat an email address.
* Enter:  address.
* Return: Address, or NULL if address is empty.
* Note: Leading and trailing white space is removed.
*/
gchar *mgu_email_check_empty( gchar *address ) {
	gchar *retVal = NULL;
	if( address ) {
		retVal = g_strdup( address );
		retVal = g_strchug( retVal );
		retVal = g_strchomp( retVal );
		if( *retVal == '\0' ) {
			g_free( retVal );
			retVal = NULL;
		}
	}
	return retVal;
}