incident

package
v1.8.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2024 License: BSD-3-Clause Imports: 16 Imported by: 4

Documentation

Overview

Package incident manages collections of related messages.

An incident is stored on disk as a directory of message files; each separate incident is a separate directory. Specifically, package incident always works with the message files in the current working directory of the calling program.

Within the directory, each non-receipt message is stored in a file called «LMI».txt, where «LMI» is the local message ID for the message. If the remote message ID for the message is known, a symbolic link «RMI».txt points to «LMI».txt.

Messages are automatically rendered in PDF format if the message type supports it and PDF rendering is built into the program; the PDF version is stored in «LMI».pdf, with possible symbolic link from «RMI».pdf.

Delivery and read receipts are stored in «LMI».DR.txt and «LMI».RR.txt, respectively; there are no «RMI» symbolic links for those.

On request, package incident can also generate an ICS-309 message log for the messages in the directory. This is stored in CSV format in ics309.csv, and if PDF rendering is built into the program, it is rendered in PDF format in ics309.pdf as well. Both files are automatically removed when any message is changed, so that the directory does not contain a stale log.

Index

Constants

This section is empty.

Variables

View Source
var ErrDuplicateReceipt = errors.New("duplicate receipt")
View Source
var MsgIDRE = regexp.MustCompile(`^([0-9][A-Z]{2}|[A-Z][A-Z0-9]{2})-([1-9][0-9]{2,}|0[1-9][0-9]|00[1-9])([A-Z]?)$`)

MsgIDRE is a regular expression matching a valid message ID. Its substrings are the three-character prefix, the three-or-more-digit sequence number, and the optional suffix character.

Functions

func AllLMIs

func AllLMIs() (lmis []string, err error)

AllLMIs returns a list of local message IDs of all messages in the directory. The list is in chronological order. An error is returned only if the directory cannot be read.

func GenerateICS309

func GenerateICS309(header *ICS309Header) (err error)

GenerateICS309 generates an ICS-309 communications log covering all of the messages in the directory. The log is generated in CSV format (ics309.csv), and if PDF rendering support is built into the program, it is also generated in PDF format (ics309.pdf). GenerateICS309 returns an error if the directory could not be read or the files could not be written. Note that the generated files are removed by any call to SaveMessage or SaveReceipt, since they could be stale.

func HasDeliveryReceipt

func HasDeliveryReceipt(lmi string) bool

HasDeliveryReceipt returns whether the message with the specified LMI has a delivery receipt.

func LMIForRMI

func LMIForRMI(rmi string) string

LMIForRMI returns the LMI for the message with the given RMI, if any. It returns "" if the RMI doesn't exist.

func MessageExists

func MessageExists(lmi string) bool

MessageExists returns true if a message exists with the specified LMI.

func ReadMessage

func ReadMessage(lmi string) (env *envelope.Envelope, msg message.Message, err error)

ReadMessage reads a message from the incident directory and returns it.

func ReadReceipt added in v1.8.3

func ReadReceipt(lmi, rtype string) (env *envelope.Envelope, msg message.Message, err error)

ReadReceipt reads a receipt for a message. rtype must be "DR" or "RR".

func ReceiveMessage

func ReceiveMessage(raw, bbs, area, msgid, opcall, opname string) (
	lmi string, env *envelope.Envelope, msg message.Message, oenv *envelope.Envelope, omsg message.Message, err error,
)

ReceiveMessage takes a raw message received from JNOS and saves it in the incident. "bbs" and "area" are the names of the BBS from which the message was retrieved and, if the message is a bulletin, the bulletin area from which it was retrieved. "msgid" is the message ID pattern; a unique ID will be given to the new message using this pattern if it needs one. "opcall" and "opname" are the operator call sign and name to put into the received message.

If the received message is a human-originated message, it will be returned as "lmi", "env", and "msg". If a delivery receipt should be sent for it, the receipt is returned as "oenv" and "omsg". (Note that the delivery receipt has not been saved; the caller should do that after sending it.)

If the received message is a receipt, it will be returned as "env" and "msg". If the receipt can be matched against a previously sent message in the incident, that previously sent message is returned as "lmi", "oenv", and "omsg" are the message for which it is a receipt. Note: in the case where a receipt has already been received for the message, all five return values are filled in, and "err" will be ErrDuplicateReceipt.

If the received message has an error, "err" will be set and the other return values will be zero.

func RemoteMap

func RemoteMap() (m map[string]string, err error)

RemoteMap returns a map from local message ID to remote message ID for those messages that have a remote message ID. It returns an error only if the directory cannot be read.

func RemoveICS309s

func RemoveICS309s()

RemoveICS309s removes generated ICS-309 communication log files.

func RemoveMessage

func RemoveMessage(lmi string)

RemoveMessage removes the message with the specified LMI.

func SaveMessage

func SaveMessage(lmi, rmi string, env *envelope.Envelope, msg message.Message, fast, rawsubj bool) (err error)

SaveMessage saves a (non-receipt) message to the incident directory, overwriting any previous message stored with the same LMI. If fast is true, PDFs are not generated even when possible; stale PDFs are removed. If rawsubj is true, the envelope Subject: line is left unchanged rather than being regenerated based on the message contents.

func SaveReceipt

func SaveReceipt(lmi string, env *envelope.Envelope, msg message.Message) (err error)

SaveReceipt saves a receipt message to the incident directory, overwriting any previous stored receipt of the same type with the same LMI.

func SeqToLMI

func SeqToLMI(seq int, remote bool) (lmis []string, err error)

SeqToLMI takes a sequence number and expands it to a list of existing message LMIs with that sequence number. If remote is true, the LMIs of messages whose RMI has the requested sequence number are also included. The LMIs are returned in unspecified order. An error is returned only if the directory cannot be read.

func UniqueMessageID

func UniqueMessageID(id string) string

UniqueMessageID returns the provided message ID if there is no existing message in the directory with that ID (local or remote). Otherwise, it increments the sequence number until the message ID is unused, and returns the result.

Types

type ICS309Header

type ICS309Header struct {
	IncidentName  string
	ActivationNum string
	OpStartDate   string
	OpStartTime   string
	OpEndDate     string
	OpEndTime     string
	OpCall        string
	OpName        string
	TacCall       string
	TacName       string
}

An ICS309Header structure contains all of the information needed for the header of an ICS-309 communications log.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL