File: server_request.h

package info (click to toggle)
mstflint 4.11.0%2B1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 33,620 kB
  • sloc: ansic: 159,630; cpp: 47,995; sh: 11,303; python: 2,488; makefile: 682
file content (118 lines) | stat: -rw-r--r-- 4,041 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118

/*
 * Copyright (C) Jan 2006 Mellanox Technologies Ltd. All rights reserved.
 *
 * This software is available to you under a choice of one of two
 * licenses.  You may choose to be licensed under the terms of the GNU
 * General Public License (GPL) Version 2, available from the file
 * COPYING in the main directory of this source tree, or the
 * OpenIB.org BSD license below:
 *
 *     Redistribution and use in source and binary forms, with or
 *     without modification, are permitted provided that the following
 *     conditions are met:
 *
 *      - Redistributions of source code must retain the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer.
 *
 *      - Redistributions in binary form must reproduce the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer in the documentation and/or other materials
 *        provided with the distribution.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 */

#ifndef __SERVER_REQUEST_H__
#define __SERVER_REQUEST_H__

#include <math.h>
#include <vector>
#include <tools_dev_types.h>
#include "psid_query_item.h"
#include "mlxfwmanager_common.h"
#ifdef USE_CURL
#include <json/reader.h>
#include <json/writer.h>
#include <curl.h>
#include <string.h>
#endif

#if defined(__WIN__)
#define EXECUTABLE_MODE 0xFFFF
#else
#define EXECUTABLE_MODE 777
#endif

using namespace std;

enum {
    ERR_SRVREQ_ACCESS_INIT = 1,
};

#define URL_TAG       "url"
#define FILE_NAME_TAG "name"
#define ERR_MSG_TAG   "err_msg"
#define ERR_NUM_TAG   "err_num"

int    progress_func(void *ptr, double TotalToDownload,
                     double NowDownloaded, double TotalToUpload,
                     double NowUploaded);

class ServerRequest {
public:
    ServerRequest(const char *url, const char *proxy,
                  int compare_ffv, bool show_progress, string key,
                  string certificate,
                  unsigned int numberOfRetrials);
    ~ServerRequest();
    int updateMFAsRequest(vector<string> &psid_list,
                          vector<dm_dev_id_t> &dev_types_list,
                          vector<string> &fw_version_list,
                          vector<PsidQueryItem> &results);
//        int queryAllMFAs(vector<string> &mfa_list);
    int DownloadFilesRequest(vector <DownloadedFileProperties> &files,
                             string os, string devs, string type);

    int queryPsids(string psids, vector<PsidQueryItem> &results);
    int download(string url, string dest_path);
    void getError(int &error, string &error_msg);
    inline void setNumberOfTrials(unsigned int num) {_numberOfRetrials = num;};
private:
    void setError(int error, string error_msg);
    int  parseQueryResponse(string jsonTxt, vector<PsidQueryItem> &results, bool ignoreNotFound = true);
//        int  parseQueryAllMFAsRespone(string jsonTxt, vector <string>&result);
    int  parseDownloadFilesResponse(string jsonTxt, vector <DownloadedFileProperties> &files);

    int curl_request(const char *url, const char *data, const char *dest_file, int numOfRet);
    int curl_request_str(const char *url, const char *data, string& response);
    string genertDownloadUrl(string file_url);
private:
    string _Url;
    string _WebService;
    string _Proxy;
    int _UseProxy;

    int _LastErrorNo;
    string _LastErrorStr;
    int _compare_ffv;
    bool _show_progress;
    string _key;
    string _ceritifcate;
    unsigned int _numberOfRetrials;
    #ifdef USE_CURL
    static CURL *_curl;
    struct curl_slist *_headers;
    #endif
};

#endif