int bracketedpaste(char **args) { char *pbuf = bracketedstring(); if (*args) { setsparam(*args, pbuf); } else { int n; ZLE_STRING_T wpaste; wpaste = stringaszleline((zmult == 1) ? pbuf : quotestring(pbuf, NULL, QT_SINGLE_OPTIONAL), 0, &n, NULL, NULL); cuttext(wpaste, n, CUT_REPLACE); if (!(zmod.flags & MOD_VIBUF)) { kct = -1; kctbuf = &cutbuf; zmult = 1; if (region_active) killregion(zlenoargs); yankcs = yankb = zlecs; doinsert(wpaste, n); yanke = zlecs; } free(pbuf); free(wpaste); } return 0; }
/* * This database operates on absolute names. * * Queries are converted into SQL queries and issued synchronously. Errors * are handled really badly. */ static isc_result_t pgsqldb_lookup(const char *zone, const char *name, void *dbdata, dns_sdblookup_t *lookup) { isc_result_t result; struct dbinfo *dbi = dbdata; PGresult *res; char str[1500]; char *canonname; int i; UNUSED(zone); canonname = isc_mem_get(ns_g_mctx, strlen(name) * 2 + 1); if (canonname == NULL) return (ISC_R_NOMEMORY); quotestring(name, canonname); snprintf(str, sizeof(str), "SELECT TTL,RDTYPE,RDATA FROM \"%s\" WHERE " "lower(NAME) = lower('%s')", dbi->table, canonname); isc_mem_put(ns_g_mctx, canonname, strlen(name) * 2 + 1); result = maybe_reconnect(dbi); if (result != ISC_R_SUCCESS) return (result); res = PQexec(dbi->conn, str); if (!res || PQresultStatus(res) != PGRES_TUPLES_OK) { PQclear(res); return (ISC_R_FAILURE); } if (PQntuples(res) == 0) { PQclear(res); return (ISC_R_NOTFOUND); } for (i = 0; i < PQntuples(res); i++) { char *ttlstr = PQgetvalue(res, i, 0); char *type = PQgetvalue(res, i, 1); char *data = PQgetvalue(res, i, 2); dns_ttl_t ttl; char *endp; ttl = strtol(ttlstr, &endp, 10); if (*endp != '\0') { PQclear(res); return (DNS_R_BADTTL); } result = dns_sdb_putrr(lookup, type, ttl, data); if (result != ISC_R_SUCCESS) { PQclear(res); return (ISC_R_FAILURE); } } PQclear(res); return (ISC_R_SUCCESS); }
void addrdata(dns_name_t *name, dns_ttl_t ttl, dns_rdata_t *rdata) { unsigned char namearray[DNS_NAME_MAXTEXT + 1]; unsigned char canonnamearray[2 * DNS_NAME_MAXTEXT + 1]; unsigned char typearray[20]; unsigned char canontypearray[40]; unsigned char dataarray[2048]; unsigned char canondataarray[4096]; isc_buffer_t b; isc_result_t result; PGresult *res; isc_buffer_init(&b, namearray, sizeof(namearray) - 1); result = dns_name_totext(name, ISC_TRUE, &b); check_result(result, "dns_name_totext"); namearray[isc_buffer_usedlength(&b)] = 0; quotestring(namearray, canonnamearray); isc_buffer_init(&b, typearray, sizeof(typearray) - 1); result = dns_rdatatype_totext(rdata->type, &b); check_result(result, "dns_rdatatype_totext"); typearray[isc_buffer_usedlength(&b)] = 0; quotestring(typearray, canontypearray); isc_buffer_init(&b, dataarray, sizeof(dataarray) - 1); result = dns_rdata_totext(rdata, NULL, &b); check_result(result, "dns_rdata_totext"); dataarray[isc_buffer_usedlength(&b)] = 0; quotestring(dataarray, canondataarray); snprintf(str, sizeof(str), "INSERT INTO %s (NAME, TTL, RDTYPE, RDATA)" " VALUES ('%s', %d, '%s', '%s')", dbtable, canonnamearray, ttl, canontypearray, canondataarray); printf("%s\n", str); res = PQexec(conn, str); if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) { fprintf(stderr, "INSERT INTO command failed: %s\n", PQresultErrorMessage(res)); PQclear(res); closeandexit(1); } PQclear(res); }
void getredirs(LinkList redirs) { LinkNode n; static char *fstr[] = { ">", ">|", ">>", ">>|", "&>", "&>|", "&>>", "&>>|", "<>", "<", "<<", "<<-", "<<<", "<&", ">&", NULL /* >&- */, "<", ">" }; taddchr(' '); for (n = firstnode(redirs); n; incnode(n)) { Redir f = (Redir) getdata(n); switch (f->type) { case REDIR_WRITE: case REDIR_WRITENOW: case REDIR_APP: case REDIR_APPNOW: case REDIR_ERRWRITE: case REDIR_ERRWRITENOW: case REDIR_ERRAPP: case REDIR_ERRAPPNOW: case REDIR_READ: case REDIR_READWRITE: case REDIR_HERESTR: case REDIR_MERGEIN: case REDIR_MERGEOUT: case REDIR_INPIPE: case REDIR_OUTPIPE: if (f->varid) { taddchr('{'); taddstr(f->varid); taddchr('}'); } else if (f->fd1 != (IS_READFD(f->type) ? 0 : 1)) taddchr('0' + f->fd1); if (f->type == REDIR_HERESTR && (f->flags & REDIRF_FROM_HEREDOC)) { if (tnewlins) { /* * Strings that came from here-documents are converted * to here strings without quotation, so convert them * back. */ taddstr(fstr[REDIR_HEREDOC]); taddstr(f->here_terminator); taddpending(f->name, f->munged_here_terminator); } else { int fnamelen, sav; taddstr(fstr[REDIR_HERESTR]); /* * Just a quick and dirty representation. * Remove a terminating newline, if any. */ fnamelen = strlen(f->name); if (fnamelen > 0 && f->name[fnamelen-1] == '\n') { sav = 1; f->name[fnamelen-1] = '\0'; } else sav = 0; /* * Strings that came from here-documents are converted * to here strings without quotation, so add that * now. If tokens are present we need to do double quoting. */ if (!has_token(f->name)) { taddchr('\''); taddstr(quotestring(f->name, NULL, QT_SINGLE)); taddchr('\''); } else { taddchr('"'); taddstr(quotestring(f->name, NULL, QT_DOUBLE)); taddchr('"'); } if (sav) f->name[fnamelen-1] = '\n'; } } else { taddstr(fstr[f->type]); if (f->type != REDIR_MERGEIN && f->type != REDIR_MERGEOUT) taddchr(' '); taddstr(f->name); } taddchr(' '); break; #ifdef DEBUG case REDIR_CLOSE: DPUTS(1, "BUG: CLOSE in getredirs()"); taddchr(f->fd1 + '0'); taddstr(">&- "); break; default: DPUTS(1, "BUG: unknown redirection in getredirs()"); #endif } } tptr--; }