parsav  Check-in [251b382f5c]

Overview
Comment:somewhat defuckulate build system
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 251b382f5c302eb3ca626d539ec46e9876e54cb0a3c14d945b56421c8b50e7f4
User & Date: lexi on 2021-01-22 16:48:53
Other Links: manifest | tags
Context
2021-01-22
17:18
defuckulate bytestream_trusted check-in: 7af9e0961e user: lexi tags: trunk
16:48
somewhat defuckulate build system check-in: 251b382f5c user: lexi tags: trunk
2021-01-19
22:02
add dist mechanism check-in: d248dc5965 user: lexi tags: trunk
Changes

Modified config.lua from [cba33505b3] to [74b801cbf1].

   157    157   			if type(e) == 'function'
   158    158   				then return e(conf)
   159    159   				else return e
   160    160   			end
   161    161   		end
   162    162   		return coalesce(
   163    163   			pkgenv(v),
   164         -			pkv(e or v),
          164  +			e ~= false and pkv(e or v) or nil,
   165    165   			(fbo and eval(fbo[v])),
   166    166   			(fbv and eval(fbv[v])))
   167    167   	end
   168    168   	local name = cnfvar('override') or name
   169    169   	local pcname = coalesce(cnfvar('pcname'), name)
   170    170   	if conf.posix then
   171    171   		pkc  = function(...) if locdep then return nil end
................................................................................
   178    178   			end
   179    179   		else pkc = nul end
   180    180   	else
   181    181   		print '(warn) configuring on non-POSIX OS, all relevant paths must be specified manually in environment variables or build will fail!'
   182    182   	end
   183    183   	locdep = u.ping('./lib/' .. name)
   184    184   	local incdir, libdir, prefix
          185  +	local libsfx = coalesce(cnfvar('libsuffix',false),'')
          186  +	local incsfx = coalesce(cnfvar('incsuffix',false),'')
   185    187   	if locdep then
   186    188   		prefix = './lib/' .. name
   187         -		libdir = prefix .. coalesce(cnfvar('libbuilddir'),cnfvar('builddir'),'')
   188         -		incdir = prefix .. coalesce(cnfvar('srcincdir'),cnfvar('builddir'),'/include')
          189  +		libdir = prefix .. coalesce(cnfvar 'libbuilddir',cnfvar 'builddir','')
          190  +		incdir = prefix .. coalesce(cnfvar 'srcincdir',  cnfvar 'builddir','/include')
   189    191   	else
   190         -		prefix = coalesce(cnfvar('prefix'), '/usr')
   191         -		libdir = cnfvar('libdir')
   192         -		incdir = cnfvar('incdir','includedir')
          192  +		prefix = coalesce(cnfvar 'prefix', '/usr')
          193  +		libdir = cnfvar 'libdir'
          194  +			if libdir then libdir = libdir .. libsfx end
          195  +		incdir = cnfvar('incdir','includedir') 
          196  +			if incdir then incdir = incdir .. incsfx end
   193    197   	end
   194         -	libdir = libdir or prefix .. '/lib'
   195         -	incdir = incdir or prefix .. '/include'
          198  +	libdir = libdir or (prefix .. '/lib'     .. libsfx)
          199  +	incdir = incdir or (prefix .. '/include' .. incsfx)
   196    200   
   197    201   	local libstr = pkc '--libs-only-l' -- (--static is not reliable)
   198    202   	local libs = fb and fb.libs or {}
   199    203   	local linkstatic = locdep
   200    204   	if (not locdep) and libstr then
   201    205   		libs = {}
   202    206   		for m in string.gmatch(libstr, '-l(%g+)') do

Modified parsav.t from [b6e7e54998] to [dd405c9e82].

   433    433   lib.err = lib.loadlib('mbedtls','mbedtls/error.h')
   434    434   lib.rsa = lib.loadlib('mbedtls','mbedtls/rsa.h')
   435    435   lib.pk = lib.loadlib('mbedtls','mbedtls/pk.h')
   436    436   lib.md = lib.loadlib('mbedtls','mbedtls/md.h')
   437    437   lib.b64 = lib.loadlib('mbedtls','mbedtls/base64.h')
   438    438   lib.net = lib.loadlib('mongoose','mongoose.h')
   439    439   lib.pq = lib.loadlib('libpq','libpq-fe.h')
          440  +lib.jc = lib.loadlib('json-c','json.h')
   440    441   
   441    442   lib.load {
   442    443   	'mem', 'math', 'str', 'file', 'crypt', 'ipc';
   443    444   	'http', 'html', 'session', 'tpl', 'store', 'acl';
   444    445   
   445    446   	'smackdown'; -- md-alike parser
   446    447   }

