本文整理汇总了C++中pcs_free函数的典型用法代码示例。如果您正苦于以下问题:C++ pcs_free函数的具体用法?C++ pcs_free怎么用?C++ pcs_free使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pcs_free函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pcs_http_build_url
static PcsFileInfo *pcs_upload_form(Pcs handle, const char *path, PcsBool overwrite, PcsHttpForm form)
{
struct pcs *pcs = (struct pcs *)handle;
char *url, *html,
*dir = pcs_utils_basedir(path),
*filename = pcs_utils_filename(path);
cJSON *json, *item;
PcsFileInfo *meta;
url = pcs_http_build_url(pcs->http, URL_PCS_REST,
"method", "upload",
"app_id", "250528",
"ondup", overwrite ? "overwrite" : "newcopy",
"dir", dir,
"filename", filename,
"BDUSS", pcs->bduss,
NULL);
pcs_free(dir);
pcs_free(filename);
if (!url) {
pcs_set_errmsg(handle, "Can't build the url.");
return NULL;
}
html = pcs_post_httpform(pcs->http, url, form, PcsTrue);
pcs_free(url);
if (!html) {
pcs_set_errmsg(handle, "Can't get response from the server.");
return NULL;
}
json = cJSON_Parse(html);
if (!json) {
pcs_set_errmsg(handle, "Can't parse the response as json: %s", html);
return NULL;
}
//"{\"error_code\":31062,\"error_msg\":\"file name is invalid\",\"request_id\":3071564675}
item = cJSON_GetObjectItem(json, "error_code");
if (item) {
int error_code = item->valueint;
const char *error_msg = NULL;
item = cJSON_GetObjectItem(json, "error_msg");
if (item)
error_msg = item->valuestring;
pcs_set_errmsg(handle, "Can't upload file. error_code: %d. error_msg: %s. raw response: %s", error_code, error_msg, html);
cJSON_Delete(json);
return NULL;
}
meta = pcs_parse_fileinfo(json);
cJSON_Delete(json);
if (!meta) {
pcs_set_errmsg(handle, "Can't parse the response as meta");
return NULL;
}
return meta;
}
示例2: pcs_slist_destroy
PCS_API void pcs_slist_destroy(PcsSList *slist)
{
PcsSList *p = slist, *p2;
while(p) {
p2 = p;
p = p->next;
if (p2->string)
pcs_free(p2->string);
pcs_free(p2);
}
}
示例3: my_dirent_destroy
void my_dirent_destroy(my_dirent *link)
{
my_dirent *cusor, *ent;
cusor = link;
while(cusor) {
ent = cusor;
cusor = cusor->next;
if (ent->path)
pcs_free(ent->path);
pcs_free(ent);
}
}
示例4: pcs_http_write
size_t pcs_http_write(char *ptr, size_t size, size_t nmemb, void *userdata)
{
struct pcs_http *http = (struct pcs_http *)userdata;
size_t sz;
char *p;
if (size == 0 || nmemb == 0) {
return 0;
}
sz = size * nmemb;
if (!pcs_http_parse_http_head(http, &ptr, &sz, PcsTrue)) {
if (http->strerror) pcs_free(http->strerror);
http->strerror = pcs_utils_strdup("Cannot parse the http head. ");
return 0;
}
if (sz > 0) {
if (http->res_type == PCS_HTTP_RES_TYPE_NORMAL + 1) {
http->res_body = pcs_http_append_bytes(http->res_body, http->res_body_size, ptr, sz);
http->res_body_size += sz;
}
else if (http->res_type == PCS_HTTP_RES_TYPE_VALIDATE_TEXT + 1) {
//验证内容正确性
p = &ptr[sz - 1];
while(p > ptr) {
if (*p == 0) {
if (http->strerror) pcs_free(http->strerror);
http->strerror = pcs_utils_strdup("The response is not the validate text. ");
return 0;
}
p--;
}
http->res_body = pcs_http_append_bytes(http->res_body, http->res_body_size, ptr, sz);
http->res_body_size += sz;
}
else if (http->res_type == PCS_HTTP_RES_TYPE_RAW + 1) {
http->res_body = pcs_http_append_bytes(http->res_body, http->res_body_size, ptr, sz);
http->res_body_size += sz;
}
else if (http->res_type == PCS_HTTP_RES_TYPE_DOWNLOAD + 1) {
if (!http->write_func) {
if (http->strerror) pcs_free(http->strerror);
http->strerror = pcs_utils_strdup("Have no write function. ");
return 0;
}
return (*http->write_func)(ptr, sz, http->res_content_length, http->write_data);
}
else
return 0;
}
return size * nmemb;
}
示例5: pcs_http_destroy
PCS_API void pcs_http_destroy(PcsHttp handle)
{
struct pcs_http *http = (struct pcs_http *)handle;
if (http->curl)
curl_easy_cleanup(http->curl);
if (http->res_header)
pcs_free(http->res_header);
if (http->res_body)
pcs_free(http->res_body);
if (http->res_encode)
pcs_free(http->res_encode);
pcs_free(http);
}
示例6: node_destroy
static void node_destroy(HashtableNode *node, void(*free_value)(void *))
{
HashtableNode *tmp, *cusor;
cusor = node;
while(cusor) {
tmp = cusor;
cusor = cusor->next;
if (tmp->key)
pcs_free(tmp->key);
if (free_value && tmp->value)
(*free_value)(tmp->value);
pcs_free(tmp);
}
}
示例7: pcs_setopt
PCS_API PcsRes pcs_setopt(Pcs handle, PcsOption opt, void *value)
{
PcsRes res = PCS_OK;
struct pcs *pcs = (struct pcs *)handle;
switch (opt)
{
case PCS_OPTION_USERNAME:
if (pcs->username) pcs_free(pcs->username);
pcs->username = pcs_utils_strdup((char *)value);
break;
case PCS_OPTION_PASSWORD:
if (pcs->password) pcs_free(pcs->password);
pcs->password = pcs_utils_strdup((char *)value);
break;
case PCS_OPTION_CAPTCHA_FUNCTION:
pcs->captcha_func = (PcsGetCaptchaFunction)value;
break;
case PCS_OPTION_CAPTCHA_FUNCTION_DATA:
pcs->captcha_data = value;
break;
case PCS_OPTION_DOWNLOAD_WRITE_FUNCTION:
pcs_http_setopt(pcs->http, PCS_HTTP_OPTION_HTTP_WRITE_FUNCTION, value);
break;
case PCS_OPTION_DOWNLOAD_WRITE_FUNCTION_DATA:
pcs_http_setopt(pcs->http, PCS_HTTP_OPTION_HTTP_WRITE_FUNCTION_DATE, value);
break;
case PCS_OPTION_HTTP_RESPONSE_FUNCTION:
pcs_http_setopt(pcs->http, PCS_HTTP_OPTION_HTTP_RESPONSE_FUNCTION, value);
break;
case PCS_OPTION_HTTP_RESPONSE_FUNCTION_DATE:
pcs_http_setopt(pcs->http, PCS_HTTP_OPTION_HTTP_RESPONSE_FUNCTION_DATE, value);
break;
case PCS_OPTION_PROGRESS_FUNCTION:
pcs_http_setopt(pcs->http, PCS_HTTP_OPTION_PROGRESS_FUNCTION, value);
break;
case PCS_OPTION_PROGRESS_FUNCTION_DATE:
pcs_http_setopt(pcs->http, PCS_HTTP_OPTION_PROGRESS_FUNCTION_DATE, value);
break;
case PCS_OPTION_PROGRESS:
pcs_http_setopt(pcs->http, PCS_HTTP_OPTION_PROGRESS, value);
break;
default:
pcs_set_errmsg(handle, "Unknown option");
res = PCS_UNKNOWN_OPT;
break;
}
return res;
}
示例8: cb_get_verify_code_byurlc_curl_write
static size_t cb_get_verify_code_byurlc_curl_write(char *ptr, size_t size, size_t nmemb, void *userdata)
{
char **html = (char **) userdata;
char *p;
size_t sz, ptrsz;
ptrsz = size * nmemb;
if (ptrsz == 0)
return ptrsz;
if (*html)
sz = strlen(*html);
else
sz = 0;
size = sz + ptrsz;
p = (char *) pcs_malloc(size + 1);
if (!p)
return 0;
if (*html) {
memcpy(p, *html, sz);
pcs_free(*html);
}
memcpy(&p[sz], ptr, ptrsz);
p[size] = '\0';
*html = p;
return ptrsz;
}
示例9: strlen
PCS_API char *pcs_utils_strcat(char *dst, const char *src, int src_len, int free_dst)
{
char *res = 0;
int dst_len;
if (!src)
return dst;
if (src_len == -1)
src_len = strlen(src);
if (src_len == 0)
return dst;
if (dst)
dst_len = strlen(dst);
else
dst_len = 0;
res = (char *)pcs_malloc(dst_len + src_len + 1);
if (!res)
return 0;
memcpy(res, dst, dst_len);
memcpy(res + dst_len, src, src_len);
res[dst_len + src_len] = '\0';
if (dst && free_dst)
pcs_free(dst);
return res;
}
示例10: strcpy
/*
* 获取路径的父路径,如果没有父路径则返回NULL。
* path - 当前路径
* len - path的字节长度,如果传入-1,则内部使用strlen()获取其长度
* 返回值需要调用pcs_free()
*/
char *base_dir(const char *path, int len)
{
char *dir, *p;
if (!path) return NULL;
if (len == -1) len = strlen(path);
if (len == 0) return NULL;
dir = (char *)pcs_malloc(len + 1);
strcpy(dir, path);
p = dir + len - 1;
while (p > dir && *p != '/' && *p != '\\') p--;
if (p == dir) {
if (*p != '/' && *p != '\\') {
pcs_free(dir);
return NULL;
}
p[1] = '\0';
}
else {
#ifdef _WIN32
if (*(p - 1) == ':' && ((p - dir) == 2))
*(p + 1) = '\0';
else
*p = '\0';
#else
*p = '\0';
#endif
}
return dir;
}
示例11: pcs_http_get_content_length_from_header
static inline int pcs_http_get_content_length_from_header(const char *header, int size)
{
int res = -1;
char *val = NULL;
const char *p = header, *key = "Content-Length",
*end = NULL,
*tmp;
int i = 14;//strlen(key) = 14;
while (*p) {
if (*p == key[0] && pcs_utils_streq(p, key, i)) {
tmp = p + i;
PCS_SKIP_SPACE(tmp);
if (*tmp != ':') continue; tmp++;
PCS_SKIP_SPACE(tmp);
end = tmp;
while (*end && *end >= '0' && *end <= '9') end++;
if (end > tmp) {
val = (char *)pcs_malloc(end - tmp + 1);
memcpy(val, tmp, end - tmp);
val[end - tmp] = '\0';
res = atoi(val);
pcs_free(val);
break;
}
}
p++;
}
return res;
}
示例12: exec_cat
static void exec_cat(Pcs pcs, struct params *params)
{
const char *res;
size_t sz;
printf("\nCat %s\n", params->args[0]);
res = pcs_cat(pcs, params->args[0], &sz);
if (res == NULL) {
printf("Cat failed: %s\n", pcs_strerror(pcs));
return;
}
if (params->is_rc4) {
const char *rc4_key = get_rc4_key(params);
char *text;
RC4_CTX rc4;
secure_rc4_setup(&rc4, rc4_key);
text = (char *)pcs_malloc(sz + 1);
memset(text, 0, sz + 1);
RC4(&rc4, sz, (const unsigned char *)res, (unsigned char *)text);
text[sz] = '\0';
printf(">>>\n%s\n<<<\n", text);
pcs_free(text);
}
else {
printf(">>>\n%s\n<<<\n", res);
}
}
示例13: pcs_http_create
PCS_API PcsHttp pcs_http_create(const char *cookie_file)
{
struct pcs_http *http;
http = (struct pcs_http *) pcs_malloc(sizeof(struct pcs_http));
if (!http)
return NULL;
memset(http, 0, sizeof(struct pcs_http));
http->timeout = 0;
http->connect_timeout = 10;
http->curl = curl_easy_init();
if (!http->curl) {
pcs_free(http);
return NULL;
}
curl_easy_setopt(http->curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(http->curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(http->curl, CURLOPT_LOW_SPEED_LIMIT, 1024L);
curl_easy_setopt(http->curl, CURLOPT_LOW_SPEED_TIME, 60L);
curl_easy_setopt(http->curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(http->curl, CURLOPT_USERAGENT, USAGE);
curl_easy_setopt(http->curl, CURLOPT_FOLLOWLOCATION, 1L);
if (cookie_file) {
curl_easy_setopt(http->curl, CURLOPT_COOKIEFILE, cookie_file);
curl_easy_setopt(http->curl, CURLOPT_COOKIEJAR, cookie_file);
}
else {
curl_easy_setopt(http->curl, CURLOPT_COOKIEFILE, "");
}
return http;
}
示例14: exec_echo_override
static void exec_echo_override(Pcs pcs, struct params *params)
{
char *text;
size_t sz;
PcsFileInfo *f;
printf("\nOverwrite text to %s\n", params->args[0]);
sz = strlen(params->args[1]);
if (params->is_rc4) {
const char *rc4_key = get_rc4_key2(params);
RC4_CTX rc4;
secure_rc4_setup(&rc4, rc4_key);
text = (char *)pcs_malloc(sz + 1);
memset(text, 0, sz + 1);
RC4(&rc4, sz, (const unsigned char *)params->args[1], (unsigned char *)text);
text[sz] = '\0';
f = pcs_upload_buffer(pcs, params->args[0], PcsTrue, text, sz);
pcs_free(text);
}
else {
text = params->args[1];
f = pcs_upload_buffer(pcs, params->args[0], PcsTrue, text, sz);
}
if (f) {
pcs_fileinfo_destroy(f);
printf("Overwirte success\n", params->args[0]);
} else {
printf("Overwirte failed\n", params->args[0]);
}
}
示例15: va_copy
PCS_API char *pcs_utils_vsprintf(const char *fmt, va_list ap)
{
int cnt, sz=0;
char *buf;
va_list ap_try;
#ifdef WIN32
sz = 4096;
#else
sz = 1024;
#endif
buf = (char*)pcs_malloc(sz);
try_print:
va_copy(ap_try, ap);
cnt = vsnprintf(buf, sz - 1, fmt, ap_try);
va_end(ap_try);
if (cnt > sz) {
pcs_free(buf);
sz *= 2;
buf = (char*)pcs_malloc(sz);
goto try_print;
}
if (cnt < 0) return NULL;
buf[cnt] = '\0';
return buf;
}