Refactor: GAtPPP connect callback

The connect callback was not giving enough information and the
information it was providing was not in a convenient form.

- Provide the ppp interface name (e.g. tun0)
- Provide ip, dns1 & dns2 as strings
- Do not send the ppp structure in the callback, it is most likely
  present in the user data anyway
This commit is contained in:
Denis Kenzior 2010-03-31 18:45:17 -05:00
parent 4d44103cce
commit d6093b819f
3 changed files with 34 additions and 13 deletions

View File

@ -49,10 +49,13 @@ void g_at_ppp_set_credentials(GAtPPP *ppp, const char *username,
auth_set_credentials(ppp->auth, username, passwd);
}
void g_at_ppp_set_connect_function(GAtPPP *ppp,
GAtPPPConnectFunc callback, gpointer user_data)
void g_at_ppp_set_connect_function(GAtPPP *ppp, GAtPPPConnectFunc func,
gpointer user_data)
{
ppp->connect_cb = callback;
if (func == NULL)
return;
ppp->connect_cb = func;
ppp->connect_data = user_data;
}

View File

@ -34,9 +34,9 @@ typedef enum _GAtPPPConnectStatus {
G_AT_PPP_CONNECT_FAIL
} GAtPPPConnectStatus;
typedef void (*GAtPPPConnectFunc)(GAtPPP *ppp, GAtPPPConnectStatus success,
guint32 ip_address,
guint32 dns1, guint32 dns2,
typedef void (*GAtPPPConnectFunc)(GAtPPPConnectStatus success,
const char *iface, const char *ip,
const char *dns1, const char *dns2,
gpointer user_data);
typedef void (*GAtPPPDisconnectFunc)(GAtPPP *ppp, gpointer user_data);

View File

@ -222,14 +222,32 @@ static void ipcp_up(struct pppcp_data *pppcp)
{
struct ipcp_data *data = pppcp->priv;
GAtPPP *ppp = pppcp->ppp;
char ip[INET_ADDRSTRLEN];
char dns1[INET_ADDRSTRLEN];
char dns2[INET_ADDRSTRLEN];
struct in_addr addr;
/* call the connect function */
if (ppp->connect_cb)
ppp->connect_cb(ppp, G_AT_PPP_CONNECT_SUCCESS,
__get_unaligned_long(data->ip_address),
__get_unaligned_long(data->primary_dns),
__get_unaligned_long(data->secondary_dns),
ppp->connect_data);
if (ppp->connect_cb == NULL)
return;
memset(ip, 0, sizeof(ip));
addr.s_addr = __get_unaligned_long(data->ip_address);
inet_ntop(AF_INET, &addr, ip, INET_ADDRSTRLEN);
memset(dns1, 0, sizeof(dns1));
addr.s_addr = __get_unaligned_long(data->primary_dns);
inet_ntop(AF_INET, &addr, dns1, INET_ADDRSTRLEN);
memset(dns2, 0, sizeof(dns2));
addr.s_addr = __get_unaligned_long(data->secondary_dns);
inet_ntop(AF_INET, &addr, dns2, INET_ADDRSTRLEN);
ppp->connect_cb(G_AT_PPP_CONNECT_SUCCESS,
pppcp->ppp->net->if_name,
ip[0] ? ip : NULL,
dns1[0] ? dns1 : NULL,
dns2[0] ? dns2 : NULL,
ppp->connect_data);
}
static void ipcp_down(struct pppcp_data *data)