diff options
| -rw-r--r-- | lib/misc.c | 16 | ||||
| -rw-r--r-- | lib/misc.h | 1 | ||||
| -rw-r--r-- | protocols/twitter/twitter.c | 21 | 
3 files changed, 19 insertions, 19 deletions
@@ -750,3 +750,19 @@ int truncate_utf8(char *string, int maxlen)  	*end = '\0';  	return end - string;  } + +/* Parses a guint64 from string, returns TRUE on success */ +gboolean parse_int64(char *string, int base, guint64 *number) +{ +	guint64 parsed; +	char *endptr; + +	errno = 0; +	parsed = g_ascii_strtoull(string, &endptr, base); +	if (errno || endptr == string || *endptr != '\0') { +		return FALSE; +	} +	*number = parsed; +	return TRUE; +} + @@ -148,5 +148,6 @@ G_MODULE_EXPORT int md5_verify_password(char *password, char *hash);  G_MODULE_EXPORT char **split_command_parts(char *command, int limit);  G_MODULE_EXPORT char *get_rfc822_header(const char *text, const char *header, int len);  G_MODULE_EXPORT int truncate_utf8(char *string, int maxlen); +G_MODULE_EXPORT gboolean parse_int64(char *string, int base, guint64 *number);  #endif diff --git a/protocols/twitter/twitter.c b/protocols/twitter/twitter.c index 4debc08a..7f5e0368 100644 --- a/protocols/twitter/twitter.c +++ b/protocols/twitter/twitter.c @@ -858,23 +858,6 @@ static void twitter_buddy_data_free(struct bee_user *bu)  	g_free(bu->data);  } -/* Parses a decimal or hex tweet ID, returns TRUE on success */ -static gboolean twitter_parse_id(char *string, int base, guint64 *id) -{ -	guint64 parsed; -	char *endptr; - -	errno = 0; -	parsed = g_ascii_strtoull(string, &endptr, base); -	if (errno || endptr == string || *endptr != '\0') { -		return FALSE; -	} -	*id = parsed; -	return TRUE; -} - -bee_user_t twitter_log_local_user; -  /** Convert the given bitlbee tweet ID, bitlbee username, or twitter tweet ID   *  into a twitter tweet ID.   * @@ -902,10 +885,10 @@ static guint64 twitter_message_id_from_command_arg(struct im_connection *ic, cha  		if (arg[0] == '#') {  			arg++;  		} -		if (twitter_parse_id(arg, 16, &id) && id < TWITTER_LOG_LENGTH) { +		if (parse_int64(arg, 16, &id) && id < TWITTER_LOG_LENGTH) {  			bu = td->log[id].bu;  			id = td->log[id].id; -		} else if (twitter_parse_id(arg, 10, &id)) { +		} else if (parse_int64(arg, 10, &id)) {  			/* Allow normal tweet IDs as well; not a very useful  			   feature but it's always been there. Just ignore  			   very low IDs to avoid accidents. */  | 
