changeset 6268:084e1f6610a8

[gaim-migrate @ 6765] Changed the name of one of the new IP functions, and added a couple more to wrap around prefs and such. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Tue, 22 Jul 2003 08:12:08 +0000
parents 36b80ce02a51
children 0a902bd3e170
files src/ft.c src/ft.h
diffstat 2 files changed, 71 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/ft.c	Tue Jul 22 08:11:44 2003 +0000
+++ b/src/ft.c	Tue Jul 22 08:12:08 2003 +0000
@@ -31,7 +31,6 @@
 GaimXfer *
 gaim_xfer_new(GaimAccount *account, GaimXferType type, const char *who)
 {
-	const char *ip;
 	GaimXfer *xfer;
 	GaimXferUiOps *ui_ops;
 
@@ -46,13 +45,7 @@
 	xfer->who     = g_strdup(who);
 	xfer->ui_ops  = gaim_get_xfer_ui_ops();
 
-	if ((ip = gaim_account_get_public_ip(account)) != NULL)
-		ip = gaim_prefs_get_string("/core/ft/public_ip");
-
-	if (ip != NULL && *ip != '\0')
-		xfer->local_ip = g_strdup(ip);
-	else
-		xfer->local_ip = gaim_xfers_get_local_ip();
+	xfer->local_ip = gaim_xfers_get_ip_for_account(account);
 
 	ui_ops = gaim_xfer_get_ui_ops(xfer);
 
@@ -709,8 +702,29 @@
 /**************************************************************************
  * File Transfer Subsystem API
  **************************************************************************/
+void
+gaim_xfers_set_local_ip(const char *ip)
+{
+	g_return_if_fail(ip != NULL);
+
+	gaim_prefs_set_string("/core/ft/public_ip", ip);
+}
+
+const char *
+gaim_xfers_get_local_ip(void)
+{
+	const char *ip;
+
+	ip = gaim_prefs_get_string("/core/ft/public_ip");
+
+	if (ip == NULL || *ip == '\0')
+		return NULL;
+
+	return ip;
+}
+
 char *
-gaim_xfers_get_local_ip(void)
+gaim_xfers_get_local_system_ip(void)
 {
 	struct hostent *host;
 	char localhost[129];
@@ -731,6 +745,19 @@
 	return g_strdup(ip);
 }
 
+char *
+gaim_xfers_get_ip_for_account(const GaimAccount *account)
+{
+	g_return_val_if_fail(account != NULL, NULL);
+
+	if (gaim_account_get_public_ip(account) != NULL)
+		return g_strdup(gaim_account_get_public_ip(account));
+	else if (gaim_xfers_get_local_ip() != NULL)
+		return g_strdup(gaim_xfers_get_local_ip());
+	else
+		return gaim_xfers_get_local_system_ip();
+}
+
 void
 gaim_xfers_init(void)
 {
--- a/src/ft.h	Tue Jul 22 08:11:44 2003 +0000
+++ b/src/ft.h	Tue Jul 22 08:12:08 2003 +0000
@@ -470,6 +470,20 @@
 /*@{*/
 
 /**
+ * Sets the IP address of the local system in preferences.
+ *
+ * @param ip The local IP address.
+ */
+void gaim_xfers_set_local_ip(const char *ip);
+
+/**
+ * Returns the IP address of the local system set in preferences.
+ *
+ * @return The local IP address set in preferences.
+ */
+const char *gaim_xfers_get_local_ip(void);
+
+/**
  * Returns the IP address of the local system.
  *
  * @note The returned IP address must be g_free()'d when no longer
@@ -477,7 +491,27 @@
  *
  * @return The local IP address.
  */
-char *gaim_xfers_get_local_ip(void);
+char *gaim_xfers_get_local_system__ip(void);
+
+/**
+ * Returns the IP address that should be used for the specified account.
+ *
+ * First, the IP associated with @a account is tried, via a call to
+ * gaim_account_get_local_ip().
+ *
+ * If that IP is not set, the IP set in preferences is tried.
+ *
+ * If that IP is not set, the system's local IP is tried, via a call to
+ * gaim_xfers_get_local_ip().
+ *
+ * @note The returned IP address must be g_free()'d when no longer
+ *       in use.
+ *
+ * @param account The account the IP is going to be used with.
+ *
+ * @return The local IP address to be used.
+ */
+char *gaim_xfers_get_ip_for_account(const GaimAccount *account);
 
 /**
  * Initializes the file transfer subsystem.