#include <stddef.h>
Go to the source code of this file.
Macros | |
#define | CP_OK 0 |
#define | CP_FAIL 1 |
#define | CP_TRUE 1 |
#define | CP_FALSE 0 |
Typedefs | |
typedef struct _cloudplugs_session * | cp_session |
typedef int | cp_res |
typedef int | cp_bool |
typedef enum _CP_HTTP_RESULT | CP_HTTP_RESULT |
typedef enum _CP_ERR_CODE | CP_ERR_CODE |
Enumerations | |
enum | _CP_HTTP_RESULT { CP_HTTP_OK = 200, CP_HTTP_CREATED = 201, CP_HTTP_MULTI_STATUS = 207, CP_HTTP_BAD_REQUEST = 400, CP_HTTP_UNAUTHORIZED = 401, CP_HTTP_PAYMENT_REQUIRED = 402, CP_HTTP_FORBIDDEN = 403, CP_HTTP_NOT_FOUND = 404, CP_HTTP_NOT_ALLOWED = 405, CP_HTTP_NOT_ACCEPTABLE = 406, CP_HTTP_SERVER_ERROR = 500, CP_HTTP_NOT_IMPLEMENTED = 501, CP_HTTP_BAD_GATEWAY = 502, CP_HTTP_SERVICE_UNAVAILABLE = 503 } |
enum | _CP_ERR_CODE { CP_ERR_INTERNAL_ERROR = -1, CP_ERR_OUT_OF_MEMORY = -2, CP_ERR_INVALID_SESSION = -3, CP_ERR_QUERY_IS_NOT_AN_OBJECT = -4, CP_ERR_QUERY_INVALID_TYPE = -5, CP_ERR_HEADERS_MUST_BE_STRING = -6, CP_ERR_INVALID_PARAMETER = -7, CP_ERR_INVALID_LOGIN = -8, CP_ERR_JSON_PARSE = -9, CP_ERR_JSON_ENCODE = -10, CP_ERR_INVALID_CONTENT_LENGTH = -11, CP_ERR_HTTP = -12 } |
Functions | |
cp_res | cloudplugs_global_init () |
cp_res | cloudplugs_global_shutdown () |
cp_res | cloudplugs_set_base_url (cp_session cps, const char *url) |
cp_res | cloudplugs_set_cacert (cp_session cps, const char *filename) |
const char * | cloudplugs_get_base_url (cp_session cps) |
cp_res | cloudplugs_set_timeout (cp_session cps, int timeout) |
int | cloudplugs_get_timeout (cp_session cps) |
const char * | cloudplugs_get_last_err_string (cp_session cps) |
CP_ERR_CODE | cloudplugs_get_last_err_code (cp_session cps) |
const char * | cloudplugs_get_last_http_result_string (cp_session cps) |
CP_HTTP_RESULT | cloudplugs_get_last_http_result (cp_session cps) |
cp_session | cloudplugs_create_session () |
cp_res | cloudplugs_set_auth (cp_session cps, const char *id, const char *pass, cp_bool is_master) |
cp_res | cloudplugs_ssl_verify (cp_session cps, cp_bool is_verified) |
cp_bool | cloudplugs_has_ssl_verify (cp_session cps) |
cp_res | cloudplugs_enable_ssl (cp_session cps, cp_bool is_enabled) |
cp_bool | cloudplugs_has_ssl (cp_session cps) |
cp_res | cloudplugs_get_auth_id (cp_session cps, char *id, size_t size) |
cp_res | cloudplugs_get_auth_pass (cp_session cps, char *password, size_t size) |
cp_bool | cloudplugs_is_auth_master (cp_session cps) |
cp_res | cloudplugs_destroy_session (cp_session cps) |
cp_bool | cloudplugs_extract_string_from_json (char **json, const char *key, char *res, const int n) |
cp_res | cloudplugs_enroll_product (cp_session cps, const char *body, char **result, size_t *result_length) |
cp_res | cloudplugs_enroll_prototype (cp_session cps, const char *body, char **result, size_t *result_length) |
cp_res | cloudplugs_enroll_ctrl (cp_session cps, const char *body, char **result, size_t *result_length) |
cp_res | cloudplugs_control_device (cp_session cps, const char *body, char **result, size_t *result_length) |
cp_res | cloudplugs_uncontrol_device (cp_session cps, const char *plugid, const char *plugid_controlled, char **result, size_t *result_length) |
cp_res | cloudplugs_get_device (cp_session cps, const char *plugid, char **result, size_t *result_length) |
cp_res | cloudplugs_get_device_prop (cp_session cps, const char *plugid, const char *prop, char **result, size_t *result_length) |
cp_res | cloudplugs_set_device_prop (cp_session cps, const char *plugid, const char *prop, const char *value) |
cp_res | cloudplugs_remove_device_prop (cp_session cps, const char *plugid, const char *prop) |
cp_res | cloudplugs_set_device (cp_session cps, const char *plugid, const char *value, char **result, size_t *result_length) |
cp_res | cloudplugs_unenroll (cp_session cps, const char *plugid, char **result, size_t *result_length) |
cp_res | cloudplugs_get_channel (cp_session cps, const char *channel_mask, const char *query, char **result, size_t *result_length) |
cp_res | cloudplugs_retrieve_data (cp_session cps, const char *channel_mask, const char *query, char **result, size_t *result_length) |
cp_res | cloudplugs_publish_data (cp_session cps, const char *channel, const char *body, char **result, size_t *result_length) |
cp_res | cloudplugs_remove_data (cp_session cps, const char *channel_mask, const char *body, char **result, size_t *result_length) |
cp_res | cloudplugs_set_device_location (cp_session cps, const char *plugid, double longitude, double latitude, double altitude, double accuracy, double timestamp) |
cp_res | cloudplugs_get_device_location (cp_session cps, const char *plugid, char **result, size_t *result_length) |
#define CP_FAIL 1 |
#define CP_FALSE 0 |
#define CP_OK 0 |
#define CP_TRUE 1 |
typedef int cp_bool |
Library internal booleans
typedef enum _CP_ERR_CODE CP_ERR_CODE |
Library internal error codes
typedef enum _CP_HTTP_RESULT CP_HTTP_RESULT |
HTTP results returned by the server
typedef int cp_res |
An integer representing the result of a request
typedef struct _cloudplugs_session* cp_session |
Reference to a session
enum _CP_ERR_CODE |
enum _CP_HTTP_RESULT |
cp_res cloudplugs_control_device | ( | cp_session | cps, |
const char * | body, | ||
char ** | result, | ||
size_t * | result_length | ||
) |
This function performs an HTTP request to the server for controlling a device and place the response in *result and *result_length.
cps | The session reference. |
body | A buffer containing a json object like this: { "model" : PLUG_ID, // model id of the device to control "ctrl" : HWID, // serial number (hwid) of the device to control "pass" : String, } |
result | If not NULL, then *result will contain the dynamically allocated json string of the retrieved response body. The caller is responsible to free memory in *result. |
result_length | The length of the string stored in *result. |
cp_session cloudplugs_create_session | ( | ) |
Initializes a HTTP persistent connection.
cp_res cloudplugs_destroy_session | ( | cp_session | cps | ) |
Closes and cleans a session.
cps | The session reference. |
cp_res cloudplugs_enable_ssl | ( | cp_session | cps, |
cp_bool | is_enabled | ||
) |
Enable or disable ssl protocol.
cps | The session reference. |
is_enabled | Boolean state of ssl. |
cp_res cloudplugs_enroll_ctrl | ( | cp_session | cps, |
const char * | body, | ||
char ** | result, | ||
size_t * | result_length | ||
) |
This function performs an HTTP request to the server for enrolling a new or already existent controller device and place the response in *result and *result_length.
cps | The session reference without authentication if it's the first enroll. |
body | A buffer containing a json object like this: { "model" : PLUG_ID, // model id of the device to control "ctrl" : HWID, // serial number (hwid) of the device to control "pass" : String, "hwid" : HWID, // unique string to identify this controller device "name" : String // the name of this device } |
result | If not NULL, then a pointer such that *result will contain the dynamically allocated json string of the retrieved response body. The caller is responsible to free memory in *result. |
result_length | The length of the string stored in *result. |
cp_res cloudplugs_enroll_product | ( | cp_session | cps, |
const char * | body, | ||
char ** | result, | ||
size_t * | result_length | ||
) |
This function performs an HTTP request to the server for enrolling a new production device and place the response in *result and *result_length.
cps | The session reference without authentication. |
body | A buffer containing a json object like this: { "model" : PLUG_ID, // the model of this device "hwid" : HWID, // the serial number "pass" : String, "props" : JSON // optional, to initialize the custom properties } |
result | If not NULL, then *result will contain the dynamically allocated json string of the retrieved response body. The caller is responsible to free memory in *result. |
result_length | The length of the string stored in *result. |
cp_res cloudplugs_enroll_prototype | ( | cp_session | cps, |
const char * | body, | ||
char ** | result, | ||
size_t * | result_length | ||
) |
This function performs an HTTP request to the server for enrolling a prototype and place the response in *result and *result_length.
cps | The session reference without authentication. |
body | A buffer containing a json object like this: { "hwid" : HWID, // optional, if absent it will be set as a random unique string "pass" : String, // optional, if absent set as the X-Plug-Master of the company "name" : String, "perm" : PERM_FILTER, // optional, if absent permit all "props" : JSON // optional, to initialize the custom properties } |
result | If not NULL, then *result will contain the dynamically allocated json string of the retrieved response body. The caller is responsible to free memory in *result. |
result_length | The length of the string stored in *result. |
cp_bool cloudplugs_extract_string_from_json | ( | char ** | json, |
const char * | key, | ||
char * | res, | ||
const int | n | ||
) |
Extract a string value from a json object
json | The JSON string. |
key | The key. |
res | The destination buffer where the string value will be written. |
n | Size of the destination buffer. |
cp_res cloudplugs_get_auth_id | ( | cp_session | cps, |
char * | id, | ||
size_t | size | ||
) |
Get the authentication id (PLUG_ID or email) of the session.
cps | The session reference. |
id | The destination buffer where the authentication id will be written. |
size | Size of the destination buffer. |
cp_res cloudplugs_get_auth_pass | ( | cp_session | cps, |
char * | password, | ||
size_t | size | ||
) |
Get the authentication password of the session.
cps | The session reference. |
password | The destination buffer where the authentication password will be written. |
size | Size of the destination buffer. |
const char* cloudplugs_get_base_url | ( | cp_session | cps | ) |
Get the current base url.
cps | The session reference. |
cp_res cloudplugs_get_channel | ( | cp_session | cps, |
const char * | channel_mask, | ||
const char * | query, | ||
char ** | result, | ||
size_t * | result_length | ||
) |
This function performs an HTTP request to the server for retrieving list channels/channels about already published data and place the response in *result and *result_length.
cps | The session reference. |
channel_mask | CHMASK The channel mask. |
query | If not NULL, must be a url-encode string containing those values: before: Optional, TIMESTAMP or OBJECT_ID timestamp valid if greater than zero after: Optional, TIMESTAMP or OBJECT_ID timestamp valid if greater than zero at: Optional, TIMESTAMP_CSV timestamp valid if greater than zero of: Optional, PLUG_ID_CSV offset: Optional Number: positive integer (including 0) limit: Optional Number: positive integer (including 0) |
result | A pointer such that *result will contain the dynamically allocated json string of the retrieved response body. The caller is responsible to free memory in *result. |
result_length | The length of the string stored in *result. |
cp_res cloudplugs_get_device | ( | cp_session | cps, |
const char * | plugid, | ||
char ** | result, | ||
size_t * | result_length | ||
) |
This function performs an HTTP request to the server for reading a device and place the response in *result and *result_length.
cps | The session reference. |
plugid | The PLUG_ID of the device. |
result | If not NULL, then *result will contain the dynamically allocated json string of the retrieved response body. The caller is responsible to free memory in *result. |
result_length | The length of the string stored in *result. |
cp_res cloudplugs_get_device_location | ( | cp_session | cps, |
const char * | plugid, | ||
char ** | result, | ||
size_t * | result_length | ||
) |
This function performs an HTTP request to the server for writing or deleting device location and place the response in *result and *result_length.
cps | The session reference. |
plugid | If not NULL, then the PLUG_ID of the device, otherwise the device referenced in the session. |
result | If not NULL, then *result will contain the dynamically allocated json string of the retrieved response body. The caller is responsible to free memory in *result. |
result_length | The length of the string stored in *result. |
cp_res cloudplugs_get_device_prop | ( | cp_session | cps, |
const char * | plugid, | ||
const char * | prop, | ||
char ** | result, | ||
size_t * | result_length | ||
) |
This function performs an HTTP request to the server for reading the device properties and place the response in *result and *result_length.
cps | The session reference. |
plugid | The PLUG_ID of the device. |
prop | If NULL, then all properties value; otherwise the single property value. |
result | If not NULL, then *result will contain the dynamically allocated json string of the retrieved response body. The caller is responsible to free memory in *result. |
result_length | The length of the string stored in *result. |
CP_ERR_CODE cloudplugs_get_last_err_code | ( | cp_session | cps | ) |
Return a human-readable string that describes the last error.
cps | The session reference. |
const char* cloudplugs_get_last_err_string | ( | cp_session | cps | ) |
Return a human-readable string that describes the last error.
cps | The session reference. |
CP_HTTP_RESULT cloudplugs_get_last_http_result | ( | cp_session | cps | ) |
Return a human-readable string that describes the last error.
cps | The session reference. |
const char* cloudplugs_get_last_http_result_string | ( | cp_session | cps | ) |
Return a human-readable string that describes the last error.
cps | The session reference. |
int cloudplugs_get_timeout | ( | cp_session | cps | ) |
Get the current timeout.
cps | The session reference. |
cp_res cloudplugs_global_init | ( | ) |
Must be called at least once within a program (a program is all the code that shares a memory space) before the program calls any other function of CloudPlugs library. The environment it sets up is constant for the life of the program and is the same for every program, so multiple calls have the same effect as one call. This function is not thread safe. You must not call it when any other thread in the program (i.e. a thread sharing the same memory) is running. This doesn't just mean no other thread that is using CloudPlugs library.
cp_res cloudplugs_global_shutdown | ( | ) |
Must be called once for each call made to cloudplugs_global_init(), after you are done using CloudPlugs library. This function is not thread safe. You must not call it when any other thread in the program (i.e. a thread sharing the same memory) is running. This doesn't just mean no other thread that is using CloudPlugs library.
cp_bool cloudplugs_has_ssl | ( | cp_session | cps | ) |
State of ssl protocol.
cps | The session reference. |
cp_bool cloudplugs_has_ssl_verify | ( | cp_session | cps | ) |
State of ssl verification.
cps | The session reference. |
cp_bool cloudplugs_is_auth_master | ( | cp_session | cps | ) |
Return the authentication mode in the session.
cps | The session reference. |
cp_res cloudplugs_publish_data | ( | cp_session | cps, |
const char * | channel, | ||
const char * | body, | ||
char ** | result, | ||
size_t * | result_length | ||
) |
This function performs an HTTP request to the server for publishing data and [optionally] place the response in *result and *result_length.
cps | The session reference. |
channel | An optional CHANNEL , if NULL data need to contain a couple "channel":"channel" |
body | A json object or an array of objects like this: { "id" : “PLUG_ID”, "channel" : CHANNEL, // optional, to override the channel in the url "data" : JSON, "at" : TIMESTAMP, "of" : PLUG_ID, // optional, check if the X-Plug-Id is authorized for setting this field "is_priv" : Boolean, // optional, default false "expire_at" : TIMESTAMP, // optional, expire date of this data entry "ttl" : Number // optional, how many seconds this data entry will live (if "expire_at" is present, then this field is ignored) } |
result | If not NULL, then *result will contain the dynamically allocated json string of the retrieved response body. The caller is responsible to free memory in *result. |
result_length | The length of the string stored in *result. |
cp_res cloudplugs_remove_data | ( | cp_session | cps, |
const char * | channel_mask, | ||
const char * | body, | ||
char ** | result, | ||
size_t * | result_length | ||
) |
This function performs an HTTP request to the server for deleting already published data and [optionally] place the response in *result and *result_length.
cps | The session reference. |
channel_mask | The CHMASK |
body | A buffer containing a json object like this (at least one param is required: id, before, after or at): { "id" : OBJECT_ID_CSV , "before" : TIMESTAMP or PLUG_ID, "after" : TIMESTAMP or PLUG_ID, "at" : TIMESTAMP_CSV or , "of" : PLUG_ID_CSV or } |
result | If not NULL, then *result will contain the dynamically allocated json string of the retrieved response body. The caller is responsible to free memory in *result. |
result_length | The length of the string stored in *result. |
cp_res cloudplugs_remove_device_prop | ( | cp_session | cps, |
const char * | plugid, | ||
const char * | prop | ||
) |
This function performs an HTTP request to the server for deleting device property and [optionally] place the response in *result and *result_length.
cps | The session reference. |
plugid | The PLUG_ID of the device. |
prop | The single property to be remove. |
cp_res cloudplugs_retrieve_data | ( | cp_session | cps, |
const char * | channel_mask, | ||
const char * | query, | ||
char ** | result, | ||
size_t * | result_length | ||
) |
This function performs an HTTP request to the server for retrieving already published data and place the response in *result and *result_length.
cps | The session reference. |
channel_mask | CHMASK The channel mask. |
query | If not NULL, must be a url-encode string containing those values: before: Optional, TIMESTAMP or OBJECT_ID timestamp valid if greater than zero after: Optional, TIMESTAMP or OBJECT_ID timestamp valid if greater than zero at: Optional, TIMESTAMP_CSV timestamp valid if greater than zero of: Optional,PLUG_ID_CSV offset: Optional Number: positive integer (including 0) limit: Optional Number: positive integer (including 0) |
result | A pointer such that *result will contain the dynamically allocated json string of the retrieved response body. The caller is responsible to free memory in *result. |
result_length | The length of the string stored in *result. |
cp_res cloudplugs_set_auth | ( | cp_session | cps, |
const char * | id, | ||
const char * | pass, | ||
cp_bool | is_master | ||
) |
Set the session authentication credentials.
cps | The session reference. |
id | A string containing the PLUG_ID or the master email. |
pass | A string containing the authentication code. |
is_master | CP_TRUE for using master authentication in the session; CP_FALSE for using regular authentication. |
cp_res cloudplugs_set_base_url | ( | cp_session | cps, |
const char * | url | ||
) |
Change the default base url.
cps | The session reference. |
url | Http or https url string. |
cp_res cloudplugs_set_cacert | ( | cp_session | cps, |
const char * | filename | ||
) |
Set the certification authority for verify ssl connections.
cps | The session reference. |
filename | String naming a file holding one or more certificates to verify the peer with. |
cp_res cloudplugs_set_device | ( | cp_session | cps, |
const char * | plugid, | ||
const char * | value, | ||
char ** | result, | ||
size_t * | result_length | ||
) |
This function performs an HTTP request to the server for modifying device and [optionally] place the response in *result and *result_length.
cps | The session reference. |
plugid | The PLUG_ID of the device. |
value | A json object like this: { "perm" : PERM_FILTER, // optional, it contains just the sharing filters to modify "name" : String, // optional "status" : STATUS, // optional "props" : Object // optional, it contains just the properties to modify } |
result | If not NULL, then *result will contain the dynamically allocated json string of the retrieved response body. The caller is responsible to free memory in *result. |
result_length | The length of the string stored in *result. |
cp_res cloudplugs_set_device_location | ( | cp_session | cps, |
const char * | plugid, | ||
double | longitude, | ||
double | latitude, | ||
double | altitude, | ||
double | accuracy, | ||
double | timestamp | ||
) |
This function performs an HTTP request to the server for writing or deleting device location and [optionally] place the response in *result and *result_length.
cps | The session reference. |
plugid | If not NULL, then the PLUG_ID of the device, otherwise the device referenced in the session. |
longitude | |
latitude | |
altitude | //optional |
accuracy | //optional |
timestamp | //optional |
cp_res cloudplugs_set_device_prop | ( | cp_session | cps, |
const char * | plugid, | ||
const char * | prop, | ||
const char * | value | ||
) |
This function performs an HTTP request to the server for writing or deleting device properties and [optionally] place the response in *result and *result_length.
cps | The session reference. |
plugid | The PLUG_ID of the device. |
prop | If NULL, then value must be an object; otherwise the single property value is written. |
value | A json value, use null to delete one or all device properties. |
cp_res cloudplugs_set_timeout | ( | cp_session | cps, |
int | timeout | ||
) |
Change the default timeout.
cps | The session reference. |
timeout | Timeout in seconds. |
cp_res cloudplugs_ssl_verify | ( | cp_session | cps, |
cp_bool | is_verified | ||
) |
Enable or disable ssl verification.
cps | The session reference. |
is_verified | Boolean state of ssl verification. |
cp_res cloudplugs_uncontrol_device | ( | cp_session | cps, |
const char * | plugid, | ||
const char * | plugid_controlled, | ||
char ** | result, | ||
size_t * | result_length | ||
) |
This function performs an HTTP request to the server for uncontrol a device and [optionally] place the response in *result and *result_length.
cps | The session reference. |
plugid | If NULL, then is the PLUG_ID in the session. |
plugid_controlled | If not NULL, then the device(s) to uncontroll (default all associated devices). |
result | If not NULL, then *result will contain the dynamically allocated json string of the retrieved response body. The caller is responsible to free memory in *result. |
result_length | The length of the string stored in *result. |
cp_res cloudplugs_unenroll | ( | cp_session | cps, |
const char * | plugid, | ||
char ** | result, | ||
size_t * | result_length | ||
) |
This function performs an HTTP request to the server for removing any device (development, product or controller) and [optionally] place the response in *result and *result_length.
cps | The session reference. |
plugid | The PLUG_ID_CSV of the device(s) to remove; if NULL then remove the device referenced in the session. |
result | If not NULL, then *result will contain the dynamically allocated json string of the retrieved response body. The caller is responsible to free memory in *result. |
result_length | The length of the string stored in *result. |