Frameworks/libpurple.framework/Versions/0.6.2/Headers/dnsquery.h
author Zachary West <zacw@adium.im>
Fri Aug 21 13:25:11 2009 -0700 (2009-08-21)
changeset 2592 e8d15275025e
parent 1739 Frameworks/libpurple.framework/Versions/0.6.0/Headers/dnsquery.h@8b0daad9656c
permissions -rw-r--r--
im.pidgin.adium.1-4 at 267c6165e02e34318a1823960bd04c0639952f73
Evan@653
     1
/**
Evan@653
     2
 * @file dnsquery.h DNS query API
Evan@653
     3
 * @ingroup core
Evan@653
     4
 */
Evan@653
     5
Evan@653
     6
/* purple
Evan@653
     7
 *
Evan@653
     8
 * Purple is the legal property of its developers, whose names are too numerous
Evan@653
     9
 * to list here.  Please refer to the COPYRIGHT file distributed with this
Evan@653
    10
 * source distribution.
Evan@653
    11
 *
Evan@653
    12
 * This program is free software; you can redistribute it and/or modify
Evan@653
    13
 * it under the terms of the GNU General Public License as published by
Evan@653
    14
 * the Free Software Foundation; either version 2 of the License, or
Evan@653
    15
 * (at your option) any later version.
Evan@653
    16
 *
Evan@653
    17
 * This program is distributed in the hope that it will be useful,
Evan@653
    18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Evan@653
    19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Evan@653
    20
 * GNU General Public License for more details.
Evan@653
    21
 *
Evan@653
    22
 * You should have received a copy of the GNU General Public License
Evan@653
    23
 * along with this program; if not, write to the Free Software
Evan@653
    24
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
Evan@653
    25
 */
Evan@653
    26
#ifndef _PURPLE_DNSQUERY_H_
Evan@653
    27
#define _PURPLE_DNSQUERY_H_
Evan@653
    28
Evan@653
    29
#include <glib.h>
Evan@653
    30
#include "eventloop.h"
Evan@653
    31
#include "account.h"
Evan@653
    32
Evan@653
    33
typedef struct _PurpleDnsQueryData PurpleDnsQueryData;
Evan@653
    34
Evan@653
    35
/**
Evan@653
    36
 * The "hosts" parameter is a linked list containing pairs of
Evan@653
    37
 * one size_t addrlen and one struct sockaddr *addr.  It should
Evan@653
    38
 * be free'd by the callback function.
Evan@653
    39
 */
Evan@653
    40
typedef void (*PurpleDnsQueryConnectFunction)(GSList *hosts, gpointer data, const char *error_message);
Evan@653
    41
Evan@653
    42
/**
Evan@653
    43
 * Callbacks used by the UI if it handles resolving DNS
Evan@653
    44
 */
Evan@653
    45
typedef void  (*PurpleDnsQueryResolvedCallback) (PurpleDnsQueryData *query_data, GSList *hosts);
Evan@653
    46
typedef void  (*PurpleDnsQueryFailedCallback) (PurpleDnsQueryData *query_data, const gchar *error_message);
Evan@653
    47
Evan@653
    48
/**
Evan@653
    49
 * DNS Request UI operations;  UIs should implement this if they want to do DNS
Evan@653
    50
 * lookups themselves, rather than relying on the core.
Evan@653
    51
 *
Evan@653
    52
 * @see @ref ui-ops
Evan@653
    53
 */
Evan@653
    54
typedef struct
Evan@653
    55
{
Evan@653
    56
	/** If implemented, the UI is responsible for DNS queries */
Evan@653
    57
	gboolean (*resolve_host)(PurpleDnsQueryData *query_data,
Evan@653
    58
	                         PurpleDnsQueryResolvedCallback resolved_cb,
Evan@653
    59
	                         PurpleDnsQueryFailedCallback failed_cb);
Evan@653
    60
Evan@653
    61
	/** Called just before @a query_data is freed; this should cancel any
Evan@653
    62
	 *  further use of @a query_data the UI would make. Unneeded if
Evan@653
    63
	 *  #resolve_host is not implemented.
Evan@653
    64
	 */
Evan@653
    65
	void (*destroy)(PurpleDnsQueryData *query_data);
Evan@653
    66
Evan@653
    67
	void (*_purple_reserved1)(void);
Evan@653
    68
	void (*_purple_reserved2)(void);
Evan@653
    69
	void (*_purple_reserved3)(void);
Evan@653
    70
	void (*_purple_reserved4)(void);
Evan@653
    71
} PurpleDnsQueryUiOps;
Evan@653
    72
