-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.cpp
81 lines (79 loc) · 2.28 KB
/
client.cpp
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
#include "client.h"
void transread(const char *host,const char *filepath,const char *targetdir,const char *uid,const char *gid,const char *position,const char *size)
{
Py_Initialize();
if(!Py_IsInitialized())
{
printf("can't initialize\n");
}
PyObject * pModule = NULL;
PyObject * pFunc = NULL;
PyObject * result = NULL;
PyRun_SimpleString("import sys");
PyRun_SimpleString("import os");
PyRun_SimpleString("import string");
PyRun_SimpleString("sys.path.append('./')");
PyObject *pArgs = PyTuple_New(7);
PyTuple_SetItem(pArgs,0,Py_BuildValue("s",host));
PyTuple_SetItem(pArgs,1,Py_BuildValue("s",filepath));
PyTuple_SetItem(pArgs,2,Py_BuildValue("s",targetdir));
PyTuple_SetItem(pArgs,3,Py_BuildValue("s",uid));
PyTuple_SetItem(pArgs,4,Py_BuildValue("s",gid));
PyTuple_SetItem(pArgs,5,Py_BuildValue("s",position));
PyTuple_SetItem(pArgs,6,Py_BuildValue("s",size));
printf("size is %s\n",size);
pModule = PyImport_ImportModule("client");
if(pModule == NULL)
{
printf("can't load module\n");
}
pFunc = PyObject_GetAttrString(pModule,"readentrance");
if(pFunc == NULL)
{
printf("can't load function\n");
}
result = PyEval_CallObject(pFunc,pArgs);
cout<<result<<endl;
Py_DECREF(pArgs);
if(result == NULL)
cout<<"null"<<endl;
Py_DECREF(result);
Py_Finalize();
//return 0;
}
void transupload(const char *host,const char *filepath,const char *targetdir)
{
Py_Initialize();
if(!Py_IsInitialized())
{
printf("can't initialize\n");
}
PyObject * pModule = NULL;
PyObject * pFunc = NULL;
PyObject * result = NULL;
PyRun_SimpleString("import sys");
PyRun_SimpleString("import os");
PyRun_SimpleString("import string");
PyRun_SimpleString("sys.path.append('./')");
PyObject *pArgs = PyTuple_New(3);
PyTuple_SetItem(pArgs,0,Py_BuildValue("s",host));
PyTuple_SetItem(pArgs,1,Py_BuildValue("s",filepath));
PyTuple_SetItem(pArgs,2,Py_BuildValue("s",targetdir));
pModule = PyImport_ImportModule("client");
// printf("host %s",host);
if(pModule == NULL)
{
printf("can't load module\n");
}
pFunc = PyObject_GetAttrString(pModule,"uploadentrance");
if(pFunc == NULL)
{
printf("can't load function\n");
}
result = PyEval_CallObject(pFunc,pArgs);
Py_DECREF(pArgs);
if(result == NULL)
cout<<"null"<<endl;
Py_DECREF(result);
Py_Finalize();
}