| | @@ -61,29 +61,50 @@ |
| 61 | 61 | ** transfer. |
| 62 | 62 | */ |
| 63 | 63 | static struct { |
| 64 | 64 | const char *zName; /* Name of the configuration parameter */ |
| 65 | 65 | int groupMask; /* Which config groups is it part of */ |
| 66 | | -} aSafeConfig[] = { |
| 66 | +} aConfig[] = { |
| 67 | 67 | { "css", CONFIGSET_SKIN }, |
| 68 | 68 | { "header", CONFIGSET_SKIN }, |
| 69 | 69 | { "footer", CONFIGSET_SKIN }, |
| 70 | 70 | { "project-name", CONFIGSET_PROJ }, |
| 71 | 71 | { "project-description", CONFIGSET_PROJ }, |
| 72 | 72 | { "index-page", CONFIGSET_SKIN }, |
| 73 | 73 | { "timeline-block-markup", CONFIGSET_SKIN }, |
| 74 | 74 | { "timeline-max-comment", CONFIGSET_SKIN }, |
| 75 | 75 | }; |
| 76 | +static int iConfig = 0; |
| 77 | + |
| 78 | +/* |
| 79 | +** Return name of first configuration property matching the given mask. |
| 80 | +*/ |
| 81 | +const char *configure_first_name(int iMask){ |
| 82 | + iConfig = 0; |
| 83 | + return configure_next_name(iMask); |
| 84 | +} |
| 85 | +const char *configure_next_name(int iMask){ |
| 86 | + while( iConfig<count(aConfig) ){ |
| 87 | + if( aConfig[iConfig].groupMask & iMask ){ |
| 88 | + return aConfig[iConfig++].zName; |
| 89 | + }else{ |
| 90 | + iConfig++; |
| 91 | + } |
| 92 | + } |
| 93 | + return 0; |
| 94 | +} |
| 76 | 95 | |
| 77 | 96 | /* |
| 78 | 97 | ** Return TRUE if a particular configuration parameter zName is |
| 79 | 98 | ** safely exportable. |
| 80 | 99 | */ |
| 81 | 100 | int configure_is_exportable(const char *zName){ |
| 82 | 101 | int i; |
| 83 | | - for(i=0; i<count(aSafeConfig); i++){ |
| 84 | | - if( strcmp(zName, aSafeConfig[i].zName)==0 ) return 1; |
| 102 | + for(i=0; i<count(aConfig); i++){ |
| 103 | + if( strcmp(zName, aConfig[i].zName)==0 ){ |
| 104 | + return aConfig[i].groupMask; |
| 105 | + } |
| 85 | 106 | } |
| 86 | 107 | return 0; |
| 87 | 108 | } |
| 88 | 109 | |
| 89 | 110 | /* |
| | @@ -102,39 +123,39 @@ |
| 102 | 123 | return 0; |
| 103 | 124 | } |
| 104 | 125 | |
| 105 | 126 | |
| 106 | 127 | /* |
| 107 | | -** COMMAND: configure |
| 128 | +** COMMAND: configuration |
| 108 | 129 | ** |
| 109 | 130 | ** Usage: %fossil configure METHOD ... |
| 110 | 131 | ** |
| 111 | 132 | ** Where METHOD is one of: export import pull reset. All methods |
| 112 | 133 | ** accept the -R or --repository option to specific a repository. |
| 113 | 134 | ** |
| 114 | | -** %fossil config export AREA FILENAME |
| 135 | +** %fossil configuration export AREA FILENAME |
| 115 | 136 | ** |
| 116 | 137 | ** Write to FILENAME exported configuraton information for AREA. |
| 117 | 138 | ** AREA can be one of: all ticket skin project |
| 118 | 139 | ** |
| 119 | | -** %fossil config import FILENAME |
| 140 | +** %fossil configuration import FILENAME |
| 120 | 141 | ** |
| 121 | 142 | ** Read a configuration from FILENAME, overwriting the current |
| 122 | 143 | ** configuration. Warning: Do not read a configuration from |
| 123 | 144 | ** an untrusted source since the configuration is not checked |
| 124 | 145 | ** for safety and can introduce security threats. |
| 125 | 146 | ** |
| 126 | | -** %fossil config pull AREA URL |
| 147 | +** %fossil configuration pull AREA URL |
| 127 | 148 | ** |
| 128 | 149 | ** Pull and install the configuration from a different server |
| 129 | 150 | ** identified by URL. AREA is as in "export". |
| 130 | 151 | ** |
| 131 | | -** %fossil configure reset AREA |
| 152 | +** %fossil configuration reset AREA |
| 132 | 153 | ** |
| 133 | 154 | ** Restore the configuration to the default. AREA as above. |
| 134 | 155 | */ |
| 135 | | -void configure_cmd(void){ |
| 156 | +void configuration_cmd(void){ |
| 136 | 157 | int n; |
| 137 | 158 | const char *zMethod; |
| 138 | 159 | if( g.argc<3 ){ |
| 139 | 160 | usage("METHOD ..."); |
| 140 | 161 | } |
| | @@ -158,39 +179,63 @@ |
| 158 | 179 | "SELECT 'REPLACE INTO config(name,value) VALUES('''" |
| 159 | 180 | " || name || ''',' || quote(value) || ');'" |
| 160 | 181 | " FROM config WHERE name IN " |
| 161 | 182 | ); |
| 162 | 183 | zSep = "("; |
| 163 | | - for(i=0; i<count(aSafeConfig); i++){ |
| 164 | | - if( aSafeConfig[i].groupMask & mask ){ |
| 165 | | - blob_appendf(&sql, "%s'%s'", zSep, aSafeConfig[i].zName); |
| 184 | + for(i=0; i<count(aConfig); i++){ |
| 185 | + if( aConfig[i].groupMask & mask ){ |
| 186 | + blob_appendf(&sql, "%s'%s'", zSep, aConfig[i].zName); |
| 166 | 187 | zSep = ","; |
| 167 | 188 | } |
| 168 | 189 | } |
| 169 | 190 | blob_appendf(&sql, ") ORDER BY name"); |
| 170 | 191 | db_prepare(&q, blob_str(&sql)); |
| 171 | 192 | blob_reset(&sql); |
| 172 | 193 | blob_appendf(&out, |
| 173 | 194 | "-- The \"%s\" configuration exported from\n" |
| 174 | 195 | "-- repository \"%s\"\n" |
| 175 | | - "-- on %s\nBEGIN;\n", |
| 196 | + "-- on %s\n", |
| 176 | 197 | g.argv[3], g.zRepositoryName, |
| 177 | 198 | db_text(0, "SELECT datetime('now')") |
| 178 | 199 | ); |
| 179 | 200 | while( db_step(&q)==SQLITE_ROW ){ |
| 180 | 201 | blob_appendf(&out, "%s\n", db_column_text(&q, 0)); |
| 181 | 202 | } |
| 182 | 203 | db_finalize(&q); |
| 183 | | - blob_appendf(&out, "COMMIT;\n"); |
| 184 | 204 | blob_write_to_file(&out, g.argv[4]); |
| 185 | 205 | blob_reset(&out); |
| 186 | 206 | }else |
| 187 | 207 | if( strncmp(zMethod, "import", n)==0 ){ |
| 208 | + Blob in; |
| 209 | + if( g.argc!=4 ) usage("import FILENAME"); |
| 210 | + blob_read_from_file(&in, g.argv[3]); |
| 211 | + db_begin_transaction(); |
| 212 | + db_multi_exec("%s", blob_str(&in)); |
| 213 | + db_end_transaction(0); |
| 188 | 214 | }else |
| 189 | 215 | if( strncmp(zMethod, "pull", n)==0 ){ |
| 216 | + int mask; |
| 217 | + url_proxy_options(); |
| 218 | + if( g.argc!=5 ) usage("pull AREA URL"); |
| 219 | + mask = find_area(g.argv[3]); |
| 220 | + url_parse(g.argv[4]); |
| 221 | + if( g.urlIsFile ){ |
| 222 | + fossil_fatal("network sync only"); |
| 223 | + } |
| 224 | + user_select(); |
| 225 | + client_sync(0,0,0,mask); |
| 190 | 226 | }else |
| 191 | 227 | if( strncmp(zMethod, "reset", n)==0 ){ |
| 228 | + int mask, i; |
| 229 | + if( g.argc!=4 ) usage("reset AREA"); |
| 230 | + mask = find_area(g.argv[3]); |
| 231 | + db_begin_transaction(); |
| 232 | + for(i=0; i<count(aConfig); i++){ |
| 233 | + if( (aConfig[i].groupMask & mask)==0 ) continue; |
| 234 | + db_multi_exec("DELETE FROM config WHERE name=%Q", aConfig[i].zName); |
| 235 | + } |
| 236 | + db_end_transaction(0); |
| 192 | 237 | }else |
| 193 | 238 | { |
| 194 | 239 | fossil_fatal("METHOD should be one of: export import pull reset"); |
| 195 | 240 | } |
| 196 | 241 | } |
| 197 | 242 | |