changeset 14051:f78289db8977

[gaim-migrate @ 16664] Removed code for looking up specific Chinese geolocation info from a user's IP address. The code was defunct for two reasons: First, the file holding the geolocation data (QQWry.dat) was simply too large to package with Gaim. Second, the current version of QQ seems to have stopped broadcasting the user's IP address with his/her status. committer: Tailor Script <tailor@pidgin.im>
author Mark Huetsch <markhuetsch>
date Mon, 07 Aug 2006 08:30:36 +0000
parents 6342ffdeb3ac
children d178bff33359
files src/protocols/qq/Makefile.am src/protocols/qq/Makefile.mingw src/protocols/qq/ip_location.c src/protocols/qq/ip_location.h src/protocols/qq/qq.c
diffstat 5 files changed, 2 insertions(+), 361 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/qq/Makefile.am	Mon Aug 07 07:39:00 2006 +0000
+++ b/src/protocols/qq/Makefile.am	Mon Aug 07 08:30:36 2006 +0000
@@ -50,8 +50,6 @@
 	header_info.h \
 	im.c \
 	im.h \
-	ip_location.c \
-	ip_location.h \
 	keep_alive.c \
 	keep_alive.h \
 	login_logout.c \
--- a/src/protocols/qq/Makefile.mingw	Mon Aug 07 07:39:00 2006 +0000
+++ b/src/protocols/qq/Makefile.mingw	Mon Aug 07 08:30:36 2006 +0000
@@ -95,7 +95,6 @@
 	group_search.c \
 	header_info.c \
 	im.c \
-	ip_location.c \
 	keep_alive.c \
 	login_logout.c \
 	packet_parse.c \
