5 #include <sys/socket.h>
8 #include "download-provider-ipc.h"
9 #include "download-provider-log.h"
12 int ipc_receive_header(int fd)
17 download_controls msgheader = 0;
18 if (read(fd, &msgheader, sizeof(download_controls)) < 0) {
19 TRACE_DEBUG_MSG("failed to read message header (%s)",
26 int ipc_send_stateinfo(download_clientinfo *clientinfo)
28 if (!clientinfo || clientinfo->clientfd <= 0)
31 download_state_info stateinfo;
32 download_controls type = DOWNLOAD_CONTROL_GET_STATE_INFO;
33 memset(&stateinfo, 0x00, sizeof(download_state_info));
34 stateinfo.state = clientinfo->state;
35 stateinfo.err = clientinfo->err;
38 if (send(clientinfo->clientfd, &type, sizeof(download_controls), 0) < 0) {
39 TRACE_DEBUG_MSG("failed to send message header (%s)",
43 if (send(clientinfo->clientfd, &stateinfo, sizeof(download_state_info), 0) < 0) {
44 TRACE_DEBUG_MSG("failed to send message header (%s)",
51 int ipc_send_request_stateinfo(download_clientinfo *clientinfo)
53 if (!clientinfo || clientinfo->clientfd <= 0)
56 download_request_state_info requeststateinfo;
57 download_controls type = DOWNLOAD_CONTROL_GET_REQUEST_STATE_INFO;
58 memset(&requeststateinfo, 0x00, sizeof(download_request_state_info));
59 requeststateinfo.stateinfo.state = clientinfo->state;
60 requeststateinfo.stateinfo.err = clientinfo->err;
61 if (clientinfo->requestinfo)
62 requeststateinfo.requestid = clientinfo->requestinfo->requestid;
65 if (send(clientinfo->clientfd, &type, sizeof(download_controls), 0) < 0) {
66 TRACE_DEBUG_MSG("failed to send message header (%s)",
71 (clientinfo->clientfd, &requeststateinfo, sizeof(download_request_state_info),
73 TRACE_DEBUG_MSG("failed to send message header (%s)",
80 int ipc_send_downloadinfo(download_clientinfo *clientinfo)
82 if (!clientinfo || clientinfo->clientfd <= 0
83 || !clientinfo->downloadinfo)
86 download_controls type = DOWNLOAD_CONTROL_GET_DOWNLOAD_INFO;
88 if (send(clientinfo->clientfd, &type, sizeof(download_controls), 0) < 0) {
89 TRACE_DEBUG_MSG("failed to send message header (%s)",
94 (clientinfo->clientfd, clientinfo->downloadinfo,
95 sizeof(download_content_info), 0) < 0) {
96 TRACE_DEBUG_MSG("failed to send message header (%s)",
103 int ipc_send_downloadinginfo(download_clientinfo *clientinfo)
105 if (!clientinfo || clientinfo->clientfd <= 0
106 || !clientinfo->downloadinginfo)
109 download_controls type = DOWNLOAD_CONTROL_GET_DOWNLOADING_INFO;
111 if (send(clientinfo->clientfd, &type, sizeof(download_controls), 0) < 0) {
112 TRACE_DEBUG_MSG("failed to send message header (%s)",
117 (clientinfo->clientfd, clientinfo->downloadinginfo,
118 sizeof(downloading_state_info), 0) < 0) {
119 TRACE_DEBUG_MSG("failed to send message header (%s)",
126 extern int service_import_from_bundle(service_h service, bundle *data);
127 int ipc_receive_request_msg(download_clientinfo *clientinfo)
129 if (!clientinfo || clientinfo->clientfd <= 0)
132 if (!clientinfo->requestinfo)
133 clientinfo->requestinfo =
134 (download_request_info *) calloc(1, sizeof(download_request_info));
136 if (!clientinfo->requestinfo)
139 // read reqeust structure
141 (clientinfo->clientfd, clientinfo->requestinfo,
142 sizeof(download_request_info)) < 0) {
143 TRACE_DEBUG_MSG("failed to read message header");
146 if (clientinfo->requestinfo->client_packagename.length > 1) {
147 clientinfo->requestinfo->client_packagename.str =
149 calloc((clientinfo->requestinfo->client_packagename.length +
152 (clientinfo->clientfd,
153 clientinfo->requestinfo->client_packagename.str,
154 clientinfo->requestinfo->client_packagename.length *
157 ("failed to read message header client_app_id(%s)",
161 clientinfo->requestinfo->client_packagename.str[clientinfo->
165 TRACE_DEBUG_MSG("request client_packagename [%s]",
166 clientinfo->requestinfo->client_packagename.
169 if (clientinfo->requestinfo->url.length > 1) {
170 clientinfo->requestinfo->url.str =
171 (char *)calloc((clientinfo->requestinfo->url.length + 1),
174 (clientinfo->clientfd, clientinfo->requestinfo->url.str,
175 clientinfo->requestinfo->url.length * sizeof(char)) < 0) {
176 TRACE_DEBUG_MSG("failed to read message header url(%s)",
180 clientinfo->requestinfo->url.str[clientinfo->requestinfo->url.
182 TRACE_DEBUG_MSG("request url [%s]",
183 clientinfo->requestinfo->url.str);
185 if (clientinfo->requestinfo->install_path.length > 1) {
186 clientinfo->requestinfo->install_path.str =
188 calloc((clientinfo->requestinfo->install_path.length + 1),
191 (clientinfo->clientfd,
192 clientinfo->requestinfo->install_path.str,
193 clientinfo->requestinfo->install_path.length *
196 ("failed to read message header install_path(%s)",
200 clientinfo->requestinfo->install_path.str[clientinfo->
202 install_path.length] =
204 TRACE_DEBUG_MSG("request install_path [%s]",
205 clientinfo->requestinfo->install_path.str);
207 if (clientinfo->requestinfo->filename.length > 1) {
208 clientinfo->requestinfo->filename.str =
210 calloc((clientinfo->requestinfo->filename.length + 1),
213 (clientinfo->clientfd,
214 clientinfo->requestinfo->filename.str,
215 clientinfo->requestinfo->filename.length * sizeof(char)) <
218 ("failed to read message header filename(%s)",
222 clientinfo->requestinfo->filename.str[clientinfo->requestinfo->
223 filename.length] = '\0';
224 TRACE_DEBUG_MSG("request filename [%s]",
225 clientinfo->requestinfo->filename.str);
227 if (clientinfo->requestinfo->service_data.length > 1) {
228 bundle_raw *raw_data = NULL;
231 service_h service_handle;
232 clientinfo->requestinfo->service_data.str =
234 calloc((clientinfo->requestinfo->service_data.length + 1),
237 (clientinfo->clientfd,
238 clientinfo->requestinfo->service_data.str,
239 clientinfo->requestinfo->service_data.length * sizeof(char)) <
242 ("failed to read message header filename(%s)",
246 clientinfo->requestinfo->service_data.str[clientinfo->requestinfo->
247 service_data.length] = '\0';
248 raw_data = (bundle_raw *)clientinfo->requestinfo->service_data.str;
249 len = clientinfo->requestinfo->service_data.length;
250 if ((b = bundle_decode(raw_data, len)) == NULL) {
251 TRACE_DEBUG_MSG("Failed to decode bundle raw data");
254 if (service_create(&service_handle) < 0) {
255 TRACE_DEBUG_MSG("Failed to create service handle");
259 if (service_import_from_bundle(service_handle, b) < 0) {
260 TRACE_DEBUG_MSG("Failed to import service handle");
262 service_destroy(service_handle);
266 clientinfo->service_handle = service_handle;
268 service_get_package(service_handle, &pkg);
270 TRACE_DEBUG_MSG("operation### [%s]",pkg);
276 if (clientinfo->requestinfo->headers.rows) {
277 clientinfo->requestinfo->headers.str =
278 (download_flexible_string *) calloc(clientinfo->requestinfo->headers.
279 rows, sizeof(download_flexible_string));
281 for (i = 0; i < clientinfo->requestinfo->headers.rows; i++) {
283 (clientinfo->clientfd,
284 &clientinfo->requestinfo->headers.str[i],
285 sizeof(download_flexible_string)) < 0) {
287 ("failed to read message header headers(%s)",
291 if (clientinfo->requestinfo->headers.str[i].length > 1) {
292 TRACE_DEBUG_MSG("headers[%d] length[%d]", i,
293 clientinfo->requestinfo->
294 headers.str[i].length);
295 clientinfo->requestinfo->headers.str[i].str =
297 calloc((clientinfo->requestinfo->headers.
298 str[i].length + 1), sizeof(char));
300 (clientinfo->clientfd,
301 clientinfo->requestinfo->headers.str[i].
303 clientinfo->requestinfo->headers.str[i].
304 length * sizeof(char)) < 0) {
306 ("failed to read message header headers(%s)",
310 clientinfo->requestinfo->headers.str[i].
311 str[clientinfo->requestinfo->headers.str[i].
313 TRACE_DEBUG_MSG("headers[%d][%s]", i,
314 clientinfo->requestinfo->