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); auth_set_credentials(ppp->auth, username, passwd);
} }
void g_at_ppp_set_connect_function(GAtPPP *ppp, void g_at_ppp_set_connect_function(GAtPPP *ppp, GAtPPPConnectFunc func,
GAtPPPConnectFunc callback, gpointer user_data) gpointer user_data)
{ {
ppp->connect_cb = callback; if (func == NULL)
return;
ppp->connect_cb = func;
ppp->connect_data = user_data; ppp->connect_data = user_data;
} }

View File

@ -34,9 +34,9 @@ typedef enum _GAtPPPConnectStatus {
G_AT_PPP_CONNECT_FAIL G_AT_PPP_CONNECT_FAIL
} GAtPPPConnectStatus; } GAtPPPConnectStatus;
typedef void (*GAtPPPConnectFunc)(GAtPPP *ppp, GAtPPPConnectStatus success, typedef void (*GAtPPPConnectFunc)(GAtPPPConnectStatus success,
guint32 ip_address, const char *iface, const char *ip,
guint32 dns1, guint32 dns2, const char *dns1, const char *dns2,
gpointer user_data); gpointer user_data);
typedef void (*GAtPPPDisconnectFunc)(GAtPPP *ppp, 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; struct ipcp_data *data = pppcp->priv;
GAtPPP *ppp = pppcp->ppp; 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 == NULL)
if (ppp->connect_cb) return;
ppp->connect_cb(ppp, G_AT_PPP_CONNECT_SUCCESS,
__get_unaligned_long(data->ip_address), memset(ip, 0, sizeof(ip));
__get_unaligned_long(data->primary_dns), addr.s_addr = __get_unaligned_long(data->ip_address);
__get_unaligned_long(data->secondary_dns), inet_ntop(AF_INET, &addr, ip, INET_ADDRSTRLEN);
ppp->connect_data);
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) static void ipcp_down(struct pppcp_data *data)