If you want to do anything with Handhelj's databases, you'll need to know
the format.  Remember that all information is stored in m68k native byte order
so convert integers if you're reading on a different architecture.  This
document is accurate for Handhelj 1.3.0.

Kev Vance
October 26, 2002

##############################  ENTRY RECORDS  ###############################
##############################    VERSION 3    ###############################

All entries that await being posted are stored in the "Handhelj Entries"
database.  There is one record for each entry.  If the user has an incomplete
entry, it will be stored in the "Handhelj Inprogress" database.  The only
record in this database will be the incomplete entry.  The records in both
databases are in the following format:

HEADER
------
type		location		description
UInt16		00			Version of format (this ver=3)

The next section identifies which user wrote the entry.  This information can
be used to determine the user's password from the USER RECORDS.

USER INFORMATION
----------------
type		location		description
String		02			Login name of user, NUL terminated
String		02+login		Journal name of user, NUL terminated.
					If user is posting as herself, this is
					just a single NUL byte.
String		02+login+journal	Server name of user
UInt16		02+login+...+server	Server port of user

After the user information (location N), the entry and its metadata are
stored.

ENTRY
-----
type		location		description
Int16		N			Posting time: minutes (0..59)
Int16		N+2			Posting time: hours (0..23)
Int16		N+4			Posting time: day of month (1..31)
Int16		N+6			Posting time: month (1..12)
Int16		N+8			Posting time: year number
UInt8		N+10			Allow comments metadata (0=allow,
					1=disallow)
UInt8		N+11			Userpic number (0=default, 1=first
					pic, ...)
UInt8		N+12			Preformatted metadata (0=insert <BR>s,
					1=do not insert <BR>s)
UInt8		N+13			Backdated metadata (0=not backdated,
					1=backdated)
UInt8		N+14			Security metadata (0=public,
					1=friends-only, 2=private)
UInt16		N+15			Mood number (0=none, 1=custom,
					2=first mood in MOODS DB, ...)
String		N+17			Custom mood, NUL terminated.  If no
					custom mood, then a single NUL byte.
String		N+17+mood		Current music name, NUL terminated.
					If no music, then a single NUL byte.
String		N+17+mood+music		Entry subject, NUL terminated.  If no
					subject, then a single NUL byte.
String		N+17+mood+music+subject	Entry body, NUL terminated.  If no
					body, then a single NUL byte (this can
					only occur for an Inprogress entry)


###############################  MOOD RECORDS  ###############################
###############################   VERSION 1    ###############################

All moods are stored in the "Handhelj Moods" database.  There is one record
for each server/port combination.  (i.e. myjournal.com:8000 may have different
moods than myjournal.com:8001)  Each record is in the following format:

HEADER
------
type		location		description
UInt16		00			Version of format (this ver=1)
UInt8		02			Length of server string
String		03			Server string, NUL termated
UInt16		03 + length of server	Server port
UInt16		05 + length of server	Number of moods
UInt16		07 + length of server	Maximum mood ID

Directly after the header (location N), moods are stored one after the other.
Moods MUST be stored in alphabetical order.


MOODS
-----
type		location		description
String		N			Mood name, NUL terminated
UInt16		N + length of name	Mood ID


#############################  USERPIC RECORDS  ##############################
#############################     VERSION 3     ##############################

TO BE ESTABLISHED.


###############################  USER RECORDS  ###############################
###############################   VERSION 3    ###############################

All users are stored in the "Handhelj Users" database.  There is one record
for each user.  Each record is in the following format:

USER
----
type		location		description
UInt16		00			Version of format (this ver=3)
UInt16		02			Number of "post as" journals
UInt16		04			Number of userpics
UInt8		06			Use fast server (0=no, 1=yes)
String		07			Login name, NUL terminated
String		07+login		User's actual name, NUL terminated
String		07+login+name		Password, in ASCII MD5, NUL terminated
String		07+login+name+passwd	Server name, NUL terminated
UInt16		07+login+...+server	Server port

After the user information (location N), the list of "post as" journals is
stored:

JOURNALS
--------
type		location		description
String		N			Journal name, NUL terminated
String		N+last			Next journal name, NUL terminated
...

After the journals (location M), the userpic names and URLs are stored.  The
URLs point to locations on the internet where the userpic images can be
downloaded.  These pairs are stored one after the other.

USERPICS
-------------
type		location		description
String		M			Userpic name, NUL terminated
String		M+last			URL that matches the previous name,
					NUL terminated
...
