5 #include <sys/socket.h>
8 #include "download-provider-ipc.h"
9 #include "download-provider-log.h"
11 int ipc_receive_header(int fd)
16 download_controls msgheader = 0;
17 if (read(fd, &msgheader, sizeof(download_controls)) < 0) {
18 TRACE_DEBUG_MSG("failed to read message header (%s)",
25 int ipc_send_stateinfo(download_clientinfo *clientinfo)
27 if (!clientinfo || clientinfo->clientfd <= 0)
30 download_state_info stateinfo;
31 download_controls type = DOWNLOAD_CONTROL_GET_STATE_INFO;
32 memset(&stateinfo, 0x00, sizeof(download_state_info));
33 stateinfo.state = clientinfo->state;
34 stateinfo.err = clientinfo->err;
37 if (send(clientinfo->clientfd, &type, sizeof(download_controls), 0) < 0) {
38 TRACE_DEBUG_MSG("failed to send message header (%s)",
42 if (send(clientinfo->clientfd, &stateinfo, sizeof(download_state_info), 0) < 0) {
43 TRACE_DEBUG_MSG("failed to send message header (%s)",
50 int ipc_send_request_stateinfo(download_clientinfo *clientinfo)
52 if (!clientinfo || clientinfo->clientfd <= 0)
55 download_request_state_info requeststateinfo;
56 download_controls type = DOWNLOAD_CONTROL_GET_REQUEST_STATE_INFO;
57 memset(&requeststateinfo, 0x00, sizeof(download_request_state_info));
58 requeststateinfo.stateinfo.state = clientinfo->state;
59 requeststateinfo.stateinfo.err = clientinfo->err;
60 if (clientinfo->requestinfo)
61 requeststateinfo.requestid = clientinfo->requestinfo->requestid;
64 if (send(clientinfo->clientfd, &type, sizeof(download_controls), 0) < 0) {
65 TRACE_DEBUG_MSG("failed to send message header (%s)",
70 (clientinfo->clientfd, &requeststateinfo, sizeof(download_request_state_info),
72 TRACE_DEBUG_MSG("failed to send message header (%s)",
79 int ipc_send_downloadinfo(download_clientinfo *clientinfo)
81 if (!clientinfo || clientinfo->clientfd <= 0
82 || !clientinfo->downloadinfo)
85 download_controls type = DOWNLOAD_CONTROL_GET_DOWNLOAD_INFO;
87 if (send(clientinfo->clientfd, &type, sizeof(download_controls), 0) < 0) {
88 TRACE_DEBUG_MSG("failed to send message header (%s)",
93 (clientinfo->clientfd, clientinfo->downloadinfo,
94 sizeof(download_content_info), 0) < 0) {
95 TRACE_DEBUG_MSG("failed to send message header (%s)",
102 int ipc_send_downloadinginfo(download_clientinfo *clientinfo)
104 if (!clientinfo || clientinfo->clientfd <= 0
105 || !clientinfo->downloadinginfo)
108 download_controls type = DOWNLOAD_CONTROL_GET_DOWNLOADING_INFO;
110 if (send(clientinfo->clientfd, &type, sizeof(download_controls), 0) < 0) {
111 TRACE_DEBUG_MSG("failed to send message header (%s)",
116 (clientinfo->clientfd, clientinfo->downloadinginfo,
117 sizeof(downloading_state_info), 0) < 0) {
118 TRACE_DEBUG_MSG("failed to send message header (%s)",
125 int ipc_receive_request_msg(download_clientinfo *clientinfo)
127 if (!clientinfo || clientinfo->clientfd <= 0)
130 if (!clientinfo->requestinfo)
131 clientinfo->requestinfo =
132 (download_request_info *) calloc(1, sizeof(download_request_info));
134 if (!clientinfo->requestinfo)
137 // read reqeust structure
139 (clientinfo->clientfd, clientinfo->requestinfo,
140 sizeof(download_request_info)) < 0) {
141 TRACE_DEBUG_MSG("failed to read message header");
144 if (clientinfo->requestinfo->client_packagename.length > 0) {
145 clientinfo->requestinfo->client_packagename.str =
147 calloc((clientinfo->requestinfo->client_packagename.length +
150 (clientinfo->clientfd,
151 clientinfo->requestinfo->client_packagename.str,
152 clientinfo->requestinfo->client_packagename.length *
155 ("failed to read message header client_app_id(%s)",
159 clientinfo->requestinfo->client_packagename.str[clientinfo->
163 TRACE_DEBUG_MSG("request client_packagename [%s]",
164 clientinfo->requestinfo->client_packagename.
167 if (clientinfo->requestinfo->url.length > 0) {
168 clientinfo->requestinfo->url.str =
169 (char *)calloc((clientinfo->requestinfo->url.length + 1),
172 (clientinfo->clientfd, clientinfo->requestinfo->url.str,
173 clientinfo->requestinfo->url.length * sizeof(char)) < 0) {
174 TRACE_DEBUG_MSG("failed to read message header url(%s)",
178 clientinfo->requestinfo->url.str[clientinfo->requestinfo->url.
180 TRACE_DEBUG_MSG("request url [%s]",
181 clientinfo->requestinfo->url.str);
183 if (clientinfo->requestinfo->install_path.length > 0) {
184 clientinfo->requestinfo->install_path.str =
186 calloc((clientinfo->requestinfo->install_path.length + 1),
189 (clientinfo->clientfd,
190 clientinfo->requestinfo->install_path.str,
191 clientinfo->requestinfo->install_path.length *
194 ("failed to read message header install_path(%s)",
198 clientinfo->requestinfo->install_path.str[clientinfo->
200 install_path.length] =
202 TRACE_DEBUG_MSG("request install_path [%s]",
203 clientinfo->requestinfo->install_path.str);
205 if (clientinfo->requestinfo->filename.length > 0) {
206 clientinfo->requestinfo->filename.str =
208 calloc((clientinfo->requestinfo->filename.length + 1),
211 (clientinfo->clientfd,
212 clientinfo->requestinfo->filename.str,
213 clientinfo->requestinfo->filename.length * sizeof(char)) <
216 ("failed to read message header filename(%s)",
220 clientinfo->requestinfo->filename.str[clientinfo->requestinfo->
221 filename.length] = '\0';
222 TRACE_DEBUG_MSG("request filename [%s]",
223 clientinfo->requestinfo->filename.str);
225 if (clientinfo->requestinfo->headers.rows) {
226 clientinfo->requestinfo->headers.str =
227 (download_flexible_string *) calloc(clientinfo->requestinfo->headers.
228 rows, sizeof(download_flexible_string));
230 for (i = 0; i < clientinfo->requestinfo->headers.rows; i++) {
232 (clientinfo->clientfd,
233 &clientinfo->requestinfo->headers.str[i],
234 sizeof(download_flexible_string)) < 0) {
236 ("failed to read message header headers(%s)",
240 if (clientinfo->requestinfo->headers.str[i].length > 0) {
241 TRACE_DEBUG_MSG("headers[%d] length[%d]", i,
242 clientinfo->requestinfo->
243 headers.str[i].length);
244 clientinfo->requestinfo->headers.str[i].str =
246 calloc((clientinfo->requestinfo->headers.
247 str[i].length + 1), sizeof(char));
249 (clientinfo->clientfd,
250 clientinfo->requestinfo->headers.str[i].
252 clientinfo->requestinfo->headers.str[i].
253 length * sizeof(char)) < 0) {
255 ("failed to read message header headers(%s)",
259 clientinfo->requestinfo->headers.str[i].
260 str[clientinfo->requestinfo->headers.str[i].
262 TRACE_DEBUG_MSG("headers[%d][%s]", i,
263 clientinfo->requestinfo->