From 4f49b16079b27d7ce633619e4cddfdf2bffbc952 Mon Sep 17 00:00:00 2001 From: cashmere Date: Fri, 4 Sep 2026 09:05:24 +0200 Subject: initial commit --- src/configure.c | 1157 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1157 insertions(+) create mode 100644 src/configure.c (limited to 'src/configure.c') diff --git a/src/configure.c b/src/configure.c new file mode 100644 index 0000000..353ebd6 --- /dev/null +++ b/src/configure.c @@ -0,0 +1,1157 @@ +/* +** Copyright (c) 2008 D. Richard Hipp +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the Simplified BSD License (also +** known as the "2-Clause License" or "FreeBSD License".) +** +** This program is distributed in the hope that it will be useful, +** but without any warranty; without even the implied warranty of +** merchantability or fitness for a particular purpose. +** +** Author contact information: +** drh@hwaci.com +** http://www.hwaci.com/drh/ +** +******************************************************************************* +** +** This file contains code used to manage repository configurations. +** +** By "repository configure" we mean the local state of a repository +** distinct from the versioned files. +*/ +#include "config.h" +#include "configure.h" +#include + +#if INTERFACE +/* +** Configuration transfers occur in groups. These are the allowed +** groupings: +*/ +#define CONFIGSET_CSS 0x000001 /* Style sheet only */ +#define CONFIGSET_SKIN 0x000002 /* WWW interface appearance */ +#define CONFIGSET_TKT 0x000004 /* Ticket configuration */ +#define CONFIGSET_PROJ 0x000008 /* Project name */ +#define CONFIGSET_SHUN 0x000010 /* Shun settings */ +#define CONFIGSET_USER 0x000020 /* The USER table */ +#define CONFIGSET_ADDR 0x000040 /* The CONCEALED table */ +#define CONFIGSET_XFER 0x000080 /* Transfer configuration */ +#define CONFIGSET_ALIAS 0x000100 /* URL Aliases */ +#define CONFIGSET_SCRIBER 0x000200 /* Email subscribers */ +#define CONFIGSET_IWIKI 0x000400 /* Interwiki codes */ +#define CONFIGSET_ALL 0x0007ff /* Everything */ + +#define CONFIGSET_OVERWRITE 0x100000 /* Causes overwrite instead of merge */ + +/* +** This mask is used for the common TH1 configuration settings (i.e. those +** that are not specific to one particular subsystem, such as the transfer +** subsystem). +*/ +#define CONFIGSET_TH1 (CONFIGSET_SKIN|CONFIGSET_TKT|CONFIGSET_XFER) + +#endif /* INTERFACE */ + +/* +** Names of the configuration sets +*/ +static struct { + const char *zName; /* Name of the configuration set */ + int groupMask; /* Mask for that configuration set */ + const char *zHelp; /* What it does */ +} aGroupName[] = { + { "/email", CONFIGSET_ADDR, "Concealed email addresses in tickets" }, + { "/project", CONFIGSET_PROJ, "Project name and description" }, + { "/skin", CONFIGSET_SKIN | CONFIGSET_CSS, + "Web interface appearance settings" }, + { "/css", CONFIGSET_CSS, "Style sheet" }, + { "/shun", CONFIGSET_SHUN, "List of shunned artifacts" }, + { "/ticket", CONFIGSET_TKT, "Ticket setup", }, + { "/user", CONFIGSET_USER, "Users and privilege settings" }, + { "/xfer", CONFIGSET_XFER, "Transfer setup", }, + { "/alias", CONFIGSET_ALIAS, "URL Aliases", }, + { "/subscriber", CONFIGSET_SCRIBER, "Email notification subscriber list" }, + { "/interwiki", CONFIGSET_IWIKI, "Inter-wiki link prefixes" }, + { "/all", CONFIGSET_ALL, "All of the above" }, +}; + + +/* +** The following is a list of settings that we are willing to +** transfer. +** +** Setting names that begin with an alphabetic characters refer to +** single entries in the CONFIG table. Setting names that begin with +** "@" are for special processing. +*/ +static struct { + const char *zName; /* Name of the configuration parameter */ + int groupMask; /* Which config groups is it part of */ +} aConfig[] = { + { "css", CONFIGSET_CSS }, + { "header", CONFIGSET_SKIN }, + { "mainmenu", CONFIGSET_SKIN }, + { "footer", CONFIGSET_SKIN }, + { "details", CONFIGSET_SKIN }, + { "js", CONFIGSET_SKIN }, + { "default-skin", CONFIGSET_SKIN }, + { "logo-mimetype", CONFIGSET_SKIN }, + { "logo-image", CONFIGSET_SKIN }, + { "background-mimetype", CONFIGSET_SKIN }, + { "background-image", CONFIGSET_SKIN }, + { "icon-mimetype", CONFIGSET_SKIN }, + { "icon-image", CONFIGSET_SKIN }, + { "timeline-date-format", CONFIGSET_SKIN }, + { "timeline-default-style", CONFIGSET_SKIN }, + { "timeline-dwelltime", CONFIGSET_SKIN }, + { "timeline-closetime", CONFIGSET_SKIN }, + { "timeline-hard-newlines", CONFIGSET_SKIN }, + { "timeline-max-comment", CONFIGSET_SKIN }, + { "timeline-plaintext", CONFIGSET_SKIN }, + { "timeline-truncate-at-blank", CONFIGSET_SKIN }, + { "timeline-tslink-info", CONFIGSET_SKIN }, + { "timeline-utc", CONFIGSET_SKIN }, + { "adunit", CONFIGSET_SKIN }, + { "adunit-omit-if-admin", CONFIGSET_SKIN }, + { "adunit-omit-if-user", CONFIGSET_SKIN }, + { "default-csp", CONFIGSET_SKIN }, + { "sitemap-extra", CONFIGSET_SKIN }, + { "safe-html", CONFIGSET_SKIN }, + +#ifdef FOSSIL_ENABLE_TH1_HOOKS + { "th1-hooks", CONFIGSET_TH1 }, +#endif + { "th1-uri-regexp", CONFIGSET_TH1 }, + + { "project-name", CONFIGSET_PROJ }, + { "short-project-name", CONFIGSET_PROJ }, + { "project-description", CONFIGSET_PROJ }, + { "index-page", CONFIGSET_PROJ }, + { "manifest", CONFIGSET_PROJ }, + { "binary-glob", CONFIGSET_PROJ }, + { "clean-glob", CONFIGSET_PROJ }, + { "ignore-glob", CONFIGSET_PROJ }, + { "keep-glob", CONFIGSET_PROJ }, + { "crlf-glob", CONFIGSET_PROJ }, + { "crnl-glob", CONFIGSET_PROJ }, + { "encoding-glob", CONFIGSET_PROJ }, + { "empty-dirs", CONFIGSET_PROJ }, + { "dotfiles", CONFIGSET_PROJ }, + { "parent-project-code", CONFIGSET_PROJ }, + { "parent-project-name", CONFIGSET_PROJ }, + { "hash-policy", CONFIGSET_PROJ }, + { "comment-format", CONFIGSET_PROJ }, + { "mimetypes", CONFIGSET_PROJ }, + { "forbid-delta-manifests", CONFIGSET_PROJ }, + { "mv-rm-files", CONFIGSET_PROJ }, + { "forum-statuses", CONFIGSET_PROJ }, + { "path-to-tag", CONFIGSET_PROJ }, + { "ticket-table", CONFIGSET_TKT }, + { "ticket-common", CONFIGSET_TKT }, + { "ticket-change", CONFIGSET_TKT }, + { "ticket-newpage", CONFIGSET_TKT }, + { "ticket-viewpage", CONFIGSET_TKT }, + { "ticket-editpage", CONFIGSET_TKT }, + { "ticket-reportlist", CONFIGSET_TKT }, + { "ticket-report-template", CONFIGSET_TKT }, + { "ticket-key-template", CONFIGSET_TKT }, + { "ticket-title-expr", CONFIGSET_TKT }, + { "ticket-closed-expr", CONFIGSET_TKT }, + { "@reportfmt", CONFIGSET_TKT }, + + { "@user", CONFIGSET_USER }, + { "user-color-map", CONFIGSET_USER }, + + { "@concealed", CONFIGSET_ADDR }, + + { "@shun", CONFIGSET_SHUN }, + + { "@alias", CONFIGSET_ALIAS }, + + { "@subscriber", CONFIGSET_SCRIBER }, + + { "@interwiki", CONFIGSET_IWIKI }, + + { "xfer-common-script", CONFIGSET_XFER }, + { "xfer-push-script", CONFIGSET_XFER }, + { "xfer-commit-script", CONFIGSET_XFER }, + { "xfer-ticket-script", CONFIGSET_XFER }, + +}; +static int iConfig = 0; + +/* +** Return name of first configuration property matching the given mask. +*/ +const char *configure_first_name(int iMask){ + iConfig = 0; + return configure_next_name(iMask); +} +const char *configure_next_name(int iMask){ + if( iConfig==0 && (iMask & CONFIGSET_ALL)==CONFIGSET_ALL ){ + iConfig = count(aGroupName); + return "/all"; + } + while( iConfig2 && zName[0]=='\'' && zName[n-1]=='\'' ){ + char * zCpy; + zName++; + n -= 2; + zCpy = fossil_strndup(zName, (ssize_t)n); + pSet = db_find_setting(zCpy, 0); + fossil_free(zCpy); + }else{ + pSet = db_find_setting(zName, 0); + } + if( pSet && pSet->sensitive ){ + /* https://fossil-scm.org/forum/forumpost/6179500deadf6ec7 */ + return 0; + } + for(i=0; i=count(aType) ) return; + + while( blob_token(pContent, &name) && blob_sqltoken(pContent, &value) ){ + char *z = blob_terminate(&name); + if( !safeSql(z) ) return; + if( nToken>0 ){ + for(jj=0; jj=aType[ii].nField ) continue; + }else{ + if( !safeInt(z) ) return; + } + azToken[nToken++] = z; + azToken[nToken++] = z = blob_terminate(&value); + if( !safeSql(z) ) return; + if( nToken>=count(azToken)-1 ) break; + } + if( nToken<2 ) return; + if( aType[ii].zName[0]=='/' ){ + thisMask = configure_is_exportable(azToken[1]); + if( 0==thisMask ){ + fossil_warning("Skipping non-exportable setting: %s = %s", + azToken[1], nToken>3 ? azToken[3] : "?"); + /* Will be skipped below */ + } + }else{ + thisMask = configure_is_exportable(aType[ii].zName); + } + if( (thisMask & groupMask)==0 ) return; + if( (thisMask & checkMask)!=0 ){ + if( (thisMask & CONFIGSET_SCRIBER)!=0 ){ + alert_schema(1); + } + checkMask &= ~thisMask; + } + + blob_zero(&sql); + if( groupMask & CONFIGSET_OVERWRITE ){ + if( (thisMask & configHasBeenReset)==0 && aType[ii].zName[0]!='/' ){ + db_multi_exec("DELETE FROM \"%w\"", &aType[ii].zName[1]); + configHasBeenReset |= thisMask; + } + blob_append_sql(&sql, "REPLACE INTO "); + }else{ + blob_append_sql(&sql, "INSERT OR IGNORE INTO "); + } + blob_append_sql(&sql, "\"%w\"(\"%w\",mtime", + &zName[1], aType[ii].zPrimKey); + if( fossil_stricmp(zName,"/subscriber")==0 ) alert_schema(0); + for(jj=2; jj=%lld", iStart); + while( db_step(&q)==SQLITE_ROW ){ + blob_appendf(&rec,"%s %s scom %s", + db_column_text(&q, 0), + db_column_text(&q, 1), + db_column_text(&q, 2) + ); + blob_appendf(pOut, "config /shun %d\n%s\n", + blob_size(&rec), blob_str(&rec)); + nCard++; + blob_reset(&rec); + } + db_finalize(&q); + } + if( groupMask & CONFIGSET_USER ){ + if( db_table_has_column("repository","user","jx") ){ + db_prepare(&q, "SELECT mtime, quote(login), quote(pw), quote(cap)," + " quote(info), quote(photo), quote(jx) FROM user" + " WHERE mtime>=%lld", iStart); + }else{ + db_prepare(&q, "SELECT mtime, quote(login), quote(pw), quote(cap)," + " quote(info), quote(photo), 'NULL' FROM user" + " WHERE mtime>=%lld", iStart); + } + while( db_step(&q)==SQLITE_ROW ){ + const char *z; + blob_appendf(&rec,"%s %s", db_column_text(&q,0), db_column_text(&q,1)); + z = db_column_text(&q,2); + if( strcmp(z,"NULL")!=0 ) blob_appendf(&rec," pw %s", z); + z = db_column_text(&q,3); + if( strcmp(z,"NULL")!=0 ) blob_appendf(&rec," cap %s", z); + z = db_column_text(&q,4); + if( strcmp(z,"NULL")!=0 ) blob_appendf(&rec," info %s", z); + z = db_column_text(&q,5); + if( strcmp(z,"NULL")!=0 ) blob_appendf(&rec," photo %s", z); + z = db_column_text(&q,6); + if( strcmp(z,"NULL")!=0 ) blob_appendf(&rec," jx %s", z); + blob_appendf(pOut, "config /user %d\n%s\n", + blob_size(&rec), blob_str(&rec)); + nCard++; + blob_reset(&rec); + } + db_finalize(&q); + } + if( groupMask & CONFIGSET_TKT ){ + if( db_table_has_column("repository","reportfmt","jx") ){ + db_prepare(&q, "SELECT mtime, quote(title), quote(owner), quote(cols)," + " quote(sqlcode), quote(jx) FROM reportfmt" + " WHERE mtime>=%lld", iStart); + }else{ + db_prepare(&q, "SELECT mtime, quote(title), quote(owner), quote(cols)," + " quote(sqlcode), 'NULL' FROM reportfmt" + " WHERE mtime>=%lld", iStart); + } + while( db_step(&q)==SQLITE_ROW ){ + const char *z; + blob_appendf(&rec,"%s %s", db_column_text(&q,0), db_column_text(&q,1)); + z = db_column_text(&q,2); + if( strcmp(z,"NULL")!=0 ) blob_appendf(&rec," owner %s", z); + z = db_column_text(&q,3); + if( strcmp(z,"NULL")!=0 ) blob_appendf(&rec," cols %s", z); + z = db_column_text(&q,4); + if( strcmp(z,"NULL")!=0 ) blob_appendf(&rec," sqlcode %s", z); + z = db_column_text(&q,5); + if( strcmp(z,"NULL")!=0 ) blob_appendf(&rec," jx %s", z); + blob_appendf(pOut, "config /reportfmt %d\n%s\n", + blob_size(&rec), blob_str(&rec)); + nCard++; + blob_reset(&rec); + } + db_finalize(&q); + } + if( groupMask & CONFIGSET_ADDR ){ + db_prepare(&q, "SELECT mtime, quote(hash), quote(content) FROM concealed" + " WHERE mtime>=%lld", iStart); + while( db_step(&q)==SQLITE_ROW ){ + blob_appendf(&rec,"%s %s content %s", + db_column_text(&q, 0), + db_column_text(&q, 1), + db_column_text(&q, 2) + ); + blob_appendf(pOut, "config /concealed %d\n%s\n", + blob_size(&rec), blob_str(&rec)); + nCard++; + blob_reset(&rec); + } + db_finalize(&q); + } + if( groupMask & CONFIGSET_ALIAS ){ + db_prepare(&q, "SELECT mtime, quote(name), quote(value) FROM config" + " WHERE name GLOB 'walias:/*' AND mtime>=%lld", iStart); + while( db_step(&q)==SQLITE_ROW ){ + blob_appendf(&rec,"%s %s value %s", + db_column_text(&q, 0), + db_column_text(&q, 1), + db_column_text(&q, 2) + ); + blob_appendf(pOut, "config /config %d\n%s\n", + blob_size(&rec), blob_str(&rec)); + nCard++; + blob_reset(&rec); + } + db_finalize(&q); + } + if( groupMask & CONFIGSET_IWIKI ){ + db_prepare(&q, "SELECT mtime, quote(name), quote(value) FROM config" + " WHERE name GLOB 'interwiki:*' AND mtime>=%lld", iStart); + while( db_step(&q)==SQLITE_ROW ){ + blob_appendf(&rec,"%s %s value %s", + db_column_text(&q, 0), + db_column_text(&q, 1), + db_column_text(&q, 2) + ); + blob_appendf(pOut, "config /config %d\n%s\n", + blob_size(&rec), blob_str(&rec)); + nCard++; + blob_reset(&rec); + } + db_finalize(&q); + } + if( (groupMask & CONFIGSET_SCRIBER)!=0 + && db_table_exists("repository","subscriber") + ){ + db_prepare(&q, "SELECT mtime, quote(semail)," + " quote(suname), quote(sdigest)," + " quote(sdonotcall), quote(ssub)," + " quote(sctime), quote(smip)" + " FROM subscriber WHERE sverified" + " AND mtime>=%lld", iStart); + while( db_step(&q)==SQLITE_ROW ){ + blob_appendf(&rec, + "%lld %s suname %s sdigest %s sdonotcall %s ssub %s" + " sctime %s smip %s", + db_column_int64(&q, 0), /* mtime */ + db_column_text(&q, 1), /* semail (PK) */ + db_column_text(&q, 2), /* suname */ + db_column_text(&q, 3), /* sdigest */ + db_column_text(&q, 4), /* sdonotcall */ + db_column_text(&q, 5), /* ssub */ + db_column_text(&q, 6), /* sctime */ + db_column_text(&q, 7) /* smip */ + ); + blob_appendf(pOut, "config /subscriber %d\n%s\n", + blob_size(&rec), blob_str(&rec)); + nCard++; + blob_reset(&rec); + } + db_finalize(&q); + } + db_prepare(&q, "SELECT mtime, quote(name), quote(value) FROM config" + " WHERE name=:name AND mtime>=%lld", iStart); + for(ii=0; iisensitive ){ + /* https://fossil-scm.org/forum/forumpost/6179500deadf6ec7 */ + continue; + } + db_bind_text(&q, ":name", aConfig[ii].zName); + while( db_step(&q)==SQLITE_ROW ){ + blob_appendf(&rec,"%s %s value %s", + db_column_text(&q, 0), + db_column_text(&q, 1), + db_column_text(&q, 2) + ); + blob_appendf(pOut, "config /config %d\n%s\n", + blob_size(&rec), blob_str(&rec)); + nCard++; + blob_reset(&rec); + } + db_reset(&q); + } + } + db_finalize(&q); + return nCard; +} + +/* +** Identify a configuration group by name. Return its mask. +** Throw an error if no match. +*/ +int configure_name_to_mask(const char *z, int notFoundIsFatal){ + int i; + int n = strlen(z); + for(i=0; i fossil configuration export AREA FILENAME +** +** Write to FILENAME exported configuration information for AREA. +** AREA can be one of: +** +** all email interwiki project shun skin +** ticket user alias subscriber +** +** > fossil configuration import FILENAME +** +** Read a configuration from FILENAME, overwriting the current +** configuration. +** +** > fossil configuration merge FILENAME +** +** Read a configuration from FILENAME and merge its values into +** the current configuration. Existing values take priority over +** values read from FILENAME. +** +** > fossil configuration pull AREA ?URL? +** +** Pull and install the configuration from a different server +** identified by URL. If no URL is specified, then the default +** server is used. Use the --overwrite flag to completely +** replace local settings with content received from URL. +** +** > fossil configuration push AREA ?URL? +** +** Push the local configuration into the remote server identified +** by URL. Admin privilege is required on the remote server for +** this to work. When the same record exists both locally and on +** the remote end, the one that was most recently changed wins. +** +** > fossil configuration reset AREA +** +** Restore the configuration to the default. AREA as above. +** +** > fossil configuration sync AREA ?URL? +** +** Synchronize configuration changes in the local repository with +** the remote repository at URL. +** +** Options: +** --proxy PROXY Use PROXY as http proxy during sync operation +** (used by pull, push and sync subcommands) +** -R|--repository REPO Affect repository REPO with changes +** +** See also: [[settings]], [[unset]] +*/ +void configuration_cmd(void){ + int n; + const char *zMethod; + db_find_and_open_repository(0, 0); + db_open_config(0, 0); + if( g.argc<3 ){ + usage("SUBCOMMAND ..."); + } + zMethod = g.argv[2]; + n = strlen(zMethod); + if( strncmp(zMethod, "export", n)==0 ){ + int mask; + const char *zSince = find_option("since",0,1); + sqlite3_int64 iStart; + if( g.argc!=5 ){ + usage("export AREA FILENAME"); + } + mask = configure_name_to_mask(g.argv[3], 1); + if( zSince ){ + iStart = db_multi_exec( + "SELECT coalesce(strftime('%%s',%Q),strftime('%%s','now',%Q))+0", + zSince, zSince + ); + }else{ + iStart = 0; + } + export_config(mask, g.argv[3], iStart, g.argv[4]); + }else + if( strncmp(zMethod, "import", n)==0 + || strncmp(zMethod, "merge", n)==0 ){ + Blob in; + int groupMask; + if( g.argc!=4 ) usage(mprintf("%s FILENAME",zMethod)); + blob_read_from_file(&in, g.argv[3], ExtFILE); + db_begin_transaction(); + if( zMethod[0]=='i' ){ + groupMask = CONFIGSET_ALL | CONFIGSET_OVERWRITE; + }else{ + groupMask = CONFIGSET_ALL; + } + db_unprotect(PROTECT_USER); + configure_receive_all(&in, groupMask); + db_protect_pop(); + db_end_transaction(0); + }else + if( strncmp(zMethod, "pull", n)==0 + || strncmp(zMethod, "push", n)==0 + || strncmp(zMethod, "sync", n)==0 + ){ + int mask; + const char *zServer = 0; + int overwriteFlag = 0; + + if( strncmp(zMethod,"pull",n)==0 ){ + overwriteFlag = find_option("overwrite",0,0)!=0; + } + url_proxy_options(); + if( g.argc!=4 && g.argc!=5 ){ + usage(mprintf("%s AREA ?URL?", zMethod)); + } + mask = configure_name_to_mask(g.argv[3], 1); + if( g.argc==5 ){ + zServer = g.argv[4]; + } + url_parse(zServer, URL_PROMPT_PW|URL_USE_CONFIG); + if( g.url.protocol==0 ) fossil_fatal("no server URL specified"); + user_select(); + url_enable_proxy("via proxy: "); + g.zHttpAuth = get_httpauth(); + if( overwriteFlag ) mask |= CONFIGSET_OVERWRITE; + if( strncmp(zMethod, "push", n)==0 ){ + client_sync(0,0,(unsigned)mask,0,0); + }else if( strncmp(zMethod, "pull", n)==0 ){ + if( overwriteFlag ) db_unprotect(PROTECT_USER); + client_sync(0,(unsigned)mask,0,0,0); + if( overwriteFlag ) db_protect_pop(); + }else{ + client_sync(0,(unsigned)mask,(unsigned)mask,0,0); + } + }else + if( strncmp(zMethod, "reset", n)==0 ){ + int mask, i; + char *zBackup; + if( g.argc!=4 ) usage("reset AREA"); + mask = configure_name_to_mask(g.argv[3], 1); + zBackup = db_text(0, + "SELECT strftime('config-backup-%%Y%%m%%d%%H%%M%%f','now')"); + db_begin_transaction(); + export_config(mask, g.argv[3], 0, zBackup); + for(i=0; i=3 ){ + zPattern = g.argv[2]; + } + blob_init(&sql,0,0); + blob_appendf(&sql, "SELECT name, value, datetime(mtime,'unixepoch')" + " FROM config"); + if( zPattern ){ + blob_appendf(&sql, " WHERE name GLOB %Q", zPattern); + } + if( showMtime ){ + blob_appendf(&sql, " ORDER BY mtime, name"); + }else{ + blob_appendf(&sql, " ORDER BY name"); + } + db_prepare(&q, "%s", blob_str(&sql)/*safe-for-%s*/); + blob_reset(&sql); +#define MX_VAL 40 +#define MX_NM 28 +#define MX_LONGNM 60 + while( db_step(&q)==SQLITE_ROW ){ + const char *zName = db_column_text(&q,0); + int nName = db_column_bytes(&q,0); + const char *zValue = db_column_text(&q,1); + int szValue = db_column_bytes(&q,1); + const char *zMTime = db_column_text(&q,2); + for(i=j=0; j=' ' && c<='~' ){ + zTrans[j++] = c; + }else{ + zTrans[j++] = '\\'; + if( c=='\n' ){ + zTrans[j++] = 'n'; + }else if( c=='\r' ){ + zTrans[j++] = 'r'; + }else if( c=='\t' ){ + zTrans[j++] = 't'; + }else{ + zTrans[j++] = '0' + ((c>>6)&7); + zTrans[j++] = '0' + ((c>>3)&7); + zTrans[j++] = '0' + (c&7); + } + } + } + zTrans[j] = 0; + if( i=4 ? g.argv[3] : "-"; + n = db_int(0, "SELECT count(*) FROM config WHERE name GLOB %Q", zVar); + if( n==0 ){ + fossil_fatal("no match for %Q", zVar); + } + if( n>1 ){ + fossil_fatal("multiple matches: %s", + db_text(0, "SELECT group_concat(quote(name),', ') FROM (" + " SELECT name FROM config WHERE name GLOB %Q ORDER BY 1)", + zVar)); + } + blob_init(&x,0,0); + db_blob(&x, "SELECT value FROM config WHERE name GLOB %Q", zVar); + blob_write_to_file(&x, zFile); +} + +/* +** COMMAND: test-var-set +** +** Usage: %fossil test-var-set VAR ?VALUE? ?--file FILE? +** +** Store VALUE or the content of FILE (exactly one of which must be +** supplied) into variable VAR. Use a FILE of "-" to read from +** standard input. +** +** WARNING: changing the value of a variable can interfere with the +** operation of Fossil. Be sure you know what you are doing. +** +** Use "--blob FILE" instead of "--file FILE" to load a binary blob +** such as a GIF. +*/ +void test_var_set_cmd(void){ + const char *zVar; + const char *zFile; + const char *zBlob; + Blob x; + Stmt ins; + zFile = find_option("file",0,1); + zBlob = find_option("blob",0,1); + db_find_and_open_repository(OPEN_ANY_SCHEMA, 0); + verify_all_options(); + if( g.argc<3 || (zFile==0 && zBlob==0 && g.argc<4) ){ + usage("VAR ?VALUE? ?--file FILE?"); + } + zVar = g.argv[2]; + if( zFile ){ + if( zBlob ) fossil_fatal("cannot do both --file or --blob"); + blob_read_from_file(&x, zFile, ExtFILE); + }else if( zBlob ){ + blob_read_from_file(&x, zBlob, ExtFILE); + }else{ + blob_init(&x,g.argv[3],-1); + } + db_unprotect(PROTECT_CONFIG); + db_prepare(&ins, + "REPLACE INTO config(name,value,mtime)" + "VALUES(%Q,:val,now())", zVar); + if( zBlob ){ + db_bind_blob(&ins, ":val", &x); + }else{ + db_bind_text(&ins, ":val", blob_str(&x)); + } + db_step(&ins); + db_finalize(&ins); + db_protect_pop(); + blob_reset(&x); +} -- cgit v1.3.1