Evan@653
    73
#ifdef __cplusplus
Evan@653
    74
extern "C" {
Evan@653
    75
#endif
Evan@653
    76
Evan@653
    77
/**************************************************************************/
Evan@653
    78
/** @name DNS query API                                                   */
Evan@653
    79
/**************************************************************************/
Evan@653
    80
/*@{*/
Evan@653
    81
Evan@653
    82
/**
Evan@653
    83
 * Perform an asynchronous DNS query.
Evan@653
    84
 *
Evan@653
    85
 * @param hostname The hostname to resolve.
Evan@653
    86
 * @param port     A port number which is stored in the struct sockaddr.
Evan@653
    87
 * @param callback The callback function to call after resolving.
Evan@653
    88
 * @param data     Extra data to pass to the callback function.
Evan@653
    89
 *
Evan@653
    90
 * @return NULL if there was an error, otherwise return a reference to
Evan@653
    91
 *         a data structure that can be used to cancel the pending
Evan@653
    92
 *         DNS query, if needed.
Evan@653
    93
 */
Evan@653
    94
PurpleDnsQueryData *purple_dnsquery_a(const char *hostname, int port, PurpleDnsQueryConnectFunction callback, gpointer data);
Evan@653
    95
Evan@653
    96
/**
Evan@653
    97
 * Cancel a DNS query and destroy the associated data structure.
Evan@653
    98
 *
Evan@653
    99
 * @param query_data The DNS query to cancel.  This data structure
Evan@653
   100
 *        is freed by this function.
Evan@653
   101
 */
Evan@653
   102
void purple_dnsquery_destroy(PurpleDnsQueryData *query_data);
Evan@653
   103
Evan@653
   104
/**
Evan@653
   105
 * Sets the UI operations structure to be used when doing a DNS
Evan@653
   106
 * resolve.  The UI operations need only be set if the UI wants to
Evan@653
   107
 * handle the resolve itself; otherwise, leave it as NULL.
Evan@653
   108
 *
Evan@653
   109
 * @param ops The UI operations structure.
Evan@653
   110
 */
Evan@653
   111
void purple_dnsquery_set_ui_ops(PurpleDnsQueryUiOps *ops);
Evan@653
   112
Evan@653
   113
/**
Evan@653
   114
 * Returns the UI operations structure to be used when doing a DNS
Evan@653
   115
 * resolve.
Evan@653
   116
 *
Evan@653
   117
 * @return The UI operations structure.
Evan@653
   118
 */
Evan@653
   119
PurpleDnsQueryUiOps *purple_dnsquery_get_ui_ops(void);
Evan@653
   120
Evan@653
   121
/**
Evan@653
   122
 * Get the host associated with a PurpleDnsQueryData
Evan@653
   123
 *
Evan@653
   124
 * @param query_data The DNS query
Evan@653
   125
 * @return The host.
Evan@653
   126
 */
Evan@653
   127
char *purple_dnsquery_get_host(PurpleDnsQueryData *query_data);
Evan@653
   128
Evan@653
   129
/**
Evan@653
   130
 * Get the port associated with a PurpleDnsQueryData
Evan@653
   131
 *
Evan@653
   132
 * @param query_data The DNS query
Evan@653
   133
 * @return The port.
Evan@653
   134
 */
Evan@653
   135
unsigned short purple_dnsquery_get_port(PurpleDnsQueryData *query_data);
Evan@653
   136
Evan@653
   137
/**
Evan@653
   138
 * Initializes the DNS query subsystem.
Evan@653
   139
 */
Evan@653
   140
void purple_dnsquery_init(void);
Evan@653
   141
Evan@653
   142
/**
Evan@653
   143
 * Uninitializes the DNS query subsystem.
Evan@653
   144
 */
Evan@653
   145
void purple_dnsquery_uninit(void);
Evan@653
   146
Evan@653
   147
/*@}*/
Evan@653
   148
Evan@653
   149
#ifdef __cplusplus
Evan@653
   150
}
Evan@653
   151
#endif
Evan@653
   152
Evan@653
   153
#endif /* _PURPLE_DNSQUERY_H_ */