Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Add the "fossil chat backup" command and the "/chat-backup" webpage to support it. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA3-256: |
1827a314878fecb2d105e5fe3c67839b |
| User & Date: | drh 2022-02-18 20:25:15.823 |
Context
|
2022-02-18
| ||
| 20:32 | For "fossil chat backup", when transfering content from the transfer table into the repository, be explicit about column names, as the column names might be in a different order. ... (check-in: e983a7dc93 user: drh tags: trunk) | |
| 20:25 | Add the "fossil chat backup" command and the "/chat-backup" webpage to support it. ... (check-in: 1827a31487 user: drh tags: trunk) | |
| 15:23 | Improved diff alignment following an indentation change. The objective of this change is to improve the diff output for of the [a36dd09d17f3057f] check-in. ... (check-in: 868d160838 user: drh tags: trunk) | |
Changes
Changes to src/chat.c.
| ︙ | ︙ | |||
813 814 815 816 817 818 819 820 821 822 823 824 825 826 |
"DELETE FROM chat WHERE msgid=%d;\n"
"INSERT INTO chat(mtime, xfrom, mdel)"
" VALUES(julianday('now'), %Q, %d);\n"
"COMMIT;",
mdel, g.zLogin, mdel
);
}
/*
** COMMAND: chat
**
** Usage: %fossil chat [SUBCOMMAND] [--remote URL] [ARGS...]
**
** This command performs actions associated with the /chat instance
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 |
"DELETE FROM chat WHERE msgid=%d;\n"
"INSERT INTO chat(mtime, xfrom, mdel)"
" VALUES(julianday('now'), %Q, %d);\n"
"COMMIT;",
mdel, g.zLogin, mdel
);
}
/*
** WEBPAGE: chat-backup hidden
**
** Download an SQLite database containing all chat content with a
** message-id larger than the "msgid" query parameter. Setup
** privilege is required to use this URL.
*/
void chat_backup_webpage(void){
int msgid;
unsigned char *pDb = 0;
sqlite3_int64 szDb = 0;
Blob chatDb;
login_check_credentials();
if( !g.perm.Setup ) return;
msgid = atoi(PD("msgid","0"));
db_multi_exec(
"ATTACH ':memory:' AS mem1;\n"
"PRAGMA mem1.page_size=512;\n"
"CREATE TABLE mem1.chat AS SELECT * FROM repository.chat WHERE msgid>%d;\n",
msgid
);
pDb = sqlite3_serialize(g.db, "mem1", &szDb, 0);
if( pDb==0 ){
fossil_fatal("Out of memory");
}
blob_init(&chatDb, (const char*)pDb, (int)szDb);
cgi_set_content_type("application/x-sqlite3");
cgi_set_content(&chatDb);
}
/*
** COMMAND: chat
**
** Usage: %fossil chat [SUBCOMMAND] [--remote URL] [ARGS...]
**
** This command performs actions associated with the /chat instance
|
| ︙ | ︙ | |||
836 837 838 839 840 841 842 843 844 845 846 847 848 849 | ** ** When there is no SUBCOMMAND (when this command is simply "fossil chat") ** the response is to bring up a web-browser window to the chatroom ** on the default system web-browser. You can accomplish the same by ** typing the appropriate URL into the web-browser yourself. This ** command is merely a convenience for command-line oriented people. ** ** > fossil chat send [ARGUMENTS] ** ** This command sends a new message to the chatroom. The message ** to be sent is determined by arguments as follows: ** ** -f|--file FILENAME File to attach to the message ** --as FILENAME2 Causes --file FILENAME to be sent with | > > > > > > > > > > > > | 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 | ** ** When there is no SUBCOMMAND (when this command is simply "fossil chat") ** the response is to bring up a web-browser window to the chatroom ** on the default system web-browser. You can accomplish the same by ** typing the appropriate URL into the web-browser yourself. This ** command is merely a convenience for command-line oriented people. ** ** > fossil chat backup ** ** Copy chat content from the server down into the local clone, ** as a backup. Setup privilege is required on the server. ** ** --all Download all chat content. Normally only ** previously undownloaded content is retrieved. ** --debug Additional debugging output. ** --out DATABASE Store CHAT table in separate database file ** DATABASE rather that adding to local clone ** --unsafe Allow the use of unencrypted http:// ** ** > fossil chat send [ARGUMENTS] ** ** This command sends a new message to the chatroom. The message ** to be sent is determined by arguments as follows: ** ** -f|--file FILENAME File to attach to the message ** --as FILENAME2 Causes --file FILENAME to be sent with |
| ︙ | ︙ | |||
979 980 981 982 983 984 985 986 987 988 989 990 991 992 |
fossil_print("ERROR: username and/or password is incorrect\n");
}else{
fossil_print("ERROR: %s\n", blob_str(&down));
}
fossil_fatal("unable to send the chat message");
}
blob_reset(&down);
}else if( strcmp(g.argv[2],"url")==0 ){
/* Show the URL to access chat. */
fossil_print("%s/chat\n", zUrl);
}else{
fossil_fatal("no such subcommand \"%s\". Use --help for help", g.argv[2]);
}
}
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 |
fossil_print("ERROR: username and/or password is incorrect\n");
}else{
fossil_print("ERROR: %s\n", blob_str(&down));
}
fossil_fatal("unable to send the chat message");
}
blob_reset(&down);
}else if( strcmp(g.argv[2],"backup")==0 ){
/* Pull the CHAT table from the default server down into the repository
** here on the local side */
int allowUnsafe = find_option("unsafe",0,0)!=0;
int bDebug = find_option("debug",0,0)!=0;
const char *zOut = find_option("out",0,1);
int bAll = find_option("all",0,0)!=0;
int mFlags = HTTP_GENERIC | HTTP_QUIET | HTTP_NOCOMPRESS;
int msgid;
Blob reqUri; /* The REQUEST_URI: .../chat-backup?msgid=... */
char *zObs;
const char *zPw;
Blob up, down;
int nChat;
int rc;
verify_all_options();
chat_create_tables();
msgid = bAll ? 0 : db_int(0,"SELECT max(msgid) FROM chat");
if( !g.url.isHttps && !allowUnsafe ){
fossil_fatal("URL \"%s\" is unencrypted. Use https:// instead", zUrl);
}
blob_init(&reqUri, g.url.path, -1);
blob_appendf(&reqUri, "/chat-backup?msgid=%d", msgid);
if( g.url.user && g.url.user[0] ){
zObs = obscure(g.url.user);
blob_appendf(&reqUri, "&resid=%t", zObs);
fossil_free(zObs);
}
zPw = g.url.passwd;
if( zPw==0 && isDefaultUrl ) zPw = unobscure(db_get("last-sync-pw", 0));
if( zPw && zPw[0] ){
zObs = obscure(zPw);
blob_appendf(&reqUri, "&token=%t", zObs);
fossil_free(zObs);
}
g.url.path = blob_str(&reqUri);
if( bDebug ){
fossil_print("REQUEST_URI: %s\n", g.url.path);
mFlags &= ~HTTP_QUIET;
mFlags |= HTTP_VERBOSE;
}
blob_init(&up, 0, 0);
blob_init(&down, 0, 0);
http_exchange(&up, &down, mFlags, 4, 0);
if( zOut ){
blob_write_to_file(&down, zOut);
fossil_print("Chat database at %s is %d bytes\n", zOut, blob_size(&down));
}else{
db_multi_exec("ATTACH ':memory:' AS chatbu;");
if( g.fSqlTrace ){
fossil_trace("-- deserialize(\"chatbu\", pData, %d);\n",
blob_size(&down));
}
rc = sqlite3_deserialize(g.db, "chatbu",
(unsigned char*)blob_buffer(&down),
blob_size(&down), blob_size(&down), 0);
if( rc ){
fossil_fatal("cannot open patch database: %s", sqlite3_errmsg(g.db));
}
nChat = db_int(0, "SELECT count(*) FROM chatbu.chat");
fossil_print("Got %d new records, %d bytes\n", nChat, blob_size(&down));
db_multi_exec(
"REPLACE INTO repository.chat SELECT * FROM chatbu.chat;"
);
}
}else if( strcmp(g.argv[2],"url")==0 ){
/* Show the URL to access chat. */
fossil_print("%s/chat\n", zUrl);
}else{
fossil_fatal("no such subcommand \"%s\". Use --help for help", g.argv[2]);
}
}
|