]> git.r.bdr.sh - rbdr/mobius/blobdiff - hotline/transaction_handlers.go
Adopt more fixed size array types for struct fields
[rbdr/mobius] / hotline / transaction_handlers.go
index 20b87e2118105e0cdbd977f5a0dc19eba9db6c12..3d7ba14ec03931cf9a1119f927ac561bd410da7e 100644 (file)
@@ -373,6 +373,8 @@ func HandleSendInstantMsg(cc *ClientConn, t *Transaction) (res []Transaction, er
        return res, err
 }
 
        return res, err
 }
 
+var fileTypeFLDR = [4]byte{0x66, 0x6c, 0x64, 0x72}
+
 func HandleGetFileInfo(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
        fileName := t.GetField(FieldFileName).Data
        filePath := t.GetField(FieldFilePath).Data
 func HandleGetFileInfo(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
        fileName := t.GetField(FieldFileName).Data
        filePath := t.GetField(FieldFilePath).Data
@@ -396,9 +398,9 @@ func HandleGetFileInfo(cc *ClientConn, t *Transaction) (res []Transaction, err e
                NewField(FieldFileName, []byte(encodedName)),
                NewField(FieldFileTypeString, fw.ffo.FlatFileInformationFork.friendlyType()),
                NewField(FieldFileCreatorString, fw.ffo.FlatFileInformationFork.friendlyCreator()),
                NewField(FieldFileName, []byte(encodedName)),
                NewField(FieldFileTypeString, fw.ffo.FlatFileInformationFork.friendlyType()),
                NewField(FieldFileCreatorString, fw.ffo.FlatFileInformationFork.friendlyCreator()),
-               NewField(FieldFileType, fw.ffo.FlatFileInformationFork.TypeSignature),
-               NewField(FieldFileCreateDate, fw.ffo.FlatFileInformationFork.CreateDate),
-               NewField(FieldFileModifyDate, fw.ffo.FlatFileInformationFork.ModifyDate),
+               NewField(FieldFileType, fw.ffo.FlatFileInformationFork.TypeSignature[:]),
+               NewField(FieldFileCreateDate, fw.ffo.FlatFileInformationFork.CreateDate[:]),
+               NewField(FieldFileModifyDate, fw.ffo.FlatFileInformationFork.ModifyDate[:]),
        }
 
        // Include the optional FileComment field if there is a comment.
        }
 
        // Include the optional FileComment field if there is a comment.
@@ -407,7 +409,7 @@ func HandleGetFileInfo(cc *ClientConn, t *Transaction) (res []Transaction, err e
        }
 
        // Include the FileSize field for files.
        }
 
        // Include the FileSize field for files.
-       if !bytes.Equal(fw.ffo.FlatFileInformationFork.TypeSignature, []byte{0x66, 0x6c, 0x64, 0x72}) {
+       if fw.ffo.FlatFileInformationFork.TypeSignature != fileTypeFLDR {
                fields = append(fields, NewField(FieldFileSize, fw.totalSize()))
        }
 
                fields = append(fields, NewField(FieldFileSize, fw.totalSize()))
        }
 
@@ -773,7 +775,6 @@ func HandleListUsers(cc *ClientConn, t *Transaction) (res []Transaction, err err
 // performed.  This seems to be the only place in the Hotline protocol where a data field contains another data field.
 func HandleUpdateUser(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
        for _, field := range t.Fields {
 // performed.  This seems to be the only place in the Hotline protocol where a data field contains another data field.
 func HandleUpdateUser(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
        for _, field := range t.Fields {
-
                var subFields []Field
 
                // Create a new scanner for parsing incoming bytes into transaction tokens
                var subFields []Field
 
                // Create a new scanner for parsing incoming bytes into transaction tokens
@@ -995,9 +996,7 @@ func HandleGetClientInfoText(cc *ClientConn, t *Transaction) (res []Transaction,
 }
 
 func HandleGetUserNameList(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
 }
 
 func HandleGetUserNameList(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
-       res = append(res, cc.NewReply(t, cc.Server.connectedUsers()...))
-
-       return res, err
+       return []Transaction{cc.NewReply(t, cc.Server.connectedUsers()...)}, nil
 }
 
 func HandleTranAgreed(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
 }
 
 func HandleTranAgreed(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
@@ -1256,8 +1255,9 @@ func HandleNewNewsFldr(cc *ClientConn, t *Transaction) (res []Transaction, err e
 func HandleGetNewsArtNameList(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
        if !cc.Authorize(accessNewsReadArt) {
                res = append(res, cc.NewErrReply(t, "You are not allowed to read news."))
 func HandleGetNewsArtNameList(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
        if !cc.Authorize(accessNewsReadArt) {
                res = append(res, cc.NewErrReply(t, "You are not allowed to read news."))
-               return res, err
+               return res, nil
        }
        }
+
        pathStrs := ReadNewsPath(t.GetField(FieldNewsPath).Data)
 
        var cat NewsCategoryListData15
        pathStrs := ReadNewsPath(t.GetField(FieldNewsPath).Data)
 
        var cat NewsCategoryListData15
@@ -1272,11 +1272,11 @@ func HandleGetNewsArtNameList(cc *ClientConn, t *Transaction) (res []Transaction
 
        b, err := io.ReadAll(&nald)
        if err != nil {
 
        b, err := io.ReadAll(&nald)
        if err != nil {
-
+               return res, fmt.Errorf("error loading news articles: %w", err)
        }
 
        res = append(res, cc.NewReply(t, NewField(FieldNewsArtListData, b)))
        }
 
        res = append(res, cc.NewReply(t, NewField(FieldNewsArtListData, b)))
-       return res, err
+       return res, nil
 }
 
 // HandleGetNewsArtData requests information about the specific news article.
 }
 
 // HandleGetNewsArtData requests information about the specific news article.
@@ -1938,7 +1938,6 @@ func HandleJoinChat(cc *ClientConn, t *Transaction) (res []Transaction, err erro
 
        replyFields := []Field{NewField(FieldChatSubject, []byte(privChat.Subject))}
        for _, c := range sortedClients(privChat.ClientConn) {
 
        replyFields := []Field{NewField(FieldChatSubject, []byte(privChat.Subject))}
        for _, c := range sortedClients(privChat.ClientConn) {
-
                b, err := io.ReadAll(&User{
                        ID:    *c.ID,
                        Icon:  c.Icon,
                b, err := io.ReadAll(&User{
                        ID:    *c.ID,
                        Icon:  c.Icon,