Subversion Repositories Koakuma

Rev

Rev 4 | Rev 6 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4 Rev 5
Line 52... Line 52...
52
 
52
 
53
if { [catch {
53
if { [catch {
54
	package require tdom
54
	package require tdom
55
	dom createNodeCmd -tagName "rpc" elementNode rootXML
55
	dom createNodeCmd -tagName "rpc" elementNode rootXML
56
	dom createNodeCmd -tagName "version" -jsonType NONE elementNode keyVersion
56
	dom createNodeCmd -tagName "version" -jsonType NONE elementNode keyVersion
-
 
57
	dom createNodeCmd -tagName "error" -jsonType NONE elementNode keyError
57
	dom createNodeCmd -jsonType STRING textNode valueString
58
	dom createNodeCmd -jsonType STRING textNode valueString
58
}] } {
59
}] } {
59
	crash "Failed to load tDOM"
60
	crash "Failed to load tDOM"
60
}
61
}
61
 
62
 
Line 65... Line 66...
65
	}
66
	}
66
}] } {
67
}] } {
67
	crash "Could not load components"
68
	crash "Could not load components"
68
}
69
}
69
 
70
 
-
 
71
set data ""
-
 
72
 
-
 
73
while { [gets stdin line] >= 0 } {
-
 
74
	if { "$data" == "" } {
-
 
75
		set data "$line"
-
 
76
	} else {
-
 
77
		set data "$data\n$line"
-
 
78
	}
-
 
79
}
-
 
80
 
70
set toc ""
81
set toc ""
71
set result ""
82
set result ""
72
set content ""
83
set content ""
73
 
84
 
74
proc rputs {data} {
85
proc rputs {data} {
Line 263... Line 274...
263
		rputs ""
274
		rputs ""
264
		start_html "Main" 1
275
		start_html "Main" 1
265
		rputs "$content"
276
		rputs "$content"
266
		end_html 1
277
		end_html 1
267
	} elseif { [regexp {^/rpc(/.*)?$} "$path"] } {
278
	} elseif { [regexp {^/rpc(/.*)?$} "$path"] } {
268
		rputs ""
-
 
269
		regexp {^/rpc(/.*)?$} "$path" -> api
279
		regexp {^/rpc(/.*)?$} "$path" -> api
270
		set doc [dom createDocumentNode]
280
		set doc [dom createDocumentNode]
271
		set root $doc
281
		$doc appendFromScript {
-
 
282
			keyVersion {valueString "$KOAKUMA_VERSION"}
-
 
283
		}
272
		if { "$api" == "" || "$api" == "/" } {
284
		if { "$api" == "" || "$api" == "/" } {
-
 
285
			rputs ""
-
 
286
			rputs "[$doc asJSON]"
-
 
287
		} elseif { "$api" == "/create-project" } {
-
 
288
			if { [catch {dom parse -json "$data" clidoc}] } {
-
 
289
				rputs "Status: 400 Bad Request"
-
 
290
				$doc appendFromScript {
-
 
291
					keyError {valueString "Bad JSON"}
-
 
292
				}
-
 
293
			} else {
-
 
294
				set projname "[$clidoc selectNodes "string(/name)"]"
-
 
295
				set projdescription "[$clidoc selectNodes "string(/description)"]"
-
 
296
				set vcs "[$clidoc selectNodes "string(/vcs)"]"
-
 
297
				set url "[$clidoc selectNodes "string(/url)"]"
-
 
298
				if { "$projname" == "" || "$projdescription" == "" || "$vcs" == "" || "$url" == "" } {
-
 
299
					rputs "Status: 400 Bad Request"
-
 
300
					$doc appendFromScript {
-
 
301
						keyError {valueString "Required field missing"}
-
 
302
					}
-
 
303
				} else {
-
 
304
					set has_vcs 0
-
 
305
					loop_components {
-
 
306
						upvar 1 has_vcs has_vcs
-
 
307
						upvar 1 vcs vcs
-
 
308
						if { "$name" == "$vcs" } {
-
 
309
							set has_vcs 1
-
 
310
							break
-
 
311
						}
-
 
312
					}
-
 
313
					if { $has_vcs == 0 } {
-
 
314
						rputs "Status: 400 Bad Request"
-
 
315
						$doc appendFromScript {
-
 
316
							keyError {valueString "Not a valid VCS"}
-
 
317
						}
-
 
318
					} else {
-
 
319
						open_projects
-
 
320
						close_projects
-
 
321
					}
-
 
322
				}
-
 
323
			}
-
 
324
			rputs ""
-
 
325
			rputs "[$doc asJSON]"
-
 
326
		} else {
273
			$root appendFromScript {
327
			$root appendFromScript {
274
				keyVersion {valueString "$KOAKUMA_VERSION"}
328
				keyError {valueString "No such endpoint"}
275
			}
329
			}
-
 
330
			rputs "Status: 404 Not Found"
-
 
331
			rputs ""
276
			rputs "[$doc asJSON]"
332
			rputs "[$doc asJSON]"
277
		}
333
		}
278
	} elseif { [regexp {^/project/[^/]+.*$} "$path"] } {
334
	} elseif { [regexp {^/project/[^/]+.*$} "$path"] } {
279
		regexp {^/project/([^/]+).*$} "$path" -> projname
335
		regexp {^/project/([^/]+).*$} "$path" -> projname
280
		open_projects
336
		open_projects