Fossil SCM
Added /json/whoami.
Commit
7a65dd0e00a2fab49bb47fd34a3a2fbc680fb675
Parent
8b814778c920b91…
2 files changed
+1
+36
-1
+1
| --- ajax/index.html | ||
| +++ ajax/index.html | ||
| @@ -184,10 +184,11 @@ | ||
| 184 | 184 | <input type='button' value='Send...' id='btnSend' onclick='TheApp.sendRequest()' /><br/> |
| 185 | 185 | <strong>Quick-posts:</strong><br/> |
| 186 | 186 | <input type='button' value='HAI' onclick='TheApp.cgi.HAI()' /> |
| 187 | 187 | <input type='button' value='version' onclick='TheApp.cgi.sendCommand("/json/version")' /> |
| 188 | 188 | <input type='button' value='stat' onclick='TheApp.cgi.sendCommand("/json/stat")' /> |
| 189 | +<input type='button' value='whoami' onclick='TheApp.cgi.sendCommand("/json/whoami")' /> | |
| 189 | 190 | <input type='button' value='cap' onclick='TheApp.cgi.sendCommand("/json/cap")' /> |
| 190 | 191 | <input type='button' value='branch/list' onclick='TheApp.cgi.sendCommand("/json/branch/list")' /> |
| 191 | 192 | <input type='button' value='wiki/list' onclick='TheApp.cgi.sendCommand("/json/wiki/list")' /> |
| 192 | 193 | |
| 193 | 194 | <!-- |
| 194 | 195 |
| --- ajax/index.html | |
| +++ ajax/index.html | |
| @@ -184,10 +184,11 @@ | |
| 184 | <input type='button' value='Send...' id='btnSend' onclick='TheApp.sendRequest()' /><br/> |
| 185 | <strong>Quick-posts:</strong><br/> |
| 186 | <input type='button' value='HAI' onclick='TheApp.cgi.HAI()' /> |
| 187 | <input type='button' value='version' onclick='TheApp.cgi.sendCommand("/json/version")' /> |
| 188 | <input type='button' value='stat' onclick='TheApp.cgi.sendCommand("/json/stat")' /> |
| 189 | <input type='button' value='cap' onclick='TheApp.cgi.sendCommand("/json/cap")' /> |
| 190 | <input type='button' value='branch/list' onclick='TheApp.cgi.sendCommand("/json/branch/list")' /> |
| 191 | <input type='button' value='wiki/list' onclick='TheApp.cgi.sendCommand("/json/wiki/list")' /> |
| 192 | |
| 193 | <!-- |
| 194 |
| --- ajax/index.html | |
| +++ ajax/index.html | |
| @@ -184,10 +184,11 @@ | |
| 184 | <input type='button' value='Send...' id='btnSend' onclick='TheApp.sendRequest()' /><br/> |
| 185 | <strong>Quick-posts:</strong><br/> |
| 186 | <input type='button' value='HAI' onclick='TheApp.cgi.HAI()' /> |
| 187 | <input type='button' value='version' onclick='TheApp.cgi.sendCommand("/json/version")' /> |
| 188 | <input type='button' value='stat' onclick='TheApp.cgi.sendCommand("/json/stat")' /> |
| 189 | <input type='button' value='whoami' onclick='TheApp.cgi.sendCommand("/json/whoami")' /> |
| 190 | <input type='button' value='cap' onclick='TheApp.cgi.sendCommand("/json/cap")' /> |
| 191 | <input type='button' value='branch/list' onclick='TheApp.cgi.sendCommand("/json/branch/list")' /> |
| 192 | <input type='button' value='wiki/list' onclick='TheApp.cgi.sendCommand("/json/wiki/list")' /> |
| 193 | |
| 194 | <!-- |
| 195 |
+36
-1
| --- src/json.c | ||
| +++ src/json.c | ||
| @@ -1143,11 +1143,10 @@ | ||
| 1143 | 1143 | ** a use in client code. (?) |
| 1144 | 1144 | */ |
| 1145 | 1145 | cson_value * json_page_cap(unsigned int depth){ |
| 1146 | 1146 | cson_value * payload = cson_value_new_object(); |
| 1147 | 1147 | cson_value * sub = cson_value_new_object(); |
| 1148 | - char * zCap; | |
| 1149 | 1148 | Stmt q; |
| 1150 | 1149 | cson_object * obj = cson_value_get_object(payload); |
| 1151 | 1150 | db_prepare(&q, "SELECT login, cap FROM user WHERE uid=%d", g.userUid); |
| 1152 | 1151 | if( db_step(&q)==SQLITE_ROW ){ |
| 1153 | 1152 | /* reminder: we don't use g.zLogin because it's 0 for the guest |
| @@ -1861,10 +1860,45 @@ | ||
| 1861 | 1860 | payV = NULL; |
| 1862 | 1861 | ok: |
| 1863 | 1862 | return payV; |
| 1864 | 1863 | } |
| 1865 | 1864 | |
| 1865 | +/* | |
| 1866 | +** Implements the /json/whoami page/command. | |
| 1867 | +*/ | |
| 1868 | +static cson_value * json_page_whoami(unsigned int depth){ | |
| 1869 | + cson_value * payload = NULL; | |
| 1870 | + cson_object * obj = NULL; | |
| 1871 | + Stmt q; | |
| 1872 | + db_prepare(&q, "SELECT login, cap FROM user WHERE uid=%d", g.userUid); | |
| 1873 | + if( db_step(&q)==SQLITE_ROW ){ | |
| 1874 | + | |
| 1875 | + /* reminder: we don't use g.zLogin because it's 0 for the guest | |
| 1876 | + user and the HTML UI appears to currently allow the name to be | |
| 1877 | + changed (but doing so would break other code). */ | |
| 1878 | + char const * str; | |
| 1879 | + payload = cson_value_new_object(); | |
| 1880 | + obj = cson_value_get_object(payload); | |
| 1881 | + str = (char const *)sqlite3_column_text(q.pStmt,0); | |
| 1882 | + if( str ){ | |
| 1883 | + cson_object_set( obj, "name", | |
| 1884 | + cson_value_new_string(str,strlen(str)) ); | |
| 1885 | + } | |
| 1886 | + str = (char const *)sqlite3_column_text(q.pStmt,1); | |
| 1887 | + if( str ){ | |
| 1888 | + cson_object_set( obj, "capabilities", | |
| 1889 | + cson_value_new_string(str,strlen(str)) ); | |
| 1890 | + } | |
| 1891 | + if( g.json.authToken ){ | |
| 1892 | + cson_object_set( obj, "authToken", g.json.authToken ); | |
| 1893 | + } | |
| 1894 | + }else{ | |
| 1895 | + g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND; | |
| 1896 | + } | |
| 1897 | + db_finalize(&q); | |
| 1898 | + return payload; | |
| 1899 | +} | |
| 1866 | 1900 | |
| 1867 | 1901 | /* |
| 1868 | 1902 | ** Mapping of names to JSON pages/commands. Each name is a subpath of |
| 1869 | 1903 | ** /json (in CGI mode) or a subcommand of the json command in CLI mode |
| 1870 | 1904 | */ |
| @@ -1881,10 +1915,11 @@ | ||
| 1881 | 1915 | {"tag", json_page_nyi,0}, |
| 1882 | 1916 | {"ticket", json_page_nyi,0}, |
| 1883 | 1917 | {"timeline", json_page_timeline,0}, |
| 1884 | 1918 | {"user", json_page_nyi,0}, |
| 1885 | 1919 | {"version",json_page_version,0}, |
| 1920 | +{"whoami",json_page_whoami,1}, | |
| 1886 | 1921 | {"wiki",json_page_wiki,0}, |
| 1887 | 1922 | /* Last entry MUST have a NULL name. */ |
| 1888 | 1923 | {NULL,NULL,0} |
| 1889 | 1924 | }; |
| 1890 | 1925 | |
| 1891 | 1926 |
| --- src/json.c | |
| +++ src/json.c | |
| @@ -1143,11 +1143,10 @@ | |
| 1143 | ** a use in client code. (?) |
| 1144 | */ |
| 1145 | cson_value * json_page_cap(unsigned int depth){ |
| 1146 | cson_value * payload = cson_value_new_object(); |
| 1147 | cson_value * sub = cson_value_new_object(); |
| 1148 | char * zCap; |
| 1149 | Stmt q; |
| 1150 | cson_object * obj = cson_value_get_object(payload); |
| 1151 | db_prepare(&q, "SELECT login, cap FROM user WHERE uid=%d", g.userUid); |
| 1152 | if( db_step(&q)==SQLITE_ROW ){ |
| 1153 | /* reminder: we don't use g.zLogin because it's 0 for the guest |
| @@ -1861,10 +1860,45 @@ | |
| 1861 | payV = NULL; |
| 1862 | ok: |
| 1863 | return payV; |
| 1864 | } |
| 1865 | |
| 1866 | |
| 1867 | /* |
| 1868 | ** Mapping of names to JSON pages/commands. Each name is a subpath of |
| 1869 | ** /json (in CGI mode) or a subcommand of the json command in CLI mode |
| 1870 | */ |
| @@ -1881,10 +1915,11 @@ | |
| 1881 | {"tag", json_page_nyi,0}, |
| 1882 | {"ticket", json_page_nyi,0}, |
| 1883 | {"timeline", json_page_timeline,0}, |
| 1884 | {"user", json_page_nyi,0}, |
| 1885 | {"version",json_page_version,0}, |
| 1886 | {"wiki",json_page_wiki,0}, |
| 1887 | /* Last entry MUST have a NULL name. */ |
| 1888 | {NULL,NULL,0} |
| 1889 | }; |
| 1890 | |
| 1891 |
| --- src/json.c | |
| +++ src/json.c | |
| @@ -1143,11 +1143,10 @@ | |
| 1143 | ** a use in client code. (?) |
| 1144 | */ |
| 1145 | cson_value * json_page_cap(unsigned int depth){ |
| 1146 | cson_value * payload = cson_value_new_object(); |
| 1147 | cson_value * sub = cson_value_new_object(); |
| 1148 | Stmt q; |
| 1149 | cson_object * obj = cson_value_get_object(payload); |
| 1150 | db_prepare(&q, "SELECT login, cap FROM user WHERE uid=%d", g.userUid); |
| 1151 | if( db_step(&q)==SQLITE_ROW ){ |
| 1152 | /* reminder: we don't use g.zLogin because it's 0 for the guest |
| @@ -1861,10 +1860,45 @@ | |
| 1860 | payV = NULL; |
| 1861 | ok: |
| 1862 | return payV; |
| 1863 | } |
| 1864 | |
| 1865 | /* |
| 1866 | ** Implements the /json/whoami page/command. |
| 1867 | */ |
| 1868 | static cson_value * json_page_whoami(unsigned int depth){ |
| 1869 | cson_value * payload = NULL; |
| 1870 | cson_object * obj = NULL; |
| 1871 | Stmt q; |
| 1872 | db_prepare(&q, "SELECT login, cap FROM user WHERE uid=%d", g.userUid); |
| 1873 | if( db_step(&q)==SQLITE_ROW ){ |
| 1874 | |
| 1875 | /* reminder: we don't use g.zLogin because it's 0 for the guest |
| 1876 | user and the HTML UI appears to currently allow the name to be |
| 1877 | changed (but doing so would break other code). */ |
| 1878 | char const * str; |
| 1879 | payload = cson_value_new_object(); |
| 1880 | obj = cson_value_get_object(payload); |
| 1881 | str = (char const *)sqlite3_column_text(q.pStmt,0); |
| 1882 | if( str ){ |
| 1883 | cson_object_set( obj, "name", |
| 1884 | cson_value_new_string(str,strlen(str)) ); |
| 1885 | } |
| 1886 | str = (char const *)sqlite3_column_text(q.pStmt,1); |
| 1887 | if( str ){ |
| 1888 | cson_object_set( obj, "capabilities", |
| 1889 | cson_value_new_string(str,strlen(str)) ); |
| 1890 | } |
| 1891 | if( g.json.authToken ){ |
| 1892 | cson_object_set( obj, "authToken", g.json.authToken ); |
| 1893 | } |
| 1894 | }else{ |
| 1895 | g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND; |
| 1896 | } |
| 1897 | db_finalize(&q); |
| 1898 | return payload; |
| 1899 | } |
| 1900 | |
| 1901 | /* |
| 1902 | ** Mapping of names to JSON pages/commands. Each name is a subpath of |
| 1903 | ** /json (in CGI mode) or a subcommand of the json command in CLI mode |
| 1904 | */ |
| @@ -1881,10 +1915,11 @@ | |
| 1915 | {"tag", json_page_nyi,0}, |
| 1916 | {"ticket", json_page_nyi,0}, |
| 1917 | {"timeline", json_page_timeline,0}, |
| 1918 | {"user", json_page_nyi,0}, |
| 1919 | {"version",json_page_version,0}, |
| 1920 | {"whoami",json_page_whoami,1}, |
| 1921 | {"wiki",json_page_wiki,0}, |
| 1922 | /* Last entry MUST have a NULL name. */ |
| 1923 | {NULL,NULL,0} |
| 1924 | }; |
| 1925 | |
| 1926 |