Modified pkgdata.lua from [8c50f1b4b0] to [85c9cc69e8].

     5      5   	mbedtls = { 
     6      6   		libs = {'mbedtls', 'mbedcrypto', 'mbedx509'};
     7      7   		osvars = {
     8      8   			linux_nixos = { -- lacks a *.pc on nixos systems
     9      9   				prefix = sthunk('nix', 'path-info', 'nixos.mbedtls');
    10     10   			}
    11     11   		};
    12         -		vars = { builddir = '/library' };
           12  +		vars = { builddir = '/library', srcincdir = '/include' };
           13  +	};
           14  +	['json-c'] = {
           15  +		osvars = {
           16  +			linux_nixos = {
           17  +				prefix = sthunk('nix','path-info','nixos.json_c');
           18  +			};
           19  +		};
           20  +		vars = {
           21  +			builddir = '';
           22  +			incsuffix = '/json-c'; -- only used when path generated from prefix
           23  +		}
    13     24   	};
    14     25   	mongoose = { vars = { builddir = '' } };
    15     26   	libpq = {
    16     27   		osvars = {
    17     28   			linux_nixos = {
    18     29   				prefix = sthunk('nix', 'path-info', 'nixos.postgresql.lib');
    19     30   				incdir = function()
................................................................................
    21     32   					return (util.exec(a)) .. '/include';
    22     33   				end;
    23     34   			};
    24     35   		};
    25     36   		vars = {pcname = 'postgresql';}
    26     37   	};
    27     38   	libc = {
    28         -		libs = {'dl'}; -- libc.so does not need explicit mention
           39  +		libs = {'c'}; -- libc.so probably does not need explicit mention, but
    29     40   		osvars = {
           41  +			linux = { override = 'glibc'; };
    30     42   			linux_nixos = {
    31     43   				prefix = sthunk('nix', 'path-info', 'nixos.glibc');
    32     44   				override = 'glibc';
    33     45   			};
    34         -			linux = { override = 'glibc'; };
    35     46   		}
    36     47   	};
    37     48   }

Modified render/conf/users.t from [be5a9e1656] to [2f981259f7].

   182    182   			   :lpush('" max="'):push(lib.math.decstr(max, &decbuf[20]),0)
   183    183   			   :lpush('" value="'):push(lib.math.decstr(value, &decbuf[20]),0):lpush('"></div>')
   184    184   		end
   185    185   	end
   186    186   end)
   187    187   
   188    188   local input_pusher = function(kind,wrap,uniq)
   189         -	local fn = terra(acc: &lib.str.acc, name: pstr, val: pstr, lbl: pstr, on: bool, enabled: bool, class: pstr)
          189  +	local fn = terra(acc: &lib.str.acc, id: pstr, name: pstr, val: pstr, lbl: pstr, on: bool, enabled: bool, class: pstr)
   190    190   		if wrap then acc:lpush('<label>') end
   191    191   		acc:lpush(['<input type="'..kind..'" name="']):ppush(name)
   192    192   		if not wrap then
   193         -			acc:lpush('" id="'):ppush(name)
          193  +			acc:lpush('" id="'):ppush(id)
   194    194   			if uniq then acc:lpush('-'):ppush(val) end
   195    195   		end
   196    196   		if val:ref()   then acc:lpush('" value="'):ppush(val) end
   197    197   		if class:ref() then acc:lpush('" class="'):ppush(class) end
   198    198   		acc:lpush('"')
   199    199   		if on then acc:lpush(' checked') end
   200    200   		if not enabled then acc:lpush(' disabled') end
   201    201   		acc:lpush('>')
   202         -		if not wrap then acc:lpush('<label for="'):ppush(name)
          202  +		if not wrap then acc:lpush('<label for="'):ppush(id)
   203    203   		                 if uniq then acc:lpush('-'):ppush(val) end
   204    204   		                 acc:lpush('">')
   205    205   		            else acc:lpush(' ') end
   206    206   		acc:ppush(lbl):lpush('</label>')
   207    207   	end
   208    208   	fn.name = string.format('push-input-element<%q>',kind)
   209    209   	return fn
................................................................................
   273    273   				push_num_field(cinp, 'quota', 'quota', min, max, user.ptr.rights.quota, user.ptr.id == co.who.id and co.who.rights.rank ~= 1)
   274    274   			end
   275    275   			cinp:lpush('</div><div class="elem"><div class="check-panel">')
   276    276   
   277    277   			if user.ptr.id ~= co.who.id and
   278    278   			   ((user.ptr.rights.rank == 0 and co.who.rights.powers.elevate()) or
   279    279   				(user.ptr.rights.rank >  0 and co.who.rights.powers.demote())) then
   280         -				push_checkbox(&cinp, 'staff', pstr.null(), 'site staff member', user.ptr.rights.rank > 0, true, pstr.null())
          280  +				push_checkbox(&cinp, 'staff', 'staff', pstr.null(), 'site staff member', user.ptr.rights.rank > 0, true, pstr.null())
   281    281   			end
   282    282   
   283    283   			cinp:lpush('</div></div>')
   284    284   
   285    285   			if (co.who.rights.powers.elevate() or
   286    286   			   co.who.rights.powers.demote()) and user.ptr.id ~= co.who.id then
   287    287   				var map = array([lib.store.powmap])