--- a/src/protocols/qq/ip_location.c	Mon Aug 07 07:39:00 2006 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,240 +0,0 @@
-/**
- * The QQ2003C protocol plugin
- *
- * for gaim
- *
- * Copyright (C) 2004 Puzzlebird
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * This code is based on
- *  * qqwry.c, by lvxiang <srm2003@163.com>
- *  * IpChecker.m, by Jeff_Ye
- */
-
-#include "internal.h"
-#include <string.h>
-#include "debug.h"
-#include "prefs.h"
-
-#include "utils.h"
-#include "ip_location.h"
-
-#define DEFAULT_IP_LOCATION_FILE  "gaim/QQWry.dat"
-
-typedef struct _ip_finder ip_finder;
-
-/* all offset is based the begining of the file */
-struct _ip_finder {
-	guint32 offset_first_start_ip;	/* first abs offset of start ip */
-	guint32 offset_last_start_ip;	/* last abs offset of start ip */
-	guint32 cur_start_ip;		/* start ip of current search range */
-	guint32 cur_end_ip;		/* end ip of current search range */
-	guint32 offset_cur_end_ip;	/* where is the current end ip saved */
-	GIOChannel *io;			/* IO Channel to read file */
-};					/* struct _ip_finder */
-
-/* convert 1-4 bytes array to integer.
- * Small endian (higher bytes in lower place) */
-static guint32 _byte_array_to_int(guint8 *ip, gint count)
-{
-	guint32 ret, i;
-	g_return_val_if_fail(count >= 1 && count <= 4, 0);
-	ret = ip[0];
-	for (i = 0; i < count; i++)
-		ret |= ((guint32) ip[i]) << (8 * i);
-	return ret;
-}
-
-/* read len of bytes to buf, from io at offset */
-static void _read_from(GIOChannel *io, guint32 offset, guint8 *buf, gint len)
-{
-	GError *err;
-	GIOStatus status;
-
-	err = NULL;
-	status = g_io_channel_seek_position(io, offset, G_SEEK_SET, &err);
-	if (err != NULL) {
-		gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Fail seek file @offset[%d]: %s", offset, err->message);
-		g_error_free(err);
-		memset(buf, 0, len);
-		return;
-	}
-
-	status = g_io_channel_read_chars(io, buf, len, NULL, &err);
-	if (err != NULL) {
-		gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Fail read %d bytes from file: %s", len, err->message);
-		g_error_free(err);
-		memset(buf, 0, len);
-		return;
-	}
-}
-
-/* read len of bytes to buf, from io at offset */
-static gsize _read_line_from(GIOChannel *io, guint32 offset, gchar **ret_str)
-{
-	gsize bytes_read;
-	GError *err;
-	GIOStatus status;
-
-	err = NULL;
-	status = g_io_channel_seek_position(io, offset, G_SEEK_SET, &err);
-	if (err != NULL) {
-		gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Fail seek file @offset[%d]: %s", offset, err->message);
-		g_error_free(err);
-		ret_str = NULL;
-		return -1;
-	}
-
-	status = g_io_channel_read_line(io, ret_str, &bytes_read, NULL, &err);
-	if (err != NULL) {
-		gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Fail read from file: %s", err->message);
-		g_error_free(err);
-		ret_str = NULL;
-		return -1;
-	}
-
-	return bytes_read;
-}
-
-/* read the string from io, at offset, it may jump several times
- * returns the offset of next readable string for area */
-static guint32 _get_string(GIOChannel *io, guint32 offset, gchar **ret)
-{
-	guint8 *buf;
-	g_return_val_if_fail(io != NULL, 0);
-
-	buf = g_new0(guint8, 3);
-	_read_from(io, offset, buf, 1);
-
-	switch (buf[0]) {	/* fixed by bluestar11 at gmail dot com, 04/12/20 */
-	case 0x01:		/* jump together */
-	  _read_from(io, offset + 1, buf, 3);
-	  return _get_string(io, _byte_array_to_int(buf, 3), ret);
-	case 0x02:		/* jump separately */
-	   _read_from(io, offset + 1, buf, 3);
-	  _get_string(io, _byte_array_to_int(buf, 3), ret);
-	  return offset + 4;
-	default:
-	  _read_line_from(io, offset, ret);
-	  return offset + strlen(*ret) + 1;
-	}
-}
-
-/* extract country and area starting from offset */
-static void _get_country_city(GIOChannel *io, guint32 offset, gchar **country, gchar **area)
-{
-	guint32 next_offset;
-	g_return_if_fail(io != NULL);
-
-	next_offset = _get_string(io, offset, country);
-	if (next_offset == 0)
-		*area = g_strdup("");
-	else
-		_get_string(io, next_offset, area);
-}
-
-/* set start_ip and end_ip of current range */
-static void _set_ip_range(gint rec_no, ip_finder *f)
-{
-	guint8 *buf;
-	guint32 offset;
-
-	g_return_if_fail(f != NULL);
-
-	buf = g_newa(guint8, 7);
-	offset = f->offset_first_start_ip + rec_no * 7;
-
-	_read_from(f->io, offset, buf, 7);
-	f->cur_start_ip = _byte_array_to_int(buf, 4);
-	f->offset_cur_end_ip = _byte_array_to_int(buf + 4, 3);
-
-	_read_from(f->io, f->offset_cur_end_ip, buf, 4);
-	f->cur_end_ip = _byte_array_to_int(buf, 4);
-}
-
-/* set the country and area for given IP.
- * country and area needs to be freed later */
-gboolean qq_ip_get_location(guint32 ip, gchar **country, gchar **area)
-{
-	gint rec, record_count, B, E;
-	guint8 *buf;
-	gchar *addr_file;
-	ip_finder *f;
-	GError *err;
-	const char *ip_fn;
-
-	if (ip == 0)
-		return FALSE;
-
-	f = g_new0(ip_finder, 1);
-	err = NULL;
-	ip_fn = gaim_prefs_get_string("/plugins/prpl/qq/ipfile");
-	if (ip_fn == NULL || strlen(ip_fn) == 0 || strncmp(ip_fn, "(null)", strlen("(null)")) == 0) {
-		addr_file = g_build_filename(DATADIR, DEFAULT_IP_LOCATION_FILE, NULL);
-	} else {
-		addr_file = g_build_filename(ip_fn, NULL);
-	}
-
-	f->io = g_io_channel_new_file(addr_file, "r", &err);
-	g_free(addr_file);
-	if (err != NULL) {
-		gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Unable to open (%s): %s\n", addr_file, err->message);
-		g_error_free(err);
-		return FALSE;
-	} else {
-		g_io_channel_set_encoding(f->io, NULL, NULL);	/* set binary */
-	}
-
-	buf = g_newa(guint8, 4);
-
-	_read_from(f->io, 0, buf, 4);
-	f->offset_first_start_ip = _byte_array_to_int(buf, 4);
-	_read_from(f->io, 4, buf, 4);
-	f->offset_last_start_ip = _byte_array_to_int(buf, 4);
-
-	record_count = (f->offset_last_start_ip - f->offset_first_start_ip) / 7;
-	if (record_count <= 1) {
-		gaim_debug(GAIM_DEBUG_ERROR, "QQ", "File data error, no records found\n");
-		g_io_channel_shutdown(f->io, FALSE, NULL);
-		return FALSE;;
-	}
-	/* search for right range */
-	B = 0;
-	E = record_count;
-	while (B < E - 1) {
-		rec = (B + E) / 2;
-		_set_ip_range(rec, f);
-		if (ip == f->cur_start_ip) {
-			B = rec;
-			break;
-		}
-		if (ip > f->cur_start_ip)
-			B = rec;
-		else
-			E = rec;
-	}
-	_set_ip_range(B, f);
-
-	if (f->cur_start_ip <= ip && ip <= f->cur_end_ip) {
-		_get_country_city(f->io, f->offset_cur_end_ip + 4, country, area);
-	} else {		/* not in this range... miss */
-		*country = g_strdup("unkown");
-		*area = g_strdup(" ");
-	}			/* if ip_start<=ip<=ip_end */
-
-	g_io_channel_shutdown(f->io, FALSE, NULL);
-	return TRUE;
-}
--- a/src/protocols/qq/ip_location.h	Mon Aug 07 07:39:00 2006 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-/**
- * The QQ2003C protocol plugin
- *
- * for gaim
- *
- * Copyright (C) 2004 Puzzlebird
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-#ifndef _QQ_IP_LOCATION_H_
-#define _QQ_IP_LOCATION_H_
-
-#include "glib.h"
-
-gboolean qq_ip_get_location(guint32 ip, gchar **country, gchar **city);
-
-#endif
--- a/src/protocols/qq/qq.c	Mon Aug 07 07:39:00 2006 +0000
+++ b/src/protocols/qq/qq.c	Mon Aug 07 08:30:36 2006 +0000
@@ -48,7 +48,6 @@
 #include "group_opt.h"
 #include "header_info.h"
 #include "im.h"
-#include "ip_location.h"
 #include "keep_alive.h"
 #include "login_logout.h"
 #include "packet_parse.h"
@@ -245,21 +244,10 @@
 
 	if (GAIM_BUDDY_IS_ONLINE(b) && q_bud != NULL)
 	{
-		/*
-		ip_value = ntohl(*(guint32 *) (q_bud->ip));
-		if (qq_ip_get_location(ip_value, &country, &city)) {
-			country_utf8 = qq_to_utf8(country, QQ_CHARSET_DEFAULT);
-			city_utf8 = qq_to_utf8(city, QQ_CHARSET_DEFAULT);
-			g_string_append_printf(tooltip, "\n%s, %s", country_utf8, city_utf8);
-			g_free(country);
-			g_free(city);
-			g_free(country_utf8);
-			g_free(city_utf8);
-		}
-		*/
 		ip_str = gen_ip_str(q_bud->ip);
 		if (strlen(ip_str) != 0) {
-			g_string_append_printf(tooltip, "\n<b>%s Address:</b> %s:%d", (q_bud->comm_flag & QQ_COMM_FLAG_TCP_MODE)
+			g_string_append_printf(tooltip, "\n<b>%s Address:</b> %s:%d", 
+					(q_bud->comm_flag & QQ_COMM_FLAG_TCP_MODE)
 				       ? "TCP" : "UDP", ip_str, q_bud->port);
 		}
 		g_free(ip_str);
@@ -519,74 +507,6 @@
 	g_string_free(info, TRUE);
 }
 
