QString echoBlock(int tabs, const QString &in) { QStringList pars = in.split('\n', QString::KeepEmptyParts); if(!pars.isEmpty() && pars.last().isEmpty()) pars.removeLast(); QStringList lines; int n; for(n = 0; n < pars.count(); ++n) { QStringList list = wrapString(pars[n], CONF_WRAP); for(int n2 = 0; n2 < list.count(); ++n2) lines.append(list[n2]); } QString str; for(n = 0; n < lines.count(); ++n) { QString out; out.fill(9, tabs); // 9 == tab character if(lines[n].isEmpty()) out += QString("printf \"\\n\"\n"); else out += QString("printf \"%1\\n\"\n").arg(c_escape(lines[n])); str += out; } return str; }
bool str_split (vec<str> *r, const str &s, bool quoted, int sz) { int len = s.len (); if (!len || sz <= 0) return false; const char *bp = s.cstr (); while (len > 0) { int i = min (len, sz); str s (bp, i); r->push_back (quoted ? c_escape (s, true) : s); len -= i; bp += i; } return true; }
/* setopt wrapper for curl_slist options */ CURLcode tool_setopt_slist(CURL *curl, struct GlobalConfig *config, const char *name, CURLoption tag, struct curl_slist *list) { CURLcode ret = CURLE_OK; char *escaped = NULL; bool skip = FALSE; ret = curl_easy_setopt(curl, tag, list); if(!list) skip = TRUE; if(config->libcurl && !skip && !ret) { struct curl_slist *s; int i; /* May need several slist variables, so invent name */ i = ++ easysrc_slist_count; DECL1("struct curl_slist *slist%d;", i); DATA1("slist%d = NULL;", i); CLEAN1("curl_slist_free_all(slist%d);", i); CLEAN1("slist%d = NULL;", i); for(s=list; s; s=s->next) { Curl_safefree(escaped); escaped = c_escape(s->data); if(!escaped) { ret = CURLE_OUT_OF_MEMORY; goto nomem; } DATA3("slist%d = curl_slist_append(slist%d, \"%s\");", i, i, escaped); } CODE2("curl_easy_setopt(hnd, %s, slist%d);", name, i); } nomem: Curl_safefree(escaped); return ret; }
/* setopt wrapper for CURLOPT_HTTPPOST */ CURLcode tool_setopt_httppost(CURL *curl, struct GlobalConfig *config, const char *name, CURLoption tag, struct curl_httppost *post) { CURLcode ret = CURLE_OK; char *escaped = NULL; bool skip = FALSE; ret = curl_easy_setopt(curl, tag, post); if(!post) skip = TRUE; if(config->libcurl && !skip && !ret) { struct curl_httppost *pp, *p; int i; /* May use several httppost lists, if multiple POST actions */ i = ++ easysrc_form_count; DECL1("struct curl_httppost *post%d;", i); DATA1("post%d = NULL;", i); CLEAN1("curl_formfree(post%d);", i); CLEAN1("post%d = NULL;", i); if(i == 1) DECL0("struct curl_httppost *postend;"); DATA0("postend = NULL;"); for(p=post; p; p=p->next) { DATA1("curl_formadd(&post%d, &postend,", i); DATA1(" CURLFORM_COPYNAME, \"%s\",", p->name); for(pp=p; pp; pp=pp->more) { /* May be several files uploaded for one name; * these are linked through the 'more' pointer */ Curl_safefree(escaped); escaped = c_escape(pp->contents); if(!escaped) { ret = CURLE_OUT_OF_MEMORY; goto nomem; } if(pp->flags & CURL_HTTPPOST_FILENAME) { /* file upload as for -F @filename */ DATA1(" CURLFORM_FILE, \"%s\",", escaped); } else if(pp->flags & CURL_HTTPPOST_READFILE) { /* content from file as for -F <filename */ DATA1(" CURLFORM_FILECONTENT, \"%s\",", escaped); } else DATA1(" CURLFORM_COPYCONTENTS, \"%s\",", escaped); if(pp->showfilename) { Curl_safefree(escaped); escaped = c_escape(pp->showfilename); if(!escaped) { ret = CURLE_OUT_OF_MEMORY; goto nomem; } DATA1(" CURLFORM_FILENAME, \"%s\",", escaped); } if(pp->contenttype) { Curl_safefree(escaped); escaped = c_escape(pp->contenttype); if(!escaped) { ret = CURLE_OUT_OF_MEMORY; goto nomem; } DATA1(" CURLFORM_CONTENTTYPE, \"%s\",", escaped); } } DATA0(" CURLFORM_END);"); } CODE2("curl_easy_setopt(hnd, %s, post%d);", name, i); } nomem: Curl_safefree(escaped); return ret; }