all repos — honk @ 6ee07c9220079022bb9bad6666e1a7be5642062d

my fork of honk

fun.go (view raw)

  1//
  2// Copyright (c) 2019 Ted Unangst <tedu@tedunangst.com>
  3//
  4// Permission to use, copy, modify, and distribute this software for any
  5// purpose with or without fee is hereby granted, provided that the above
  6// copyright notice and this permission notice appear in all copies.
  7//
  8// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 10// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 11// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 12// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 13// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 14// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 15
 16package main
 17
 18import (
 19	"crypto/rand"
 20	"crypto/sha512"
 21	"fmt"
 22	"html/template"
 23	"io"
 24	"net/http"
 25	"net/url"
 26	"os"
 27	"regexp"
 28	"strings"
 29	"time"
 30
 31	"github.com/dustin/go-humanize"
 32	"golang.org/x/net/html"
 33	"humungus.tedunangst.com/r/webs/cache"
 34	"humungus.tedunangst.com/r/webs/htfilter"
 35	"humungus.tedunangst.com/r/webs/httpsig"
 36	"humungus.tedunangst.com/r/webs/mz"
 37	"humungus.tedunangst.com/r/webs/templates"
 38)
 39
 40var allowedclasses = make(map[string]bool)
 41
 42func init() {
 43	allowedclasses["kw"] = true
 44	allowedclasses["bi"] = true
 45	allowedclasses["st"] = true
 46	allowedclasses["nm"] = true
 47	allowedclasses["tp"] = true
 48	allowedclasses["op"] = true
 49	allowedclasses["cm"] = true
 50	allowedclasses["al"] = true
 51	allowedclasses["dl"] = true
 52}
 53
 54var relingo = make(map[string]string)
 55
 56func loadLingo() {
 57	for _, l := range []string{"honked", "bonked", "honked back", "qonked", "evented"} {
 58		v := l
 59		k := "lingo-" + strings.ReplaceAll(l, " ", "")
 60		getconfig(k, &v)
 61		relingo[l] = v
 62	}
 63}
 64
 65func prettifydate(d time.Time) string {
 66	var customMags = []humanize.RelTimeMagnitude{
 67		{time.Second, "now", time.Second},
 68		{2 * time.Second, "1s %s", 1},
 69		{time.Minute, "%ds %s", time.Second},
 70		{2 * time.Minute, "1m %s", 1},
 71		{time.Hour, "%dm %s", time.Minute},
 72		{2 * time.Hour, "1h %s", 1},
 73		{humanize.Day, "%dh %s", time.Hour},
 74		{2 * humanize.Day, "1d %s", 1},
 75		{humanize.Week, "%dd %s", humanize.Day},
 76		{2 * humanize.Week, "1w %s", 1},
 77		{humanize.Month, "%dw %s", humanize.Week},
 78	}
 79
 80	since := time.Since(d)
 81	// More than a month, return the actual date.
 82	if since.Hours() > 730 {
 83		return d.Format("02 Jan 2006 15:04")
 84	}
 85
 86	return humanize.CustomRelTime(d, time.Now(), "", "from now", customMags)
 87}
 88
 89func reverbolate(userid int64, honks []*Honk) {
 90	var user *WhatAbout
 91	somenumberedusers.Get(userid, &user)
 92	for _, h := range honks {
 93		// idk where else to put this
 94		h.DatePretty = prettifydate(h.Date)
 95		h.What += "ed"
 96		if h.What == "honked" && h.RID != "" {
 97			h.What = "honked back"
 98			h.Style += " subtle"
 99		}
100		if !h.Public {
101			h.Style += " limited"
102		}
103		if h.Whofore == 1 {
104			h.Style += " atme"
105		}
106		translate(h)
107		local := false
108		if h.Whofore == 2 || h.Whofore == 3 {
109			local = true
110		}
111		if local && h.What != "bonked" {
112			h.Noise = re_retag.ReplaceAllString(h.Noise, "")
113			h.Noise = re_memes.ReplaceAllString(h.Noise, "")
114		}
115		h.Username, h.Handle = handles(h.Honker)
116		if !local {
117			short := shortname(userid, h.Honker)
118			if short != "" {
119				h.Username = short
120			} else {
121				h.Username = h.Handle
122				if len(h.Username) > 20 {
123					h.Username = h.Username[:20] + ".."
124				}
125			}
126		}
127		if user != nil {
128			hset := []string{}
129			if h.Honker != user.URL {
130				hset = append(hset, "@"+h.Handle)
131			}
132			if user.Options.MentionAll {
133				for _, a := range h.Audience {
134					if a == h.Honker || a == user.URL {
135						continue
136					}
137					_, hand := handles(a)
138					if hand != "" {
139						hand = "@" + hand
140						hset = append(hset, hand)
141					}
142				}
143			}
144			h.Handles = strings.Join(hset, " ")
145		}
146		if h.URL == "" {
147			h.URL = h.XID
148		}
149		if h.Oonker != "" {
150			_, h.Oondle = handles(h.Oonker)
151		}
152		h.Precis = demoji(h.Precis)
153		h.Noise = demoji(h.Noise)
154		h.Open = "open"
155		var misto string
156		for _, m := range h.Mentions {
157			if m.Where != h.Honker && !m.IsPresent(h.Noise) {
158				misto += " " + m.Who
159			}
160		}
161		var mistag string
162		for _, o := range h.Onts {
163			if !OntIsPresent(o, h.Noise) {
164				mistag += " " + o
165			}
166		}
167		if len(misto) > 0 || len(mistag) > 0 {
168			if len(misto) > 0 {
169				misto = "(" + misto[1:] + ")<p>"
170			}
171			if len(mistag) > 0 {
172				mistag = "<p>(" + mistag[1:] + ")"
173			}
174			h.Noise = misto + h.Noise + mistag
175		}
176
177		zap := make(map[string]bool)
178		{
179			var htf htfilter.Filter
180			htf.Imager = replaceimgsand(zap, false)
181			htf.SpanClasses = allowedclasses
182			htf.BaseURL, _ = url.Parse(h.XID)
183			emuxifier := func(e string) string {
184				for _, d := range h.Donks {
185					if d.Name == e {
186						zap[d.XID] = true
187						if d.Local {
188							return fmt.Sprintf(`<img class="emu" title="%s" src="/d/%s">`, d.Name, d.XID)
189						}
190					}
191				}
192				if local && h.What != "bonked" {
193					var emu Emu
194					emucache.Get(e, &emu)
195					if emu.ID != "" {
196						return fmt.Sprintf(`<img class="emu" title="%s" src="%s">`, emu.Name, emu.ID)
197					}
198				}
199				return e
200			}
201			htf.FilterText = func(w io.Writer, data string) {
202				data = htfilter.EscapeText(data)
203				data = re_emus.ReplaceAllStringFunc(data, emuxifier)
204				io.WriteString(w, data)
205			}
206			if user != nil {
207				htf.RetargetLink = func(href string) string {
208					h2 := strings.ReplaceAll(href, "/@", "/users/")
209					for _, m := range h.Mentions {
210						if h2 == m.Where || href == m.Where {
211							return "/h?xid=" + url.QueryEscape(m.Where)
212						}
213					}
214					return href
215				}
216			}
217			p, _ := htf.String(h.Precis)
218			n, _ := htf.String(h.Noise)
219			h.Precis = string(p)
220			h.Noise = string(n)
221		}
222		j := 0
223		for i := 0; i < len(h.Donks); i++ {
224			if !zap[h.Donks[i].XID] {
225				h.Donks[j] = h.Donks[i]
226				j++
227			}
228		}
229		h.Donks = h.Donks[:j]
230	}
231
232	unsee(honks, userid)
233
234	for _, h := range honks {
235		renderflags(h)
236
237		h.HTPrecis = template.HTML(h.Precis)
238		h.HTML = template.HTML(h.Noise)
239		if redo := relingo[h.What]; redo != "" {
240			h.What = redo
241		}
242	}
243}
244
245func replaceimgsand(zap map[string]bool, absolute bool) func(node *html.Node) string {
246	return func(node *html.Node) string {
247		src := htfilter.GetAttr(node, "src")
248		alt := htfilter.GetAttr(node, "alt")
249		//title := GetAttr(node, "title")
250		if htfilter.HasClass(node, "Emoji") && alt != "" {
251			return alt
252		}
253		d := finddonk(src)
254		if d != nil {
255			zap[d.XID] = true
256			base := ""
257			if absolute {
258				base = "https://" + serverName
259			}
260			return string(templates.Sprintf(`<img alt="%s" title="%s" src="%s/d/%s">`, alt, alt, base, d.XID))
261		}
262		return string(templates.Sprintf(`&lt;img alt="%s" src="<a href="%s">%s</a>"&gt;`, alt, src, src))
263	}
264}
265
266func translatechonk(ch *Chonk) {
267	noise := ch.Noise
268	if ch.Format == "markdown" {
269		var marker mz.Marker
270		noise = marker.Mark(noise)
271	}
272	var htf htfilter.Filter
273	htf.SpanClasses = allowedclasses
274	htf.BaseURL, _ = url.Parse(ch.XID)
275	ch.HTML, _ = htf.String(noise)
276}
277
278func filterchonk(ch *Chonk) {
279	translatechonk(ch)
280
281	noise := string(ch.HTML)
282
283	local := originate(ch.XID) == serverName
284
285	zap := make(map[string]bool)
286	emuxifier := func(e string) string {
287		for _, d := range ch.Donks {
288			if d.Name == e {
289				zap[d.XID] = true
290				if d.Local {
291					return fmt.Sprintf(`<img class="emu" title="%s" src="/d/%s">`, d.Name, d.XID)
292				}
293			}
294		}
295		if local {
296			var emu Emu
297			emucache.Get(e, &emu)
298			if emu.ID != "" {
299				return fmt.Sprintf(`<img class="emu" title="%s" src="%s">`, emu.Name, emu.ID)
300			}
301		}
302		return e
303	}
304	noise = re_emus.ReplaceAllStringFunc(noise, emuxifier)
305	j := 0
306	for i := 0; i < len(ch.Donks); i++ {
307		if !zap[ch.Donks[i].XID] {
308			ch.Donks[j] = ch.Donks[i]
309			j++
310		}
311	}
312	ch.Donks = ch.Donks[:j]
313
314	if strings.HasPrefix(noise, "<p>") {
315		noise = noise[3:]
316	}
317	ch.HTML = template.HTML(noise)
318	if short := shortname(ch.UserID, ch.Who); short != "" {
319		ch.Handle = short
320	} else {
321		ch.Handle, _ = handles(ch.Who)
322	}
323
324}
325
326func inlineimgsfor(honk *Honk) func(node *html.Node) string {
327	return func(node *html.Node) string {
328		src := htfilter.GetAttr(node, "src")
329		alt := htfilter.GetAttr(node, "alt")
330		d := savedonk(src, "image", alt, "image", true)
331		if d != nil {
332			honk.Donks = append(honk.Donks, d)
333		}
334		dlog.Printf("inline img with src: %s", src)
335		return ""
336	}
337}
338
339func imaginate(honk *Honk) {
340	var htf htfilter.Filter
341	htf.Imager = inlineimgsfor(honk)
342	htf.BaseURL, _ = url.Parse(honk.XID)
343	htf.String(honk.Noise)
344}
345
346var re_dangerous = regexp.MustCompile("^[a-zA-Z]{2}:")
347
348func precipitate(honk *Honk) {
349	noise := honk.Noise
350	if re_dangerous.MatchString(noise) {
351		idx := strings.Index(noise, "\n")
352		if idx == -1 {
353			honk.Precis = noise
354			noise = ""
355		} else {
356			honk.Precis = noise[:idx]
357			noise = noise[idx+1:]
358		}
359		var marker mz.Marker
360		honk.Precis = marker.Mark(strings.TrimSpace(honk.Precis))
361		honk.Noise = noise
362	}
363}
364
365func translate(honk *Honk) {
366	if honk.Format == "html" {
367		return
368	}
369	noise := honk.Noise
370
371	var marker mz.Marker
372	marker.HashLinker = ontoreplacer
373	marker.AtLinker = attoreplacer
374	marker.AllowImages = true
375	noise = strings.TrimSpace(noise)
376	noise = marker.Mark(noise)
377	honk.Noise = noise
378	honk.Onts = oneofakind(append(honk.Onts, marker.HashTags...))
379	honk.Mentions = bunchofgrapes(marker.Mentions)
380}
381
382func redoimages(honk *Honk) {
383	zap := make(map[string]bool)
384	{
385		var htf htfilter.Filter
386		htf.Imager = replaceimgsand(zap, true)
387		htf.SpanClasses = allowedclasses
388		p, _ := htf.String(honk.Precis)
389		n, _ := htf.String(honk.Noise)
390		honk.Precis = string(p)
391		honk.Noise = string(n)
392	}
393	j := 0
394	for i := 0; i < len(honk.Donks); i++ {
395		if !zap[honk.Donks[i].XID] {
396			honk.Donks[j] = honk.Donks[i]
397			j++
398		}
399	}
400	honk.Donks = honk.Donks[:j]
401
402	honk.Noise = re_memes.ReplaceAllString(honk.Noise, "")
403	honk.Noise = strings.Replace(honk.Noise, "<a href=", "<a class=\"mention u-url\" href=", -1)
404}
405
406func xcelerate(b []byte) string {
407	letters := "BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz1234567891234567891234"
408	for i, c := range b {
409		b[i] = letters[c&63]
410	}
411	s := string(b)
412	return s
413}
414
415func shortxid(xid string) string {
416	h := sha512.New512_256()
417	io.WriteString(h, xid)
418	return xcelerate(h.Sum(nil)[:20])
419}
420
421func xfiltrate() string {
422	var b [18]byte
423	rand.Read(b[:])
424	return xcelerate(b[:])
425}
426
427func grapevine(mentions []Mention) []string {
428	var s []string
429	for _, m := range mentions {
430		s = append(s, m.Where)
431	}
432	return s
433}
434
435func bunchofgrapes(m []string) []Mention {
436	var mentions []Mention
437	for i := range m {
438		where := gofish(m[i])
439		if where != "" {
440			mentions = append(mentions, Mention{Who: m[i], Where: where})
441		}
442	}
443	return mentions
444}
445
446type Emu struct {
447	ID   string
448	Name string
449	Type string
450}
451
452var re_emus = regexp.MustCompile(`:[[:alnum:]_-]+:`)
453
454var emucache = cache.New(cache.Options{Filler: func(ename string) (Emu, bool) {
455	fname := ename[1 : len(ename)-1]
456	exts := []string{".png", ".gif"}
457	for _, ext := range exts {
458		_, err := os.Stat(dataDir + "/emus/" + fname + ext)
459		if err != nil {
460			continue
461		}
462		url := fmt.Sprintf("https://%s/emu/%s%s", serverName, fname, ext)
463		if develMode {
464			url = fmt.Sprintf("/emu/%s%s", fname, ext)
465		}
466		return Emu{ID: url, Name: ename, Type: "image/" + ext[1:]}, true
467	}
468	return Emu{Name: ename, ID: "", Type: "image/png"}, true
469}, Duration: 10 * time.Second})
470
471func herdofemus(noise string) []Emu {
472	m := re_emus.FindAllString(noise, -1)
473	m = oneofakind(m)
474	var emus []Emu
475	for _, e := range m {
476		var emu Emu
477		emucache.Get(e, &emu)
478		if emu.ID == "" {
479			continue
480		}
481		emus = append(emus, emu)
482	}
483	return emus
484}
485
486var re_memes = regexp.MustCompile("meme: ?([^\n]+)")
487var re_avatar = regexp.MustCompile("avatar: ?([^\n]+)")
488var re_banner = regexp.MustCompile("banner: ?([^\n]+)")
489var re_convoy = regexp.MustCompile("convoy: ?([^\n]+)")
490var re_retag = regexp.MustCompile("tags: ?([^\n]+)")
491var re_convalidate = regexp.MustCompile("^(https?|tag|data):")
492
493func memetize(honk *Honk) {
494	repl := func(x string) string {
495		name := x[5:]
496		if name[0] == ' ' {
497			name = name[1:]
498		}
499		fd, err := os.Open(dataDir + "/memes/" + name)
500		if err != nil {
501			ilog.Printf("no meme for %s", name)
502			return x
503		}
504		var peek [512]byte
505		n, _ := fd.Read(peek[:])
506		ct := http.DetectContentType(peek[:n])
507		fd.Close()
508
509		url := fmt.Sprintf("https://%s/meme/%s", serverName, name)
510		fileid, err := savefile(name, name, url, ct, false, nil)
511		if err != nil {
512			elog.Printf("error saving meme: %s", err)
513			return x
514		}
515		d := &Donk{
516			FileID: fileid,
517			Name:   name,
518			Media:  ct,
519			URL:    url,
520			Local:  false,
521		}
522		honk.Donks = append(honk.Donks, d)
523		return ""
524	}
525	honk.Noise = re_memes.ReplaceAllStringFunc(honk.Noise, repl)
526}
527
528func recategorize(honk *Honk) {
529	repl := func(x string) string {
530		x = x[5:]
531		for _, t := range strings.Split(x, " ") {
532			if t == "" {
533				continue
534			}
535			if t[0] != '#' {
536				t = "#" + t
537			}
538			dlog.Printf("hashtag: %s", t)
539			honk.Onts = append(honk.Onts, t)
540		}
541		return ""
542	}
543	honk.Noise = re_retag.ReplaceAllStringFunc(honk.Noise, repl)
544}
545
546var re_quickmention = regexp.MustCompile("(^|[ \n])@[[:alnum:]_]+([ \n:;.,']|$)")
547
548func quickrename(s string, userid int64) string {
549	nonstop := true
550	for nonstop {
551		nonstop = false
552		s = re_quickmention.ReplaceAllStringFunc(s, func(m string) string {
553			prefix := ""
554			if m[0] == ' ' || m[0] == '\n' {
555				prefix = m[:1]
556				m = m[1:]
557			}
558			prefix += "@"
559			m = m[1:]
560			tail := ""
561			if last := m[len(m)-1]; last == ' ' || last == '\n' ||
562				last == ':' || last == ';' ||
563				last == '.' || last == ',' || last == '\'' {
564				tail = m[len(m)-1:]
565				m = m[:len(m)-1]
566			}
567
568			xid := fullname(m, userid)
569
570			if xid != "" {
571				_, name := handles(xid)
572				if name != "" {
573					nonstop = true
574					m = name
575				}
576			}
577			return prefix + m + tail
578		})
579	}
580	return s
581}
582
583var shortnames = cache.New(cache.Options{Filler: func(userid int64) (map[string]string, bool) {
584	honkers := gethonkers(userid)
585	m := make(map[string]string)
586	for _, h := range honkers {
587		m[h.XID] = h.Name
588	}
589	return m, true
590}, Invalidator: &honkerinvalidator})
591
592func shortname(userid int64, xid string) string {
593	var m map[string]string
594	ok := shortnames.Get(userid, &m)
595	if ok {
596		return m[xid]
597	}
598	return ""
599}
600
601var fullnames = cache.New(cache.Options{Filler: func(userid int64) (map[string]string, bool) {
602	honkers := gethonkers(userid)
603	m := make(map[string]string)
604	for _, h := range honkers {
605		m[h.Name] = h.XID
606	}
607	return m, true
608}, Invalidator: &honkerinvalidator})
609
610func fullname(name string, userid int64) string {
611	var m map[string]string
612	ok := fullnames.Get(userid, &m)
613	if ok {
614		return m[name]
615	}
616	return ""
617}
618
619func attoreplacer(m string) string {
620	fill := `<span class="h-card"><a class="u-url mention" href="%s">%s</a></span>`
621	where := gofish(m)
622	if where == "" {
623		return m
624	}
625	who := m[0 : 1+strings.IndexByte(m[1:], '@')]
626	return fmt.Sprintf(fill, html.EscapeString(where), html.EscapeString(who))
627}
628
629func ontoreplacer(h string) string {
630	return fmt.Sprintf(`<a class="mention hashtag" href="https://%s/o/%s">%s</a>`, serverName,
631		strings.ToLower(h[1:]), h)
632}
633
634var re_unurl = regexp.MustCompile("https://([^/]+).*/([^/]+)")
635var re_urlhost = regexp.MustCompile("https://([^/ #)]+)")
636
637func originate(u string) string {
638	m := re_urlhost.FindStringSubmatch(u)
639	if len(m) > 1 {
640		return m[1]
641	}
642	return ""
643}
644
645var allhandles = cache.New(cache.Options{Filler: func(xid string) (string, bool) {
646	handle := getxonker(xid, "handle")
647	if handle == "" {
648		dlog.Printf("need to get a handle: %s", xid)
649		info, err := investigate(xid)
650		if err != nil {
651			m := re_unurl.FindStringSubmatch(xid)
652			if len(m) > 2 {
653				handle = m[2]
654			} else {
655				handle = xid
656			}
657		} else {
658			handle = info.Name
659		}
660	}
661	return handle, true
662}})
663
664// handle, handle@host
665func handles(xid string) (string, string) {
666	if xid == "" || xid == thewholeworld || strings.HasSuffix(xid, "/followers") {
667		return "", ""
668	}
669	var handle string
670	allhandles.Get(xid, &handle)
671	if handle == xid {
672		return xid, xid
673	}
674	return handle, handle + "@" + originate(xid)
675}
676
677func butnottooloud(aud []string) {
678	for i, a := range aud {
679		if strings.HasSuffix(a, "/followers") {
680			aud[i] = ""
681		}
682	}
683}
684
685func loudandproud(aud []string) bool {
686	for _, a := range aud {
687		if a == thewholeworld {
688			return true
689		}
690	}
691	return false
692}
693
694func firstclass(honk *Honk) bool {
695	return honk.Audience[0] == thewholeworld
696}
697
698func oneofakind(a []string) []string {
699	seen := make(map[string]bool)
700	seen[""] = true
701	j := 0
702	for _, s := range a {
703		if !seen[s] {
704			seen[s] = true
705			a[j] = s
706			j++
707		}
708	}
709	return a[:j]
710}
711
712var ziggies = cache.New(cache.Options{Filler: func(userid int64) (*KeyInfo, bool) {
713	var user *WhatAbout
714	ok := somenumberedusers.Get(userid, &user)
715	if !ok {
716		return nil, false
717	}
718	ki := new(KeyInfo)
719	ki.keyname = user.URL + "#key"
720	ki.seckey = user.SecKey
721	return ki, true
722}})
723
724func ziggy(userid int64) *KeyInfo {
725	var ki *KeyInfo
726	ziggies.Get(userid, &ki)
727	return ki
728}
729
730var zaggies = cache.New(cache.Options{Filler: func(keyname string) (httpsig.PublicKey, bool) {
731	data := getxonker(keyname, "pubkey")
732	if data == "" {
733		dlog.Printf("hitting the webs for missing pubkey: %s", keyname)
734		j, err := GetJunk(readyLuserOne, keyname)
735		if err != nil {
736			ilog.Printf("error getting %s pubkey: %s", keyname, err)
737			when := time.Now().UTC().Format(dbtimeformat)
738			stmtSaveXonker.Exec(keyname, "failed", "pubkey", when)
739			return httpsig.PublicKey{}, true
740		}
741		allinjest(originate(keyname), j)
742		data = getxonker(keyname, "pubkey")
743		if data == "" {
744			ilog.Printf("key not found after ingesting")
745			when := time.Now().UTC().Format(dbtimeformat)
746			stmtSaveXonker.Exec(keyname, "failed", "pubkey", when)
747			return httpsig.PublicKey{}, true
748		}
749	}
750	if data == "failed" {
751		ilog.Printf("lookup previously failed key %s", keyname)
752		return httpsig.PublicKey{}, true
753	}
754	_, key, err := httpsig.DecodeKey(data)
755	if err != nil {
756		ilog.Printf("error decoding %s pubkey: %s", keyname, err)
757		return key, true
758	}
759	return key, true
760}, Limit: 512})
761
762func zaggy(keyname string) (httpsig.PublicKey, error) {
763	var key httpsig.PublicKey
764	zaggies.Get(keyname, &key)
765	return key, nil
766}
767
768func savingthrow(keyname string) {
769	when := time.Now().Add(-30 * time.Minute).UTC().Format(dbtimeformat)
770	stmtDeleteXonker.Exec(keyname, "pubkey", when)
771	zaggies.Clear(keyname)
772}
773
774func keymatch(keyname string, actor string) string {
775	origin := originate(actor)
776	if origin == originate(keyname) {
777		return origin
778	}
779	return ""
780}