| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- package handler
- import (
- "context"
- "io"
- "log/slog"
- "github.com/mk6i/retro-aim-server/server/oscar"
- "github.com/mk6i/retro-aim-server/server/oscar/middleware"
- "github.com/mk6i/retro-aim-server/state"
- "github.com/mk6i/retro-aim-server/wire"
- )
- type LocateService interface {
- DirInfo(ctx context.Context, frame wire.SNACFrame, body wire.SNAC_0x02_0x0B_LocateGetDirInfo) (wire.SNACMessage, error)
- RightsQuery(ctx context.Context, inFrame wire.SNACFrame) wire.SNACMessage
- SetDirInfo(ctx context.Context, sess *state.Session, inFrame wire.SNACFrame, inBody wire.SNAC_0x02_0x09_LocateSetDirInfo) (wire.SNACMessage, error)
- SetInfo(ctx context.Context, sess *state.Session, inBody wire.SNAC_0x02_0x04_LocateSetInfo) error
- SetKeywordInfo(ctx context.Context, sess *state.Session, inFrame wire.SNACFrame, body wire.SNAC_0x02_0x0F_LocateSetKeywordInfo) (wire.SNACMessage, error)
- UserInfoQuery(ctx context.Context, sess *state.Session, inFrame wire.SNACFrame, inBody wire.SNAC_0x02_0x05_LocateUserInfoQuery) (wire.SNACMessage, error)
- }
- func NewLocateHandler(locateService LocateService, logger *slog.Logger) LocateHandler {
- return LocateHandler{
- LocateService: locateService,
- RouteLogger: middleware.RouteLogger{
- Logger: logger,
- },
- }
- }
- type LocateHandler struct {
- LocateService
- middleware.RouteLogger
- }
- func (h LocateHandler) RightsQuery(ctx context.Context, _ *state.Session, inFrame wire.SNACFrame, _ io.Reader, rw oscar.ResponseWriter) error {
- outSNAC := h.LocateService.RightsQuery(ctx, inFrame)
- h.LogRequestAndResponse(ctx, inFrame, nil, outSNAC.Frame, outSNAC.Body)
- return rw.SendSNAC(outSNAC.Frame, outSNAC.Body)
- }
- func (h LocateHandler) SetInfo(ctx context.Context, sess *state.Session, inFrame wire.SNACFrame, r io.Reader, _ oscar.ResponseWriter) error {
- inBody := wire.SNAC_0x02_0x04_LocateSetInfo{}
- if err := wire.UnmarshalBE(&inBody, r); err != nil {
- return err
- }
- h.LogRequest(ctx, inFrame, inBody)
- return h.LocateService.SetInfo(ctx, sess, inBody)
- }
- func (h LocateHandler) SetDirInfo(ctx context.Context, sess *state.Session, inFrame wire.SNACFrame, r io.Reader, rw oscar.ResponseWriter) error {
- inBody := wire.SNAC_0x02_0x09_LocateSetDirInfo{}
- if err := wire.UnmarshalBE(&inBody, r); err != nil {
- return err
- }
- outSNAC, err := h.LocateService.SetDirInfo(ctx, sess, inFrame, inBody)
- if err != nil {
- return err
- }
- h.LogRequestAndResponse(ctx, inFrame, inBody, outSNAC.Frame, outSNAC.Body)
- return rw.SendSNAC(outSNAC.Frame, outSNAC.Body)
- }
- func (h LocateHandler) GetDirInfo(ctx context.Context, _ *state.Session, inFrame wire.SNACFrame, r io.Reader, rw oscar.ResponseWriter) error {
- inBody := wire.SNAC_0x02_0x0B_LocateGetDirInfo{}
- if err := wire.UnmarshalBE(&inBody, r); err != nil {
- return err
- }
- outSNAC, err := h.LocateService.DirInfo(ctx, inFrame, inBody)
- if err != nil {
- return err
- }
- h.LogRequestAndResponse(ctx, inFrame, inBody, outSNAC.Frame, outSNAC.Body)
- return rw.SendSNAC(outSNAC.Frame, outSNAC.Body)
- }
- func (h LocateHandler) SetKeywordInfo(ctx context.Context, sess *state.Session, inFrame wire.SNACFrame, r io.Reader, rw oscar.ResponseWriter) error {
- inBody := wire.SNAC_0x02_0x0F_LocateSetKeywordInfo{}
- if err := wire.UnmarshalBE(&inBody, r); err != nil {
- return err
- }
- outSNAC, err := h.LocateService.SetKeywordInfo(ctx, sess, inFrame, inBody)
- if err != nil {
- return err
- }
- h.LogRequestAndResponse(ctx, inFrame, inBody, outSNAC.Frame, outSNAC.Body)
- return rw.SendSNAC(outSNAC.Frame, outSNAC.Body)
- }
- func (h LocateHandler) UserInfoQuery(ctx context.Context, sess *state.Session, inFrame wire.SNACFrame, r io.Reader, rw oscar.ResponseWriter) error {
- inBody := wire.SNAC_0x02_0x05_LocateUserInfoQuery{}
- if err := wire.UnmarshalBE(&inBody, r); err != nil {
- return err
- }
- outSNAC, err := h.LocateService.UserInfoQuery(ctx, sess, inFrame, inBody)
- if err != nil {
- return err
- }
- h.LogRequestAndResponse(ctx, inFrame, inBody, outSNAC.Frame, outSNAC.Body)
- return rw.SendSNAC(outSNAC.Frame, outSNAC.Body)
- }
- func (h LocateHandler) UserInfoQuery2(ctx context.Context, sess *state.Session, inFrame wire.SNACFrame, r io.Reader, rw oscar.ResponseWriter) error {
- inBody := wire.SNAC_0x02_0x15_LocateUserInfoQuery2{}
- if err := wire.UnmarshalBE(&inBody, r); err != nil {
- return err
- }
- // SNAC functionality for LocateUserInfoQuery and LocateUserInfoQuery2 is
- // identical except for the Type field data type (uint16 vs uint32).
- wrappedBody := wire.SNAC_0x02_0x05_LocateUserInfoQuery{
- Type: uint16(inBody.Type2),
- ScreenName: inBody.ScreenName,
- }
- outSNAC, err := h.LocateService.UserInfoQuery(ctx, sess, inFrame, wrappedBody)
- if err != nil {
- return err
- }
- h.LogRequestAndResponse(ctx, inFrame, inBody, outSNAC.Frame, outSNAC.Body)
- return rw.SendSNAC(outSNAC.Frame, outSNAC.Body)
- }
|