Permalink
Browse files

Add a option whether enable proxy.

  • Loading branch information...
1 parent 60a50b4 commit 46b859d0cf72f3cc5b9832108cdc53378800942e @mathslinux mathslinux committed Dec 21, 2011
Showing with 62 additions and 40 deletions.
  1. +4 −0 configure.ac
  2. +10 −1 src/gui/loginpanel.c
  3. +4 −1 src/gui/loginpanel.h
  4. +44 −38 src/libqq/url.c
View
4 configure.ac
@@ -49,6 +49,10 @@ AC_ARG_ENABLE(debug,
AC_ARG_ENABLE(unity,
[ --enable-unity build on ubuntu unity],
CFLAGS="$CFLAGS -DUSE_UNITY")
+
+AC_ARG_ENABLE(proxy,
+ [ --enable-proxy build on ubuntu unity],
+ CFLAGS="$CFLAGS -DUSE_PROXY")
#AC_ARG_ENABLE(libnotify,
# AS_HELP_STRING([--enable-libnotify],
View
11 src/gui/loginpanel.c
@@ -8,7 +8,9 @@
#include <msgloop.h>
#include <msgdispacher.h>
#include <string.h>
+#ifdef USE_PROXY
#include <proxypanel.h>
+#endif /* USE_PROXY */
/*
* The global value
* in main.c
@@ -427,11 +429,13 @@ static void qq_loginpanel_init(QQLoginPanel *obj)
usr = (GQQLoginUser*)g_ptr_array_index(login_users, 0);
qq_statusbutton_set_status_string(obj -> status_comb, usr -> status);
}
+#ifdef USE_PROXY
//proxy setting
obj -> set_proxy_btn = gtk_button_new_with_label("Network");
gtk_widget_set_size_request(obj -> set_proxy_btn, 100, -1);
g_signal_connect(G_OBJECT(obj -> set_proxy_btn), "clicked"
, G_CALLBACK(set_proxy_btn_cb), (gpointer)obj);
+#endif /* USE_PROXY */
GtkWidget *hbox1 = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(hbox1), vbox, TRUE, FALSE, 0);
@@ -442,9 +446,12 @@ static void qq_loginpanel_init(QQLoginPanel *obj)
gtk_box_pack_start(GTK_BOX(hbox2), obj -> login_btn, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(hbox3), hbox2, TRUE, FALSE, 0);
+#ifdef USE_PROXY
GtkWidget *hbox_proxy_setting = gtk_hbutton_box_new();
gtk_button_box_set_layout(GTK_BUTTON_BOX(hbox_proxy_setting), GTK_BUTTONBOX_CENTER);
gtk_box_pack_start(GTK_BOX(hbox_proxy_setting), obj -> set_proxy_btn, FALSE, FALSE, 0);
+#endif /* USE_PROXY */
+
//error informatin label
obj -> err_label = gtk_label_new("");
GdkColor color;
@@ -459,8 +466,10 @@ static void qq_loginpanel_init(QQLoginPanel *obj)
gtk_box_pack_start(GTK_BOX(vbox), hbox2, TRUE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(vbox), hbox3, FALSE, FALSE, 0);
-
+
+#ifdef USE_PROXY
gtk_box_pack_start(GTK_BOX(vbox), hbox_proxy_setting, TRUE, TRUE, 10);
+#endif /* USE_PROXY */
gtk_box_set_homogeneous(GTK_BOX(obj), FALSE);
GtkWidget *logo = gtk_image_new_from_file(IMGDIR"webqq_icon.png");
View
5 src/gui/loginpanel.h
@@ -37,7 +37,10 @@ struct _QQLoginPanel{
GtkWidget *passwd_label, *passwd_entry;
GtkWidget *rempwcb; //rember password check button
GtkWidget *err_label; //show error infomation.
- GtkWidget *login_btn, *status_comb, *set_proxy_btn;
+ GtkWidget *login_btn, *status_comb;
+#ifdef USE_PROXY
+ GtkWidget *set_proxy_btn;
+#endif /* USE_PROXY */
const gchar *uin, *passwd, *status;
gint rempw;
View
82 src/libqq/url.c
@@ -10,7 +10,10 @@
#include <glib/gprintf.h>
#include <zlib.h>
+
+#ifdef USE_PROXY
#include <qqproxy.h>
+#endif
Connection* connection_new()
{
@@ -30,51 +33,54 @@ void connection_free(Connection *con)
Connection* connect_to_host(const char *hostname, int port)
{
- /* if(NULL == hostname){ */
- /* return NULL; */
- /* } */
- /* int sockfd = -1, err; */
- /* struct addrinfo *ailist = NULL, *aip = NULL; */
- /* struct addrinfo hint; */
+#ifdef USE_PROXY
+ int sockfd = get_authenticated_socket(hostname, port);
+#else
+ if(NULL == hostname){
+ return NULL;
+ }
+ int sockfd = -1, err;
+ struct addrinfo *ailist = NULL, *aip = NULL;
+ struct addrinfo hint;
- /* memset(&hint, 0, sizeof(hint)); */
- /* hint.ai_socktype = SOCK_STREAM; */
+ memset(&hint, 0, sizeof(hint));
+ hint.ai_socktype = SOCK_STREAM;
- /* if((err = getaddrinfo(hostname, NULL, &hint, &ailist)) != 0){ */
- /* g_warning("Can't get the address information of %s (%s, %d)" */
- /* ,hostname , __FILE__, __LINE__); */
- /* return NULL; */
- /* } */
+ if((err = getaddrinfo(hostname, NULL, &hint, &ailist)) != 0){
+ g_warning("Can't get the address information of %s (%s, %d)"
+ ,hostname , __FILE__, __LINE__);
+ return NULL;
+ }
- /* struct sockaddr_in *sinp; */
+ struct sockaddr_in *sinp;
- /* for(aip = ailist; aip != NULL; aip = aip -> ai_next){ */
+ for(aip = ailist; aip != NULL; aip = aip -> ai_next){
- /* if((sockfd =socket(aip -> ai_family, SOCK_STREAM, 0)) < 0){ */
- /* g_warning("Can't create a socket.(%s, %d)" */
- /* , __FILE__, __LINE__); */
- /* return NULL; */
- /* } */
+ if((sockfd =socket(aip -> ai_family, SOCK_STREAM, 0)) < 0){
+ g_warning("Can't create a socket.(%s, %d)"
+ , __FILE__, __LINE__);
+ return NULL;
+ }
- /* sinp = (struct sockaddr_in *)aip -> ai_addr; */
- /* /\* */
- /* * the http protocol uses port 80 */
- /* *\/ */
- /* sinp -> sin_port = htons((gint16)port); */
+ sinp = (struct sockaddr_in *)aip -> ai_addr;
+ /*
+ * the http protocol uses port 80
+ */
+ sinp -> sin_port = htons((gint16)port);
- /* if(connect(sockfd,aip -> ai_addr, aip -> ai_addrlen) < 0){ */
- /* close(sockfd); */
- /* sockfd = -1; */
- /* g_warning("Can't connect to the server.(%s, %d)" */
- /* , __FILE__, __LINE__); */
- /* continue; */
- /* } */
- /* //connect to the host success. */
- /* break; */
- /* } */
- /* freeaddrinfo(ailist); */
-
- int sockfd = get_authenticated_socket(hostname, port);
+ if(connect(sockfd,aip -> ai_addr, aip -> ai_addrlen) < 0){
+ close(sockfd);
+ sockfd = -1;
+ g_warning("Can't connect to the server.(%s, %d)"
+ , __FILE__, __LINE__);
+ continue;
+ }
+ //connect to the host success.
+ break;
+ }
+ freeaddrinfo(ailist);
+#endif /* USE_PROXY */
+
Connection *con = connection_new();
con -> fd = sockfd;

0 comments on commit 46b859d

Please sign in to comment.