-/*
-static void _qq_menu_locate_ip_cb(GaimConnection * gc, GaimRequestFields * fields)
-{
-        GList *groups, *flds;
-        GaimRequestField *field;
-        const gchar *id, *value;
-        gchar *ip_str = NULL, *ip_dupstr = NULL;
-	guint8 *ip;
-        gchar *country, *country_utf8, *city, *city_utf8;
-        guint32 ip_value;
-
-        for (groups = gaim_request_fields_get_groups(fields); groups && !ip_str; groups = groups->next) {
-                for (flds = gaim_request_field_group_get_fields(groups->data); flds && !ip_str; flds = flds->next) {
-                        field = flds->data;
-                        id = gaim_request_field_get_id(field);
-                        value = gaim_request_field_string_get_value(field);
-
-                        if (!g_ascii_strcasecmp(id, "ip")) {
-                                ip_str = g_strdup(value);
-				break;
-			}
-                }
-        }
-	
-	if(ip_str) {
-		ip = str_ip_gen(ip_str);
-		ip_dupstr = gen_ip_str(ip);
-        
-		ip_value = ntohl(*(guint32 *)ip);
-        	if (qq_ip_get_location(ip_value, &country, &city)) {
-                        country_utf8 = qq_to_utf8(country, QQ_CHARSET_DEFAULT);
-                        city_utf8 = qq_to_utf8(city, QQ_CHARSET_DEFAULT);
-			gaim_notify_info(gc, ip_dupstr, country_utf8, city_utf8);
-                        g_free(country);
-                        g_free(city);
-                        g_free(country_utf8);
-                        g_free(city_utf8);
-        	}
-		else 
-			gaim_notify_info(gc, ip_dupstr, "IP not found", NULL);
-		g_free(ip);
-		g_free(ip_dupstr);
-		g_free(ip_str);
-	}
-}
-
-static void _qq_menu_locate_ip(GaimPluginAction *action)
-{
-        GaimConnection *gc = (GaimConnection *) action->context;
-        GaimRequestField *field;
-        GaimRequestFields *fields;
-        GaimRequestFieldGroup *group;
-
-        g_return_if_fail(gc != NULL);
-
-        fields = gaim_request_fields_new();
-        group = gaim_request_field_group_new(NULL);
-        gaim_request_fields_add_group(fields, group);
-        
-	field = gaim_request_field_string_new("ip", _("IP Address"), NULL, FALSE);
-        gaim_request_field_group_add_field(group, field);
-        
-	gaim_request_fields(gc, _("Locate an IP"),
-			_("Locate an IP address"), NULL, fields,
-			 _("Check"), G_CALLBACK(_qq_menu_locate_ip_cb), _("Cancel"), NULL, gc);
-}
-*/
-
 static void _qq_menu_search_or_add_permanent_group(GaimPluginAction * action)
 {
 	gaim_gtk_roomlist_dialog_show();
@@ -847,11 +767,6 @@
 	m = g_list_append(m, act);
 	*/
 
-	/* XXX consider re-enabling this
-	act = gaim_plugin_action_new(_("Locate an IP"), _qq_menu_locate_ip);
-        m = g_list_append(m, act);
-	*/
-	
 	return m;
 }
 
@@ -1066,7 +981,6 @@
 	my_protocol = plugin;
 
 	gaim_prefs_add_none("/plugins/prpl/qq");
-	gaim_prefs_add_string("/plugins/prpl/qq/ipfile", "");
 	gaim_prefs_add_bool("/plugins/prpl/qq/show_status_by_icon", TRUE);
 	gaim_prefs_add_bool("/plugins/prpl/qq/show_fake_video", FALSE);
 	gaim_prefs_add_string("/plugins/prpl/qq/datadir", DATADIR);