217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
@ <pre>
@ %h(blob_str(&fullbody))
@ </pre>
}
style_footer();
manifest_destroy(pTNote);
}
/*
** Add or update a new tech note to the repository. rid is id of
** the prior version of this technote, if any.
**
** zId specifies the uuid of the tech note
** zBody specifies the content of the tech note
** zETime specifies the timestamp of the tech note
** zMimeType specifies the N-card for the wiki page. If it is 0,
** empty, or "text/x-fossil-wiki" (the default format) then it is
** ignored.
** zComment is the comment shown on the timeline.
** zTags are the tags for the tech note.
** zClr is the background color used for the tech note on the timeline.
**
** returns 1 if the tech note was added or updated, 0 if the
** update failed making an invalid artifact
*/
int event_commit_common(int rid, const char *zId, const char *zBody, char *zETime,
const char *zMimetype, const char *zComment,
const char *zTags, const char *zClr){
Blob event;
char *zDate;
Blob cksum;
int nrid, n;
blob_init(&event, 0, 0);
db_begin_transaction();
while( fossil_isspace(zComment[0]) ) zComment++;
n = strlen(zComment);
while( n>0 && fossil_isspace(zComment[n-1]) ){ n--; }
if( n>0 ){
blob_appendf(&event, "C %#F\n", n, zComment);
}
zDate = date_in_standard_format("now");
blob_appendf(&event, "D %s\n", zDate);
free(zDate);
zETime[10] = 'T';
blob_appendf(&event, "E %s %s\n", zETime, zId);
zETime[10] = ' ';
if( rid ){
char *zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
blob_appendf(&event, "P %s\n", zUuid);
free(zUuid);
}
if( zMimetype && zMimetype[0] ){
blob_appendf(&event, "N %s\n", zMimetype);
}
if( zClr && zClr[0] ){
blob_appendf(&event, "T +bgcolor * %F\n", zClr);
}
if( zTags && zTags[0] ){
Blob tags, one;
int i, j;
Stmt q;
char *zBlob;
/* Load the tags string into a blob */
blob_zero(&tags);
blob_append(&tags, zTags, -1);
/* Collapse all sequences of whitespace and "," characters into
** a single space character */
zBlob = blob_str(&tags);
for(i=j=0; zBlob[i]; i++, j++){
if( fossil_isspace(zBlob[i]) || zBlob[i]==',' ){
while( fossil_isspace(zBlob[i+1]) ){ i++; }
zBlob[j] = ' ';
}else{
zBlob[j] = zBlob[i];
}
}
blob_resize(&tags, j);
/* Parse out each tag and load it into a temporary table for sorting */
db_multi_exec("CREATE TEMP TABLE newtags(x);");
while( blob_token(&tags, &one) ){
db_multi_exec("INSERT INTO newtags VALUES(%B)", &one);
}
blob_reset(&tags);
/* Extract the tags in sorted order and make an entry in the
** artifact for each. */
db_prepare(&q, "SELECT x FROM newtags ORDER BY x");
while( db_step(&q)==SQLITE_ROW ){
blob_appendf(&event, "T +sym-%F *\n", db_column_text(&q, 0));
}
db_finalize(&q);
}
if( !login_is_nobody() ){
blob_appendf(&event, "U %F\n", login_name());
}
blob_appendf(&event, "W %d\n%s\n", strlen(zBody), zBody);
md5sum_blob(&event, &cksum);
blob_appendf(&event, "Z %b\n", &cksum);
blob_reset(&cksum);
nrid = content_put(&event);
db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", nrid);
if( manifest_crosslink(nrid, &event, MC_NONE)==0 ){
db_end_transaction(1);
return 0;
}
assert( blob_is_reset(&event) );
content_deltify(rid, nrid, 0);
db_end_transaction(0);
return 1;
}
/*
** WEBPAGE: technoteedit
** WEBPAGE: eventedit
**
** Revise or create a technical note (formerly called an 'event').
**
|
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
|
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
|
" AND tag.tagname GLOB 'sym-*'",
rid
);
}
}
zETime = db_text(0, "SELECT coalesce(datetime(%Q),datetime('now'))", zETime);
if( P("submit")!=0 && (zBody!=0 && zComment!=0) ){
char *zDate;
Blob cksum;
int nrid, n;
blob_init(&event, 0, 0);
db_begin_transaction();
login_verify_csrf_secret();
while( fossil_isspace(zComment[0]) ) zComment++;
n = strlen(zComment);
while( n>0 && fossil_isspace(zComment[n-1]) ){ n--; }
if( n>0 ){
blob_appendf(&event, "C %#F\n", n, zComment);
}
zDate = date_in_standard_format("now");
blob_appendf(&event, "D %s\n", zDate);
free(zDate);
zETime[10] = 'T';
blob_appendf(&event, "E %s %s\n", zETime, zId);
zETime[10] = ' ';
if( rid ){
char *zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
blob_appendf(&event, "P %s\n", zUuid);
free(zUuid);
}
if( zMimetype && zMimetype[0] ){
blob_appendf(&event, "N %s\n", zMimetype);
}
if( zClr && zClr[0] ){
blob_appendf(&event, "T +bgcolor * %F\n", zClr);
}
if( zTags && zTags[0] ){
Blob tags, one;
int i, j;
Stmt q;
char *zBlob;
if ( !event_commit_common(rid, zId, zBody, zETime, zMimetype, zComment, zTags, zClr) ){
/* Load the tags string into a blob */
blob_zero(&tags);
blob_append(&tags, zTags, -1);
/* Collapse all sequences of whitespace and "," characters into
** a single space character */
zBlob = blob_str(&tags);
for(i=j=0; zBlob[i]; i++, j++){
if( fossil_isspace(zBlob[i]) || zBlob[i]==',' ){
while( fossil_isspace(zBlob[i+1]) ){ i++; }
zBlob[j] = ' ';
}else{
zBlob[j] = zBlob[i];
}
}
blob_resize(&tags, j);
/* Parse out each tag and load it into a temporary table for sorting */
db_multi_exec("CREATE TEMP TABLE newtags(x);");
while( blob_token(&tags, &one) ){
db_multi_exec("INSERT INTO newtags VALUES(%B)", &one);
}
blob_reset(&tags);
/* Extract the tags in sorted order and make an entry in the
** artifact for each. */
db_prepare(&q, "SELECT x FROM newtags ORDER BY x");
while( db_step(&q)==SQLITE_ROW ){
blob_appendf(&event, "T +sym-%F *\n", db_column_text(&q, 0));
}
db_finalize(&q);
}
if( !login_is_nobody() ){
blob_appendf(&event, "U %F\n", login_name());
}
blob_appendf(&event, "W %d\n%s\n", strlen(zBody), zBody);
md5sum_blob(&event, &cksum);
blob_appendf(&event, "Z %b\n", &cksum);
blob_reset(&cksum);
nrid = content_put(&event);
db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", nrid);
if( manifest_crosslink(nrid, &event, MC_NONE)==0 ){
db_end_transaction(1);
style_header("Error");
@ Internal error: Fossil tried to make an invalid artifact for
@ the edited technode.
@ the edited technote.
style_footer();
return;
}
assert( blob_is_reset(&event) );
content_deltify(rid, nrid, 0);
db_end_transaction(0);
cgi_redirectf("technote?name=%T", zId);
}
if( P("cancel")!=0 ){
cgi_redirectf("technote?name=%T", zId);
return;
}
if( zBody==0 ){
|
495
496
497
498
499
500
501
|
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
@ <input type="submit" name="preview" value="Preview Your Changes" />
@ <input type="submit" name="submit" value="Apply These Changes" />
@ <input type="submit" name="cancel" value="Cancel" />
@ </td></tr></table>
@ </div></form>
style_footer();
}
/*
** Add a new tech note to the repository. The timestamp is
** given by the zETime parameter. isNew must be true to create
** a new page. If no previous page with the name zPageName exists
** and isNew is false, then this routine throws an error.
**
** The content of the new page is given by the blob pContent.
**
** zMimeType specifies the N-card for the wiki page. If it is 0,
** empty, or "text/x-fossil-wiki" (the default format) then it is
** ignored.
** zComment is the comment that will appear on the timeline for
** this technote
** zTags is a list of the tags for this technote
** zCLr is the background color for this technote
*/
int event_cmd_commit(char *zETime, int isNew, Blob *pContent,
const char *zMimeType, const char *zComment,
const char *zTags, const char *zClr){
int rid; /* Artifact id of the tech note */
const char *zId; /* id of the tech note */
rid = db_int(0, "SELECT objid FROM event"
" WHERE datetime(mtime)=datetime('%q') AND type = 'e'"
" LIMIT 1",
zETime
);
if( rid==0 && !isNew ){
#ifdef FOSSIL_ENABLE_JSON
g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND;
#endif
fossil_fatal("no such tech note: %s", zETime);
}
if( rid!=0 && isNew ){
#ifdef FOSSIL_ENABLE_JSON
g.json.resultCode = FSL_JSON_E_RESOURCE_ALREADY_EXISTS;
#endif
fossil_fatal("tech note %s already exists", zETime);
}
if ( isNew ){
zId = db_text(0, "SELECT lower(hex(randomblob(20)))");
}else{
zId = db_text(0,
"SELECT substr(tagname,7) FROM tag WHERE tagid=(SELECT tagid FROM event WHERE objid='%d')",
rid
);
}
user_select();
if (event_commit_common(rid, zId, blob_str(pContent), zETime,
zMimeType, zComment, zTags, zClr)==0 ){
#ifdef FOSSIL_ENABLE_JSON
g.json.resultCode = FSL_JSON_E_ASSERT;
#endif
fossil_fatal("Internal error: Fossil tried to make an invalid artifact for the technote.\n");
}
}
|