summaryrefslogtreecommitdiff
path: root/vdagent/file_xfer.h
blob: 7ac911e546463a0a1e7a1d7c025bcea66843da46 (plain)
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
/*
   Copyright (C) 2013 Red Hat, Inc.

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2 of
   the License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _H_FILE_XFER
#define _H_FILE_XFER

#include <map>
#include "vdcommon.h"

typedef struct ALIGN_VC FileXferTask {
    FileXferTask(HANDLE _handle, uint64_t _size, char* _name):
    handle(_handle), size(_size), pos(0) {
        // FIXME: should raise an error if name is too long..
        //        currently the only user is FileXfer::handle_start
        //        which verifies that strlen(_name) < MAX_PATH
        vdagent_strcpy_s(name, sizeof(name), _name);
    }
    HANDLE handle;
    uint64_t size;
    uint64_t pos;
    char name[MAX_PATH];
} ALIGN_GCC FileXferTask;

typedef std::map<uint32_t, FileXferTask*> FileXferTasks;

class FileXfer {
public:
    ~FileXfer();
    bool dispatch(VDAgentMessage* msg, VDAgentFileXferStatusMessage* status);

private:
    void handle_start(VDAgentFileXferStartMessage* start, VDAgentFileXferStatusMessage* status);
    bool handle_data(VDAgentFileXferDataMessage* data, VDAgentFileXferStatusMessage* status);
    void handle_status(VDAgentFileXferStatusMessage* status);
    bool g_key_get_string(char* data, const char* group, const char* key, char* value,
                                        unsigned vsize);
    bool g_key_get_uint64(char* data, const char* group, const char* key, uint64_t* value);

private:
    FileXferTasks _tasks;
};

#endif