17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
...
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
...
924
925
926
927
928
929
930
931
932
933
934
935
936
937
...
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
|
var act = co:ppostv('act')
if rel.recip.block() then
if act:cmp('follow') or act:cmp('subscribe') then
co:complain(403,'blocked','you cannot follow a user you are blocked by') return
end
end
if act:cmp('circle') then
lib.dbg('encircling user!')
var allcircs = co.srv:circle_search(&co.srv.pool, co.who.id, 0)
var mycircs = co.srv:circle_memberships_uid(&co.srv.pool, co.who.id, actor.id)
var marked = co.srv.pool:alloc(bool, allcircs.ct)
var member = co.srv.pool:alloc(bool, allcircs.ct)
for i = 0, marked.ct do
marked(i) = false
member(i) = false
................................................................................
handle.ct = uri.ct - 2
uri:advance(uri.ct)
elseif handle.ct + 2 < uri.ct then uri:advance(handle.ct + 2) end
lib.dbg('looking up user by xid "', {handle.ptr,handle.ct} ,'", path: ', {uri.ptr,uri.ct})
var path = lib.http.hier(&co.srv.pool, uri) --defer path:free()
for i=0,path.ct do
lib.dbg('got path component ', {path.ptr[i].ptr, path.ptr[i].ct})
end
var actor = co.srv:actor_fetch_xid(handle)
if actor.ptr == nil then
co:complain(404,'no such user','no such user known to this server')
return
end
defer actor:free()
................................................................................
if not data then goto e404 end
do defer data:free() defer mime:free()
co:bytestream(mime,data)
return end
::e404:: do co:complain(404, 'artifact not found', 'no such artifact has been uploaded to this instance') return end
end
-- entry points
terra r.dispatch_http(co: &lib.srv.convo, uri: lib.mem.ptr(int8), meth: method.t)
lib.dbg('handling URI of form ', {uri.ptr,uri.ct})
co.navbar = lib.render.nav(co)
-- some routes are non-hierarchical, and can be resolved with a simple strcmp
-- we run through those first before giving up and parsing the URI
................................................................................
elseif uri:cmp( '/logout') then
if co.aid == 0
then goto notfound
else co:reroute_cookie('/','auth=; Path=/')
end
else -- hierarchical routes
var path = lib.http.hier(&co.srv.pool, uri) --defer path:free()
if path.ct > 1 and path(0):cmp(lib.str.lit('user')) then
http.actor_profile_uid(co, path, meth)
elseif path.ct > 1 and path(0):cmp(lib.str.lit('post')) then
http.tweet_page(co, path, meth)
elseif path(0):cmp(lib.str.lit('tl')) then
http.timeline(co, path)
elseif path(0):cmp(lib.str.lit('media')) then
if co.aid == 0 then goto unauth end
http.media_manager(co, path, meth, co.who.id)
elseif path(0):cmp(lib.str.lit('doc')) then
if not meth_get(meth) then goto wrongmeth end
http.documentation(co, path)
elseif path(0):cmp(lib.str.lit('conf')) then
if co.aid == 0 then goto unauth end
http.configure(co,path,meth)
else goto notfound end
end
do return end
::wrongmeth:: co:complain(405, 'method not allowed', 'that method is not meaningful for this endpoint') do return end
::notfound:: co:complain(404, 'not found', 'no such resource available') do return end
::unauth:: co:complain(401, 'unauthorized', 'this content is not available at your clearance level') do return end
end
|
<
<
<
<
>
>
>
>
>
>
|
|
|
>
>
>
>
|
|
|
|
17
18
19
20
21
22
23
24
25
26
27
28
29
30
...
106
107
108
109
110
111
112
113
114
115
116
117
118
119
...
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
...
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
|
var act = co:ppostv('act')
if rel.recip.block() then
if act:cmp('follow') or act:cmp('subscribe') then
co:complain(403,'blocked','you cannot follow a user you are blocked by') return
end
end
if act:cmp('circle') then
var allcircs = co.srv:circle_search(&co.srv.pool, co.who.id, 0)
var mycircs = co.srv:circle_memberships_uid(&co.srv.pool, co.who.id, actor.id)
var marked = co.srv.pool:alloc(bool, allcircs.ct)
var member = co.srv.pool:alloc(bool, allcircs.ct)
for i = 0, marked.ct do
marked(i) = false
member(i) = false
................................................................................
handle.ct = uri.ct - 2
uri:advance(uri.ct)
elseif handle.ct + 2 < uri.ct then uri:advance(handle.ct + 2) end
lib.dbg('looking up user by xid "', {handle.ptr,handle.ct} ,'", path: ', {uri.ptr,uri.ct})
var path = lib.http.hier(&co.srv.pool, uri) --defer path:free()
var actor = co.srv:actor_fetch_xid(handle)
if actor.ptr == nil then
co:complain(404,'no such user','no such user known to this server')
return
end
defer actor:free()
................................................................................
if not data then goto e404 end
do defer data:free() defer mime:free()
co:bytestream(mime,data)
return end
::e404:: do co:complain(404, 'artifact not found', 'no such artifact has been uploaded to this instance') return end
end
local json = {}
terra json.webfinger(co: &lib.srv.convo)
end
-- entry points
terra r.dispatch_http(co: &lib.srv.convo, uri: lib.mem.ptr(int8), meth: method.t)
lib.dbg('handling URI of form ', {uri.ptr,uri.ct})
co.navbar = lib.render.nav(co)
-- some routes are non-hierarchical, and can be resolved with a simple strcmp
-- we run through those first before giving up and parsing the URI
................................................................................
elseif uri:cmp( '/logout') then
if co.aid == 0
then goto notfound
else co:reroute_cookie('/','auth=; Path=/')
end
else -- hierarchical routes
var path = lib.http.hier(&co.srv.pool, uri) --defer path:free()
if path.ct > 1 and path(0):cmp('user') then
http.actor_profile_uid(co, path, meth)
elseif path.ct > 1 and path(0):cmp('post') then
http.tweet_page(co, path, meth)
elseif path(0):cmp('tl') then
http.timeline(co, path)
elseif path(0):cmp('.well-known') then
if path(1):cmp('webfinger') then
json.webfinger(co)
end
elseif path(0):cmp('media') then
if co.aid == 0 then goto unauth end
http.media_manager(co, path, meth, co.who.id)
elseif path(0):cmp('doc') then
if not meth_get(meth) then goto wrongmeth end
http.documentation(co, path)
elseif path(0):cmp('conf') then
if co.aid == 0 then goto unauth end
http.configure(co,path,meth)
else goto notfound end
end
do return end
::wrongmeth:: co:complain(405, 'method not allowed', 'that method is not meaningful for this endpoint') do return end
::notfound:: co:complain(404, 'not found', 'no such resource available') do return end
::unauth:: co:complain(401, 'unauthorized', 'this content is not available at your clearance level') do return end
end
|