From 5772ad5d8b736f9a8639ad3c68beae059f04eb31 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 3 Apr 2010 22:25:09 -0700 Subject: [PATCH] Make GAtPPP fields really private --- gatchat/gatppp.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ gatchat/ppp.h | 34 +++------------------------------- gatchat/ppp_cp.c | 22 +++++++--------------- gatchat/ppp_ipcp.c | 14 ++++---------- 4 files changed, 64 insertions(+), 56 deletions(-) diff --git a/gatchat/gatppp.c b/gatchat/gatppp.c index b5e9d3e..bf28aae 100644 --- a/gatchat/gatppp.c +++ b/gatchat/gatppp.c @@ -38,6 +38,56 @@ #include "gatppp.h" #include "ppp.h" +#define BUFFERSZ DEFAULT_MRU*2 + +struct _GAtPPP { + gint ref_count; + enum ppp_phase phase; + struct pppcp_data *lcp; + struct auth_data *auth; + struct pppcp_data *ipcp; + struct ppp_net_data *net; + guint8 buffer[BUFFERSZ]; + int index; + gint mru; + guint16 auth_proto; + char user_name[256]; + char passwd[256]; + gboolean pfc; + gboolean acfc; + guint32 xmit_accm[8]; + guint32 recv_accm; + GIOChannel *modem; + GAtPPPConnectFunc connect_cb; + gpointer connect_data; + GAtDisconnectFunc disconnect_cb; + gpointer disconnect_data; + gint read_watch; + gint write_watch; + GAtDebugFunc debugf; + gpointer debug_data; + int record_fd; + GQueue *xmit_queue; +}; + +void ppp_debug(GAtPPP *ppp, const char *str) +{ + if (!ppp || !ppp->debugf) + return; + + ppp->debugf(str, ppp->debug_data); +} + +void ppp_connect_cb(GAtPPP *ppp, GAtPPPConnectStatus success, + const char *ip, const char *dns1, const char *dns2) +{ + if (ppp->connect_cb == NULL) + return; + + ppp->connect_cb(success, ppp->net->if_name, + ip, dns1, dns2, ppp->connect_data); +} + #define PPPINITFCS16 0xffff /* Initial FCS value */ #define PPPGOODFCS16 0xf0b8 /* Good final FCS value */ diff --git a/gatchat/ppp.h b/gatchat/ppp.h index 7b09fa9..90e22ce 100644 --- a/gatchat/ppp.h +++ b/gatchat/ppp.h @@ -22,7 +22,6 @@ #include "ppp_cp.h" #define DEFAULT_MRU 1500 -#define BUFFERSZ DEFAULT_MRU*2 #define DEFAULT_ACCM 0x00000000 #define PPP_ESC 0x7d #define PPP_FLAG_SEQ 0x7e @@ -108,36 +107,7 @@ struct ppp_net_data { gint watch; }; -struct _GAtPPP { - gint ref_count; - enum ppp_phase phase; - struct pppcp_data *lcp; - struct auth_data *auth; - struct pppcp_data *ipcp; - struct ppp_net_data *net; - guint8 buffer[BUFFERSZ]; - int index; - gint mru; - guint16 auth_proto; - char user_name[256]; - char passwd[256]; - gboolean pfc; - gboolean acfc; - guint32 xmit_accm[8]; - guint32 recv_accm; - GIOChannel *modem; - GAtPPPConnectFunc connect_cb; - gpointer connect_data; - GAtDisconnectFunc disconnect_cb; - gpointer disconnect_data; - gint read_watch; - gint write_watch; - GAtDebugFunc debugf; - gpointer debug_data; - int record_fd; - GQueue *xmit_queue; -}; - +void ppp_debug(GAtPPP *ppp, const char *str); void ppp_generate_event(GAtPPP *ppp, enum ppp_event event); void ppp_transmit(GAtPPP *ppp, guint8 *packet, guint infolen); void ppp_set_auth(GAtPPP *ppp, guint8 *auth_data); @@ -166,3 +136,5 @@ void ppp_net_close(struct ppp_net_data *data); void ppp_net_free(struct ppp_net_data *data); struct pppcp_data *ipcp_new(GAtPPP *ppp); void ipcp_free(struct pppcp_data *data); +void ppp_connect_cb(GAtPPP *ppp, GAtPPPConnectStatus success, + const char *ip, const char *dns1, const char *dns2); diff --git a/gatchat/ppp_cp.c b/gatchat/ppp_cp.c index cf2f5fa..46c62c1 100644 --- a/gatchat/ppp_cp.c +++ b/gatchat/ppp_cp.c @@ -38,21 +38,13 @@ static const char *pppcp_state_strings[] = {"INITIAL", "STARTING", "CLOSED", "STOPPED", "CLOSING", "STOPPING", "REQSENT", "ACKRCVD", "ACKSENT", "OPENED" }; -static void pppcp_debug(struct pppcp_data *p, const char *func) -{ - GAtPPP *ppp = p->ppp; - char *str; - - if (!ppp || !ppp->debugf) - return; - - str = g_strdup_printf("%s: %s: current state %d:%s", - p->prefix, func, p->state, pppcp_state_strings[p->state]); - ppp->debugf(str, ppp->debug_data); - g_free(str); -} - -#define pppcp_trace(p) pppcp_debug(p, __FUNCTION__) +#define pppcp_trace(p) do { \ + char *str = g_strdup_printf("%s: %s: current state %d:%s", \ + p->prefix, __FUNCTION__, \ + p->state, pppcp_state_strings[p->state]); \ + ppp_debug(p->ppp, str); \ + g_free(str); \ +} while (0); #define pppcp_to_ppp_packet(p) \ (((guint8 *) p) - PPP_HEADROOM) diff --git a/gatchat/ppp_ipcp.c b/gatchat/ppp_ipcp.c index a7ce2a5..6b1566f 100644 --- a/gatchat/ppp_ipcp.c +++ b/gatchat/ppp_ipcp.c @@ -66,15 +66,11 @@ enum ipcp_option_types { 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; - 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); @@ -87,12 +83,10 @@ static void ipcp_up(struct pppcp_data *pppcp) 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); + ppp_connect_cb(pppcp->ppp, G_AT_PPP_CONNECT_SUCCESS, + ip[0] ? ip : NULL, + dns1[0] ? dns1 : NULL, + dns2[0] ? dns2 : NULL); } static void ipcp_down(struct pppcp_data *data) -- 2.7.4