Fossil SCM

Add support for setting environment variables from within CGI script files.

mistachkin 2015-01-22 02:59 trunk merge
Commit 0af7024db1246f1fad4ff6b23aa03879f7157edc
2 files changed +19 +7
+19
--- src/file.c
+++ src/file.c
@@ -1262,10 +1262,29 @@
12621262
char *zValue = getenv(zName);
12631263
#endif
12641264
if( zValue ) zValue = fossil_filename_to_utf8(zValue);
12651265
return zValue;
12661266
}
1267
+
1268
+/*
1269
+** Sets the value of an environment variable as UTF8.
1270
+*/
1271
+int fossil_setenv(const char *zName, const char *zValue){
1272
+ int rc;
1273
+ char *zString = mprintf("%s=%s", zName, zValue);
1274
+#ifdef _WIN32
1275
+ wchar_t *uString = fossil_utf8_to_unicode(zString);
1276
+ rc = _wputenv(uString);
1277
+ fossil_unicode_free(uString);
1278
+ fossil_free(zString);
1279
+#else
1280
+ rc = putenv(zString);
1281
+ /* NOTE: Cannot free the string on POSIX. */
1282
+ /* fossil_free(zString); */
1283
+#endif
1284
+ return rc;
1285
+}
12671286
12681287
/*
12691288
** Like fopen() but always takes a UTF8 argument.
12701289
*/
12711290
FILE *fossil_fopen(const char *zName, const char *zMode){
12721291
--- src/file.c
+++ src/file.c
@@ -1262,10 +1262,29 @@
1262 char *zValue = getenv(zName);
1263 #endif
1264 if( zValue ) zValue = fossil_filename_to_utf8(zValue);
1265 return zValue;
1266 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1267
1268 /*
1269 ** Like fopen() but always takes a UTF8 argument.
1270 */
1271 FILE *fossil_fopen(const char *zName, const char *zMode){
1272
--- src/file.c
+++ src/file.c
@@ -1262,10 +1262,29 @@
1262 char *zValue = getenv(zName);
1263 #endif
1264 if( zValue ) zValue = fossil_filename_to_utf8(zValue);
1265 return zValue;
1266 }
1267
1268 /*
1269 ** Sets the value of an environment variable as UTF8.
1270 */
1271 int fossil_setenv(const char *zName, const char *zValue){
1272 int rc;
1273 char *zString = mprintf("%s=%s", zName, zValue);
1274 #ifdef _WIN32
1275 wchar_t *uString = fossil_utf8_to_unicode(zString);
1276 rc = _wputenv(uString);
1277 fossil_unicode_free(uString);
1278 fossil_free(zString);
1279 #else
1280 rc = putenv(zString);
1281 /* NOTE: Cannot free the string on POSIX. */
1282 /* fossil_free(zString); */
1283 #endif
1284 return rc;
1285 }
1286
1287 /*
1288 ** Like fopen() but always takes a UTF8 argument.
1289 */
1290 FILE *fossil_fopen(const char *zName, const char *zMode){
1291
+7
--- src/main.c
+++ src/main.c
@@ -1837,10 +1837,17 @@
18371837
}
18381838
if( blob_eq(&key, "files:") && blob_token(&line, &value) ){
18391839
pFileGlob = glob_create(blob_str(&value));
18401840
blob_reset(&value);
18411841
continue;
1842
+ }
1843
+ if( blob_eq(&key, "setenv:") && blob_token(&line, &value)
1844
+ && blob_token(&line, &value2) ){
1845
+ fossil_setenv(blob_str(&value), blob_str(&value2));
1846
+ blob_reset(&value);
1847
+ blob_reset(&value2);
1848
+ continue;
18421849
}
18431850
}
18441851
blob_reset(&config);
18451852
if( g.db==0 && g.zRepositoryName==0 && nRedirect==0 ){
18461853
cgi_panic("Unable to find or open the project repository");
18471854
--- src/main.c
+++ src/main.c
@@ -1837,10 +1837,17 @@
1837 }
1838 if( blob_eq(&key, "files:") && blob_token(&line, &value) ){
1839 pFileGlob = glob_create(blob_str(&value));
1840 blob_reset(&value);
1841 continue;
 
 
 
 
 
 
 
1842 }
1843 }
1844 blob_reset(&config);
1845 if( g.db==0 && g.zRepositoryName==0 && nRedirect==0 ){
1846 cgi_panic("Unable to find or open the project repository");
1847
--- src/main.c
+++ src/main.c
@@ -1837,10 +1837,17 @@
1837 }
1838 if( blob_eq(&key, "files:") && blob_token(&line, &value) ){
1839 pFileGlob = glob_create(blob_str(&value));
1840 blob_reset(&value);
1841 continue;
1842 }
1843 if( blob_eq(&key, "setenv:") && blob_token(&line, &value)
1844 && blob_token(&line, &value2) ){
1845 fossil_setenv(blob_str(&value), blob_str(&value2));
1846 blob_reset(&value);
1847 blob_reset(&value2);
1848 continue;
1849 }
1850 }
1851 blob_reset(&config);
1852 if( g.db==0 && g.zRepositoryName==0 && nRedirect==0 ){
1853 cgi_panic("Unable to find or open the project repository");
1854

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button