summaryrefslogtreecommitdiff
path: root/vdagent/file_xfer.h
blob: b138019eedfaa2e1821225bf6fc75b820f7b0747 (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
58
59
60
61
62
63
64
/*
   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 <memory>
#include "vdcommon.h"

struct FileXferTask {
    FileXferTask(HANDLE _handle, uint64_t _size, const TCHAR* _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 _tcslen(_name) < MAX_PATH
        lstrcpyn(name, _name, ARRAYSIZE(name));
        name[ARRAYSIZE(name)-1] = 0;
    }
    ~FileXferTask();

    HANDLE handle;
    uint64_t size;
    uint64_t pos;
    TCHAR name[MAX_PATH];

    void success();
};

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

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

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