................................................................................
   289    289   					for i=0, [map.type.N] do
   290    290   						if (co.who.rights.powers and map[i].val):sz() > 0 then
   291    291   							var on = (user.ptr.rights.powers and map[i].val):sz() > 0
   292    292   							var enabled = (     on  and co.who.rights.powers.demote() ) or
   293    293   										  ((not on) and co.who.rights.powers.elevate())
   294    294   							var namea: lib.str.acc namea:pcompose(&co.srv.pool,'power-', map[i].name)
   295    295   							var name = namea:finalize()
   296         -							push_pickbox(&cinp, name, pstr.null(), map[i].name, on, enabled, pstr.null())
          296  +							push_pickbox(&cinp, name, 'power', map[i].name, map[i].name, on, enabled, pstr.null())
   297    297   							--name:free()
   298    298   						end
   299    299   					end
   300    300   				cinp:lpush('</div></details>')
   301    301   			end
   302    302   
   303    303   			if co.who.id ~= uid and co.who.rights.powers.purge() then

Modified route.t from [48c04bb947] to [8f0d6bf9b0].

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

Modified srv.t from [fbf604f655] to [113b729c73].

   304    304   		self:rawpage(200, pg, [lib.mem.ptr(lib.http.header)] {
   305    305   			ptr = &hdrs[0], ct = 3
   306    306   		})
   307    307   	end
   308    308   end
   309    309   
   310    310   terra convo:stdpage(pg: convo.page) self:statpage(200, pg) end
          311  +
          312  +terra convo:bytestream_trusted(lockdown: bool, mime: pstring, data: lib.mem.ptr(uint8))
          313  +	var lockhdr = "Content-Security-Policy: sandbox; default-src 'none'; form-action 'none'; navigate-to 'none';\r\n"
          314  +	if not lockdown then lockhdr = "" end
          315  +	lib.net.mg_printf(self.con, "HTTP/1.1 200 OK\r\nContent-Type: %.*s\r\nContent-Length: %llu\r\n%sX-Content-Options: nosniff\r\n\r\n", mime.ct, mime.ptr, data.ct + 2, lockdown)
          316  +	lib.net.mg_send(self.con, data.ptr, data.ct)
          317  +	lib.net.mg_send(self.con, '\r\n', 2)
          318  +end
          319  +
          320  +terra convo:json(data: pstring)
          321  +	self:bytestream_trusted(false, 'application/ld+json', data:blob())
          322  +end
   311    323   
   312    324   terra convo:bytestream(mime: pstring, data: lib.mem.ptr(uint8))
   313    325   	-- TODO this is not a satisfactory solution; it's a bandaid on a gaping
   314    326   	-- chest wound. ultimately we need to compile a whitelist of safe mime
   315    327   	-- types as part of mimelib, but that is no small task. for now, this
   316    328   	-- will keep the patient from immediately bleeding out
   317    329   	if mime:cmp('text/html') or
................................................................................
   319    331   		mime:cmp('application/xhtml+xml') or
   320    332   		mime:cmp('application/vnd.wap.xhtml+xml')
   321    333   	then -- danger will robinson
   322    334   		mime = 'text/plain'
   323    335   	elseif mime:cmp('application/x-shockwave-flash') then
   324    336   		mime = 'application/octet-stream'
   325    337   	end
   326         -	lib.net.mg_printf(self.con, "HTTP/1.1 200 OK\r\nContent-Type: %.*s\r\nContent-Length: %llu\r\nContent-Security-Policy: sandbox; default-src 'none'; form-action 'none'; navigate-to 'none';\r\nX-Content-Options: nosniff\r\n\r\n", mime.ct, mime.ptr, data.ct + 2)
   327         -	lib.net.mg_send(self.con, data.ptr, data.ct)
   328         -	lib.net.mg_send(self.con, '\r\n', 2)
          338  +	self:bytestream_trusted(true, mime, data)
   329    339   end
   330    340   
   331    341   terra convo:reroute_cookie(dest: rawstring, cookie: rawstring)
   332    342   	var hdrs = array(
   333    343   		lib.http.header { key = 'Content-Type', value = 'text/html; charset=UTF-8' },
   334    344   		lib.http.header { key = 'Location',     value = dest },
   335    345   		lib.http.header { key = 'Set-Cookie',   value = cookie }