]> sjero.net Git - linphone/blob - gtk/update.c
Aac-eld add missing header according to RFC3640 3.3.6
[linphone] / gtk / update.c
1 /*\r
2 linphone, gtk-glade interface.\r
3 Copyright (C) 2008  Simon MORLAT (simon.morlat@linphone.org)\r
4 \r
5 This program is free software; you can redistribute it and/or\r
6 modify it under the terms of the GNU General Public License\r
7 as published by the Free Software Foundation; either version 2\r
8 of the License, or (at your option) any later version.\r
9 \r
10 This program is distributed in the hope that it will be useful,\r
11 but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 GNU General Public License for more details.\r
14 \r
15 You should have received a copy of the GNU General Public License\r
16 along with this program; if not, write to the Free Software\r
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
18 */\r
19 \r
20 #include "linphone.h"\r
21 \r
22 #ifdef WIN32\r
23 \r
24 #include <wininet.h>\r
25 \r
26 static int linphone_gtk_get_new_version(const char *version_url, char *version, size_t size){\r
27         DWORD dwDownloaded = 0;\r
28         HINTERNET  hSession = NULL, hConnect = NULL;\r
29         int ret=-1;\r
30         \r
31         hSession=InternetOpen("Linphone",INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);\r
32         \r
33         if (hSession==NULL) return -1;\r
34         \r
35         hConnect=InternetOpenUrl(hSession,version_url,NULL,0,0,0);\r
36         \r
37         if (hConnect==NULL) {\r
38                 InternetCloseHandle(hSession);\r
39                 return -1;\r
40         }\r
41         dwDownloaded=0;\r
42         if (InternetReadFile(hConnect,version,size,&dwDownloaded) && dwDownloaded>0){\r
43                 version[dwDownloaded]='\0';\r
44                 ms_message("Got response: %s", version);\r
45                 /*check this not just html containing 404 not found*/\r
46                 if (strstr(version,"html")==0)\r
47                         ret=0;\r
48         }\r
49         \r
50         // Close any open handles.\r
51         if (hConnect) InternetCloseHandle(hConnect);\r
52         if (hSession) InternetCloseHandle(hSession);\r
53         return ret;\r
54 }\r
55 \r
56 #else\r
57 \r
58 static int linphone_gtk_get_new_version(const char *url, char *version, size_t size){\r
59         \r
60         return -1;\r
61 }\r
62 \r
63 #endif\r
64 \r
65 static void new_version_response(GtkWidget *dialog, int response_id, gpointer download_site){\r
66         if (response_id==GTK_RESPONSE_YES){\r
67                 linphone_gtk_open_browser((const char*)download_site);\r
68         }\r
69         gtk_widget_destroy(dialog);\r
70 }\r
71 \r
72 static gboolean popup_new_version(const char *download_site){\r
73         GtkWidget *dialog;\r
74         /* draw a question box. link to dialog_click callback */\r
75         dialog = gtk_message_dialog_new (\r
76                                 GTK_WINDOW(linphone_gtk_get_main_window()),\r
77                 GTK_DIALOG_DESTROY_WITH_PARENT,\r
78                                 GTK_MESSAGE_QUESTION,\r
79                 GTK_BUTTONS_YES_NO,\r
80                 _("A more recent version is availalble from %s.\nWould you like to open a browser to download it ?"),\r
81                                 download_site);\r
82         g_signal_connect(G_OBJECT (dialog), "response",\r
83             G_CALLBACK (new_version_response),\r
84                 (gpointer)download_site);\r
85         /* actually show the box */\r
86         gtk_widget_show(dialog);\r
87         return FALSE;\r
88 }\r
89 \r
90 static gboolean popup_version_ok(){\r
91         linphone_gtk_display_something(GTK_MESSAGE_INFO,_("You are running the lastest version."));\r
92         return FALSE;\r
93 }\r
94 \r
95 static int copytilldot(char *n, const char *v){\r
96         int ret=0;\r
97         while(*v!='\0' && *v!='.' && *v!='-' && *v!='\n' && *v!='\r' && *v!='\t'){\r
98                 *n=*v;\r
99                 ret++;\r
100                 v++;\r
101                 n++;\r
102         }\r
103         *n='\0';\r
104         if (*v!='\0') ret=ret+1;\r
105         return ret;\r
106 }\r
107 \r
108 static int version_compare(const char *v1, const char *v2){\r
109         char n1[16];\r
110         char n2[16];\r
111         int ret;\r
112         if (*v1=='\0' && *v2=='\0') return 0;\r
113         v1+=copytilldot(n1,v1);\r
114         v2+=copytilldot(n2,v2);\r
115         ms_message("Comparing %s <> %s",n1,n2);\r
116         ret=strcmp(n1,n2);\r
117         if (ret==0) return version_compare(v1,v2);\r
118         else return ret;\r
119 }\r
120 \r
121 static void *check_for_new_version(void *d){\r
122         const char *version_url=(const char *)d;\r
123         char version[256];\r
124         if (linphone_gtk_get_new_version(version_url,version,sizeof(version))==0){\r
125                 if (version_compare(version,LINPHONE_VERSION)>0){\r
126                         const char *download_site=linphone_gtk_get_ui_config("download_site",NULL);\r
127                         if (download_site)   {\r
128                                 gdk_threads_enter();\r
129                                 g_idle_add((GSourceFunc)popup_new_version,(gpointer)download_site);\r
130                                 gdk_threads_leave();\r
131                         }\r
132                 }else{\r
133                         if (linphone_gtk_get_ui_config_int("update_check_menu",0)){\r
134                                 gdk_threads_enter();\r
135                                 g_idle_add((GSourceFunc)popup_version_ok,NULL);\r
136                                 gdk_threads_leave();\r
137                         }\r
138                 }\r
139         }\r
140         return NULL;\r
141 }\r
142 \r
143 void linphone_gtk_check_for_new_version(void){\r
144         ortp_thread_t thread;\r
145         static gboolean done=FALSE;\r
146         const char *version_url;\r
147         if (done) return;\r
148         done=TRUE;\r
149         version_url=linphone_gtk_get_ui_config("last_version_url",NULL);\r
150         if (version_url==NULL) return ;\r
151         ortp_thread_create(&thread,NULL,check_for_new_version,(void*)version_url);\r
152 }\r
153 \r
154 /*called when the user clicks on the "Check for updates" menu item */\r
155 void linphone_gtk_check_for_updates(void){\r
156         linphone_gtk_check_for_new_version();\r
157 }\r