7 #include <sys/socket.h>
9 #include <net_connection.h>
11 #include "download-provider-config.h"
12 #include "download-provider-notification.h"
13 #include "download-provider-pthread.h"
14 #include "download-provider-log.h"
16 extern fd_set g_download_provider_socket_readset;
17 extern fd_set g_download_provider_socket_exceptset;
19 int get_download_request_id(void)
23 static int last_uniquetime = 0;
26 uniquetime = (int)time(NULL);
27 gettimeofday(&tval, NULL);
28 if (tval.tv_usec == 0)
29 uniquetime = uniquetime + (tval.tv_usec + 1) % 0xfffff;
31 uniquetime = uniquetime + tval.tv_usec;
32 TRACE_DEBUG_INFO_MSG("ID : %d", uniquetime);
33 } while (last_uniquetime == uniquetime);
34 last_uniquetime = uniquetime; // store
38 void clear_socket(download_clientinfo *clientinfo)
42 if (clientinfo->clientfd) {
43 FD_CLR(clientinfo->clientfd, &g_download_provider_socket_readset);
44 FD_CLR(clientinfo->clientfd, &g_download_provider_socket_exceptset);
45 shutdown(clientinfo->clientfd, 0);
46 fdatasync(clientinfo->clientfd);
47 close(clientinfo->clientfd);
48 clientinfo->clientfd = 0;
52 void clear_clientinfo(download_clientinfo *clientinfo)
54 TRACE_DEBUG_INFO_MSG("[TEST] clear [%p]",clientinfo);
59 clear_socket(clientinfo);
61 CLIENT_MUTEX_LOCK(&(clientinfo->client_mutex));
62 if (clientinfo->requestinfo) {
63 clientinfo->requestinfo->requestid = 0;
64 if (clientinfo->requestinfo->client_packagename.length > 0
65 && clientinfo->requestinfo->client_packagename.str)
66 free(clientinfo->requestinfo->client_packagename.str);
67 clientinfo->requestinfo->client_packagename.str = NULL;
68 if (clientinfo->requestinfo->url.str)
69 free(clientinfo->requestinfo->url.str);
70 clientinfo->requestinfo->url.str = NULL;
71 if (clientinfo->requestinfo->install_path.str)
72 free(clientinfo->requestinfo->install_path.str);
73 clientinfo->requestinfo->install_path.str = NULL;
74 if (clientinfo->requestinfo->filename.str)
75 free(clientinfo->requestinfo->filename.str);
76 clientinfo->requestinfo->filename.str = NULL;
77 if (clientinfo->requestinfo->service_data.str)
78 free(clientinfo->requestinfo->service_data.str);
79 clientinfo->requestinfo->service_data.str = NULL;
80 if (clientinfo->requestinfo->headers.rows) {
82 for (i = 0; i < clientinfo->requestinfo->headers.rows;
84 if (clientinfo->requestinfo->headers.str[i].str)
85 free(clientinfo->requestinfo->headers.
87 clientinfo->requestinfo->headers.str[i].str =
90 free(clientinfo->requestinfo->headers.str);
91 clientinfo->requestinfo->headers.str = NULL;
93 free(clientinfo->requestinfo);
94 clientinfo->requestinfo = NULL;
96 if (clientinfo->downloadinginfo)
97 free(clientinfo->downloadinginfo);
98 clientinfo->downloadinginfo = NULL;
99 if (clientinfo->downloadinfo)
100 free(clientinfo->downloadinfo);
101 clientinfo->downloadinfo = NULL;
102 if (clientinfo->tmp_saved_path)
103 free(clientinfo->tmp_saved_path);
104 clientinfo->tmp_saved_path = NULL;
105 if (clientinfo->ui_notification_handle || clientinfo->service_handle)
106 destroy_appfw_notification(clientinfo);
107 CLIENT_MUTEX_UNLOCK(&(clientinfo->client_mutex));
108 CLIENT_MUTEX_DESTROY(&(clientinfo->client_mutex));
109 memset(clientinfo, 0x00, sizeof(download_clientinfo));
114 void clear_clientinfoslot(download_clientinfo_slot *clientinfoslot)
119 download_clientinfo *clientinfo =
120 (download_clientinfo *) clientinfoslot->clientinfo;
121 clear_clientinfo(clientinfo);
122 clientinfoslot->clientinfo = NULL;
125 int get_downloading_count(download_clientinfo_slot *clientinfo_list)
129 for (i = 0; i < MAX_CLIENT; i++) {
130 if (clientinfo_list[i].clientinfo) {
131 if (clientinfo_list[i].clientinfo->state ==
132 DOWNLOAD_STATE_DOWNLOADING
133 || clientinfo_list[i].clientinfo->state ==
134 DOWNLOAD_STATE_INSTALLING
135 || clientinfo_list[i].clientinfo->state ==
136 DOWNLOAD_STATE_READY)
143 int get_same_request_slot_index(download_clientinfo_slot *clientinfo_list,
148 if (!clientinfo_list || !requestid)
151 for (i = 0; i < MAX_CLIENT; i++) {
152 if (clientinfo_list[i].clientinfo
153 && clientinfo_list[i].clientinfo->requestinfo) {
154 if (clientinfo_list[i].clientinfo->requestinfo->
155 requestid == requestid) {
163 int get_empty_slot_index(download_clientinfo_slot *clientinfo_list)
167 if (!clientinfo_list)
170 for (i = 0; i < MAX_CLIENT; i++)
171 if (!clientinfo_list[i].clientinfo)
176 int get_pended_slot_index(download_clientinfo_slot *clientinfo_list)
180 if (!clientinfo_list)
183 for (i = 0; i < MAX_CLIENT; i++)
184 if (clientinfo_list[i].clientinfo
185 && clientinfo_list[i].clientinfo->state
186 == DOWNLOAD_STATE_PENDED)
191 int get_network_status()
193 connection_h network_handle = NULL;
194 if (connection_create(&network_handle) < 0) {
195 TRACE_DEBUG_MSG("Failed connection_create");
199 connection_ethernet_state_e system_network_state
200 = CONNECTION_ETHERNET_STATE_DISCONNECTED;
201 if (connection_get_ethernet_state(network_handle,
202 &system_network_state) != CONNECTION_ERROR_NONE)
203 TRACE_DEBUG_MSG("Failed connection_get_ethernet_state");
205 ("ethernet check result : [%d]", (int)system_network_state);
207 connection_cellular_state_e system_cellular_state
208 = CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE;
209 if (connection_get_cellular_state(network_handle,
210 &system_cellular_state) != CONNECTION_ERROR_NONE)
211 TRACE_DEBUG_MSG("Failed connection_get_ethernet_state");
213 ("cellula check result : [%d]", (int)system_cellular_state);
215 connection_wifi_state_e system_wifi_state
216 = CONNECTION_WIFI_STATE_DEACTIVATED;
217 if (connection_get_wifi_state(network_handle,
218 &system_wifi_state) != CONNECTION_ERROR_NONE)
219 TRACE_DEBUG_MSG("Failed connection_get_ethernet_state");
221 ("wifi check result : [%d]", (int)system_wifi_state);
223 if (connection_destroy(network_handle) != CONNECTION_ERROR_NONE)
224 TRACE_DEBUG_MSG("Failed connection_destroy");
226 if (!(system_network_state == CONNECTION_ETHERNET_STATE_CONNECTED
227 || system_cellular_state == CONNECTION_CELLULAR_STATE_AVAILABLE
228 || system_wifi_state == CONNECTION_WIFI_STATE_CONNECTED))