Fossil

Check-in [7dc8e9ac]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added /json/wiki/get?page=...
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | json
Files: files | file ages | folders
SHA1: 7dc8e9ac94fd752de8d080953b518e04dd30965a
User & Date: stephan 2011-09-22 15:59:11.426
Context
2011-09-22
16:21
Added rudimentary timer to AJAX test page. ... (check-in: 07a2c43c user: stephan tags: json)
15:59
Added /json/wiki/get?page=... ... (check-in: 7dc8e9ac user: stephan tags: json)
14:58
Added /json/whoami. ... (check-in: 7a65dd0e user: stephan tags: json)
Changes
Unified Diff Ignore Whitespace Patch
Changes to ajax/index.html.
186
187
188
189
190
191
192

193
194
195
196
197
198
199
<input type='button' value='HAI' onclick='TheApp.cgi.HAI()' />
<input type='button' value='version' onclick='TheApp.cgi.sendCommand("/json/version")' />
<input type='button' value='stat' onclick='TheApp.cgi.sendCommand("/json/stat")' />
<input type='button' value='whoami' onclick='TheApp.cgi.sendCommand("/json/whoami")' />
<input type='button' value='cap' onclick='TheApp.cgi.sendCommand("/json/cap")' />
<input type='button' value='branch/list' onclick='TheApp.cgi.sendCommand("/json/branch/list")' />
<input type='button' value='wiki/list' onclick='TheApp.cgi.sendCommand("/json/wiki/list")' />


<!--
<input type='button' value='get whiki' onclick='TheApp.cgi.getPages("whiki")' />
<input type='button' value='get more' onclick='TheApp.cgi.getPages("HelloWorld/WhikiNews")' />
<input type='button' value='get client data' onclick='TheApp.cgi.getPageClientData("HelloWorld/whiki/WhikiCommands")' />
<input type='button' value='save client data' onclick='TheApp.cgi.savePageClientData({"HelloWorld":[1,3,5]})' />
-->







>







186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<input type='button' value='HAI' onclick='TheApp.cgi.HAI()' />
<input type='button' value='version' onclick='TheApp.cgi.sendCommand("/json/version")' />
<input type='button' value='stat' onclick='TheApp.cgi.sendCommand("/json/stat")' />
<input type='button' value='whoami' onclick='TheApp.cgi.sendCommand("/json/whoami")' />
<input type='button' value='cap' onclick='TheApp.cgi.sendCommand("/json/cap")' />
<input type='button' value='branch/list' onclick='TheApp.cgi.sendCommand("/json/branch/list")' />
<input type='button' value='wiki/list' onclick='TheApp.cgi.sendCommand("/json/wiki/list")' />
<input type='button' value='wiki/get Fossil' onclick='TheApp.cgi.sendCommand("/json/wiki/get",{"page":"Fossil"})' />

<!--
<input type='button' value='get whiki' onclick='TheApp.cgi.getPages("whiki")' />
<input type='button' value='get more' onclick='TheApp.cgi.getPages("HelloWorld/WhikiNews")' />
<input type='button' value='get client data' onclick='TheApp.cgi.getPageClientData("HelloWorld/whiki/WhikiCommands")' />
<input type='button' value='save client data' onclick='TheApp.cgi.savePageClientData({"HelloWorld":[1,3,5]})' />
-->
Changes to src/json.c.
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
  cson_object_set(jo2, "journalMode", *zBuf ? cson_value_new_string(zBuf, strlen(zBuf)) : cson_value_null());
  return jv;
#undef SETBUF
}


static cson_value * json_wiki_list(unsigned int depth);

/*
** Mapping of /json/wiki/XXX commands/paths to callbacks.
*/
static const JsonPageDef JsonPageDefs_Wiki[] = {
{"get", json_page_nyi, 0},
{"list", json_wiki_list, 0},
{"save", json_page_nyi, 1},
/* Last entry MUST have a NULL name. */
{NULL,NULL,0}
};

/*







|




|







1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
  cson_object_set(jo2, "journalMode", *zBuf ? cson_value_new_string(zBuf, strlen(zBuf)) : cson_value_null());
  return jv;
#undef SETBUF
}


static cson_value * json_wiki_list(unsigned int depth);
static cson_value * json_wiki_get(unsigned int depth);
/*
** Mapping of /json/wiki/XXX commands/paths to callbacks.
*/
static const JsonPageDef JsonPageDefs_Wiki[] = {
{"get", json_wiki_get, 0},
{"list", json_wiki_list, 0},
{"save", json_page_nyi, 1},
/* Last entry MUST have a NULL name. */
{NULL,NULL,0}
};

/*
1518
1519
1520
1521
1522
1523
1524

1525
































































1526
1527
1528
1529
1530
1531




1532
1533
1534
1535
1536
1537
1538
** complete.
**
*/
static cson_value * json_page_wiki(unsigned int depth){
  return json_page_dispatch_helper(depth,&JsonPageDefs_Wiki[0]);
}


