-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoterapi.hpp
95 lines (82 loc) · 4.4 KB
/
noterapi.hpp
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
#ifndef NOTERAPI_H
#define NOTERAPI_H
#include <string>
#include "maths.hpp"
#include "requests.hpp"
#include "responses.hpp"
#include "jsonhelper.hpp"
#include "noteprocs.hpp"
#include "userprocs.hpp"
#include "constants.hpp"
#include "additional.hpp"
#include "unbzip2.h"
#include "resources.h"
typedef struct NOTER_CREDENTIALS {
std::string username, password;
} NOTER_CREDENTIALS;
typedef struct NOTER_CONNECTION_SETTINGS {
std::string serverAddress, share, userAgent;
unsigned int port;
bool requestCompression;
} NOTER_CONNECTION_SETTINGS;
typedef struct NOTER_SERVER_INFO {
std::string name, timezone, version;
} NOTER_SERVER_INFO;
typedef struct NOTER_NOTES {
NOTE_SUMMARY *notes;
long int noteCount;
} NOTER_NOTES;
bool noter_credentialsAvailable(NOTER_CREDENTIALS&);
bool noter_connectionSettingsAvailable(NOTER_CONNECTION_SETTINGS&);
std::string noter_getAnswerString(long int);
NOTER_CREDENTIALS noter_prepareCredentials(char*, char*);
NOTER_CONNECTION_SETTINGS noter_prepareConnectionSettings(char*, unsigned int, char*, char*, bool);
bool noter_checkAndPrepareResponse(HEADERS&, char*&, unsigned int&, json_value*&, NAMEDESCRIPTOR&);
NOTER_SERVER_INFO noter_getServerInfo(NOTER_CONNECTION_SETTINGS&, char*);
long int noter_getNoteList(NOTER_CONNECTION_SETTINGS&, NOTER_CREDENTIALS&, char*, NOTE_SUMMARY*&);
long int noter_getNote(NOTER_CONNECTION_SETTINGS&, NOTER_CREDENTIALS&, unsigned long int, char*, NOTE&);
long int inline noter_getAnswerCode(NAMEDESCRIPTOR&);
bool inline noter_correctResponse(HEADERS&);
unsigned int inline noter_simplyMakeRequest(char*, NOTER_CONNECTION_SETTINGS&, NOTER_CREDENTIALS*, char*, char*, char*, unsigned long int, char*, HEADERS&, char*);
bool inline noter_checkServerVersion(NOTER_SERVER_INFO&);
long int noter_getUserInfo(NOTER_CONNECTION_SETTINGS&, NOTER_CREDENTIALS&, char*, USER_INFO&);
long int noter_lockNote(NOTER_CONNECTION_SETTINGS&, NOTER_CREDENTIALS&, unsigned long int, char*);
long int noter_unlockNote(NOTER_CONNECTION_SETTINGS&, NOTER_CREDENTIALS&, unsigned long int, char*);
long int noter_deleteNote(NOTER_CONNECTION_SETTINGS&, NOTER_CREDENTIALS&, unsigned long int, char*);
long int noter_addNote(NOTER_CONNECTION_SETTINGS&, NOTER_CREDENTIALS&, NOTE&, char*);
long int noter_updateNote(NOTER_CONNECTION_SETTINGS&, NOTER_CREDENTIALS&, NOTE&, char*);
long int noter_registerUser(NOTER_CONNECTION_SETTINGS&, NOTER_CREDENTIALS&, char*);
long int noter_changeUserPassword(NOTER_CONNECTION_SETTINGS&, NOTER_CREDENTIALS&, char*, char*);
long int noter_removeUser(NOTER_CONNECTION_SETTINGS&, NOTER_CREDENTIALS&, char*);
unsigned int getCompressionRatio(void);
long int inline noter_getAnswerCode(NAMEDESCRIPTOR &descriptor) {
return getSingleInteger(descriptor["answer_info_code"]);
}
bool inline noter_correctResponse(HEADERS &headers) {
return ((getResponseCode(headers)==200) && (headers["Content-Type"]=="application/json"));
}
unsigned int inline noter_simplyMakeRequest(char* method, NOTER_CONNECTION_SETTINGS &connectionSettings, NOTER_CREDENTIALS *credentials,
char* action, char* subject, char* entry, unsigned long int noteID, char* newPassword, HEADERS &heads,
char* buffer)
{
return makeRequest((char*)connectionSettings.serverAddress.c_str(),
connectionSettings.port,
method,
(char*)connectionSettings.share.c_str(),
(char*)connectionSettings.userAgent.c_str(),
"application/x-www-form-urlencoded",
(char*)prepareContent(action,
(credentials==NULL)?"":(char*)credentials->username.c_str(),
(credentials==NULL)?"":(char*)credentials->password.c_str(),
subject,
entry,
noteID,
newPassword,
connectionSettings.requestCompression).c_str(),
heads,
buffer);
}
bool inline noter_checkServerVersion(NOTER_SERVER_INFO &serverInfo) {
return serverInfo.version==MATCH_VERSION;
}
#endif