/*
































































** INTERIM implementation of /json/wiki/list
*/
static cson_value * json_wiki_list(unsigned int depth){
  cson_value * listV = NULL;
  cson_array * list = NULL;
  Stmt q;




  db_prepare(&q,"SELECT"
             " substr(tagname,6) as name"
             " FROM tag WHERE tagname GLOB 'wiki-*'"
             " ORDER BY lower(name)");
  listV = cson_value_new_array();
  list = cson_value_get_array(listV);
  while( SQLITE_ROW == db_step(&q) ){







>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|





>
>
>
>







1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
** complete.
**
*/
static cson_value * json_page_wiki(unsigned int depth){
  return json_page_dispatch_helper(depth,&JsonPageDefs_Wiki[0]);
}


/*
** Implementation of /json/wiki/get.
**
** TODO: add option to parse wiki output. It is currently
** unparsed.
*/
static cson_value * json_wiki_get(unsigned int depth){
  int rid;
  Manifest *pWiki = 0;
  char const * zBody = NULL;
  char const * zPageName;
  char doParse = 0/*not yet implemented*/;

  if( !g.perm.RdWiki ){
    g.json.resultCode = FSL_JSON_E_DENIED;
    return NULL;
  }
  zPageName = g.isHTTP
    ? json_getenv_cstr("page")
    : find_option("page","p",1);
  if(!zPageName||!*zPageName){
    g.json.resultCode = FSL_JSON_E_MISSING_ARGS;
    return NULL;
  }
  rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
               " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
               " ORDER BY x.mtime DESC LIMIT 1",
               zPageName 
               );
  if( (pWiki = manifest_get(rid, CFTYPE_WIKI))!=0 ){
    zBody = pWiki->zWiki;
  }
  if( zBody==0 ){
    manifest_destroy(pWiki);
    g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND;
    return NULL;
  }else{
    unsigned int const len = strlen(zBody);
    cson_value * payV = cson_value_new_object();
    cson_object * pay = cson_value_get_object(payV);
    cson_object_set(pay,"name",json_new_string(zPageName));
    cson_object_set(pay,"version",json_new_string(pWiki->zBaseline))
      /*FIXME: pWiki->zBaseline is NULL. How to get the version number?*/
      ;
    cson_object_set(pay,"rid",cson_value_new_integer((cson_int_t)rid));
    cson_object_set(pay,"lastSavedBy",json_new_string(pWiki->zUser));
    cson_object_set(pay,"timestamp",
                      cson_value_new_integer((cson_int_t)
                        db_int64(0,
                          "SELECT strftime('%%s',%lf)",
                          pWiki->rDate
                        )
                      )
                    );
    cson_object_set(pay,"contentLength",cson_value_new_integer((cson_int_t)len));
    cson_object_set(pay,"contentFormat",json_new_string(doParse?"html":"raw"));
    cson_object_set(pay,"content",cson_value_new_string(zBody,len));
    /*TODO: add 'T' (tag) fields*/
    /*TODO: add the 'A' card (file attachment) entries?*/
    manifest_destroy(pWiki);
    return payV;
  }
}

/*
** Implementation of /json/wiki/list.
*/
static cson_value * json_wiki_list(unsigned int depth){
  cson_value * listV = NULL;
  cson_array * list = NULL;
  Stmt q;
  if( !g.perm.RdWiki ){
    g.json.resultCode = FSL_JSON_E_DENIED;
    return NULL;
  }
  db_prepare(&q,"SELECT"
             " substr(tagname,6) as name"
             " FROM tag WHERE tagname GLOB 'wiki-*'"
             " ORDER BY lower(name)");
  listV = cson_value_new_array();
  list = cson_value_get_array(listV);
  while( SQLITE_ROW == db_step(&q) ){
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
  g.json.resultCode = FSL_JSON_E_UNKNOWN;
  cson_value_free(listV);
  listV = NULL;
  end:
  db_finalize(&q);
  return listV;
}



static cson_value * json_branch_list(unsigned int depth);
/*
** Mapping of /json/branch/XXX commands/paths to callbacks.
*/
static const JsonPageDef JsonPageDefs_Branch[] = {







<







1618
1619
1620
1621
1622
1623
1624

1625
1626
1627
1628
1629
1630
1631
  g.json.resultCode = FSL_JSON_E_UNKNOWN;
  cson_value_free(listV);
  listV = NULL;
  end:
  db_finalize(&q);
  return listV;
}



static cson_value * json_branch_list(unsigned int depth);
/*
** Mapping of /json/branch/XXX commands/paths to callbacks.
*/
static const JsonPageDef JsonPageDefs_Branch[] = {