types.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. package webapi
  2. import (
  3. "context"
  4. "time"
  5. "github.com/google/uuid"
  6. "github.com/mk6i/open-oscar-server/config"
  7. "github.com/mk6i/open-oscar-server/state"
  8. "github.com/mk6i/open-oscar-server/wire"
  9. )
  10. type BuddyService interface {
  11. AddBuddies(ctx context.Context, instance *state.SessionInstance, inBody wire.SNAC_0x03_0x04_BuddyAddBuddies) error
  12. BroadcastBuddyDeparted(ctx context.Context, instance *state.SessionInstance) error
  13. DelBuddies(ctx context.Context, instance *state.SessionInstance, inBody wire.SNAC_0x03_0x05_BuddyDelBuddies) error
  14. RightsQuery(ctx context.Context, inFrame wire.SNACFrame) wire.SNACMessage
  15. }
  16. type ChatService interface {
  17. ChannelMsgToHost(ctx context.Context, instance *state.SessionInstance, inFrame wire.SNACFrame, inBody wire.SNAC_0x0E_0x05_ChatChannelMsgToHost) (*wire.SNACMessage, error)
  18. }
  19. type ChatNavService interface {
  20. CreateRoom(ctx context.Context, instance *state.SessionInstance, inFrame wire.SNACFrame, inBody wire.SNAC_0x0E_0x02_ChatRoomInfoUpdate) (wire.SNACMessage, error)
  21. ExchangeInfo(ctx context.Context, inFrame wire.SNACFrame, inBody wire.SNAC_0x0D_0x03_ChatNavRequestExchangeInfo) (wire.SNACMessage, error)
  22. RequestChatRights(ctx context.Context, inFrame wire.SNACFrame) wire.SNACMessage
  23. RequestRoomInfo(ctx context.Context, inFrame wire.SNACFrame, inBody wire.SNAC_0x0D_0x04_ChatNavRequestRoomInfo) (wire.SNACMessage, error)
  24. }
  25. type ICBMService interface {
  26. ChannelMsgToHost(ctx context.Context, instance *state.SessionInstance, inFrame wire.SNACFrame, inBody wire.SNAC_0x04_0x06_ICBMChannelMsgToHost) (*wire.SNACMessage, error)
  27. ClientEvent(ctx context.Context, instance *state.SessionInstance, inFrame wire.SNACFrame, inBody wire.SNAC_0x04_0x14_ICBMClientEvent) error
  28. EvilRequest(ctx context.Context, instance *state.SessionInstance, inFrame wire.SNACFrame, inBody wire.SNAC_0x04_0x08_ICBMEvilRequest) (wire.SNACMessage, error)
  29. ParameterQuery(ctx context.Context, inFrame wire.SNACFrame) wire.SNACMessage
  30. ClientErr(ctx context.Context, instance *state.SessionInstance, inFrame wire.SNACFrame, inBody wire.SNAC_0x04_0x0B_ICBMClientErr) error
  31. }
  32. type OServiceService interface {
  33. ClientOnline(ctx context.Context, service uint16, inBody wire.SNAC_0x01_0x02_OServiceClientOnline, instance *state.SessionInstance) error
  34. IdleNotification(ctx context.Context, instance *state.SessionInstance, inBody wire.SNAC_0x01_0x11_OServiceIdleNotification) error
  35. ServiceRequest(ctx context.Context, service uint16, instance *state.SessionInstance, inFrame wire.SNACFrame, inBody wire.SNAC_0x01_0x04_OServiceServiceRequest, listener config.Listener) (wire.SNACMessage, error)
  36. }
  37. type AuthService interface {
  38. BUCPChallenge(ctx context.Context, inBody wire.SNAC_0x17_0x06_BUCPChallengeRequest, newUUID func() uuid.UUID) (wire.SNACMessage, error)
  39. BUCPLogin(ctx context.Context, inBody wire.SNAC_0x17_0x02_BUCPLoginRequest, newUserFn func(screenName state.DisplayScreenName) (state.User, error), advertisedHost string) (wire.SNACMessage, error)
  40. CrackCookie(authCookie []byte) (state.ServerCookie, error)
  41. FLAPLogin(ctx context.Context, inFrame wire.FLAPSignonFrame, newUserFn func(screenName state.DisplayScreenName) (state.User, error), advertisedHost string) (wire.TLVRestBlock, error)
  42. RegisterBOSSession(ctx context.Context, authCookie state.ServerCookie) (*state.SessionInstance, error)
  43. RegisterChatSession(ctx context.Context, authCookie state.ServerCookie) (*state.SessionInstance, error)
  44. RetrieveBOSSession(ctx context.Context, authCookie state.ServerCookie) (*state.SessionInstance, error)
  45. Signout(ctx context.Context, instance *state.SessionInstance)
  46. SignoutChat(ctx context.Context, instance *state.SessionInstance)
  47. }
  48. type LocateService interface {
  49. SetDirInfo(ctx context.Context, instance *state.SessionInstance, inFrame wire.SNACFrame, inBody wire.SNAC_0x02_0x09_LocateSetDirInfo) (wire.SNACMessage, error)
  50. SetInfo(ctx context.Context, instance *state.SessionInstance, inBody wire.SNAC_0x02_0x04_LocateSetInfo) error
  51. UserInfoQuery(ctx context.Context, instance *state.SessionInstance, inFrame wire.SNACFrame, inBody wire.SNAC_0x02_0x05_LocateUserInfoQuery) (wire.SNACMessage, error)
  52. DirInfo(ctx context.Context, inFrame wire.SNACFrame, inBody wire.SNAC_0x02_0x0B_LocateGetDirInfo) (wire.SNACMessage, error)
  53. }
  54. type DirSearchService interface {
  55. InfoQuery(ctx context.Context, inFrame wire.SNACFrame, inBody wire.SNAC_0x0F_0x02_InfoQuery) (wire.SNACMessage, error)
  56. }
  57. type PermitDenyService interface {
  58. AddDenyListEntries(ctx context.Context, instance *state.SessionInstance, inBody wire.SNAC_0x09_0x07_PermitDenyAddDenyListEntries) error
  59. AddPermListEntries(ctx context.Context, instance *state.SessionInstance, inBody wire.SNAC_0x09_0x05_PermitDenyAddPermListEntries) error
  60. DelDenyListEntries(ctx context.Context, instance *state.SessionInstance, inBody wire.SNAC_0x09_0x08_PermitDenyDelDenyListEntries) error
  61. DelPermListEntries(ctx context.Context, instance *state.SessionInstance, inBody wire.SNAC_0x09_0x06_PermitDenyDelPermListEntries) error
  62. RightsQuery(ctx context.Context, inFrame wire.SNACFrame) wire.SNACMessage
  63. }
  64. // BuddyListRegistry is the interface for keeping track of users with active
  65. // buddy lists. Once registered, a user becomes visible to other users' buddy
  66. // lists and vice versa.
  67. type BuddyListRegistry interface {
  68. RegisterBuddyList(ctx context.Context, user state.IdentScreenName) error
  69. UnregisterBuddyList(ctx context.Context, user state.IdentScreenName) error
  70. }
  71. type TOCConfigStore interface {
  72. // SetTOCConfig sets the user's TOC config. The TOC config is the server-side
  73. // buddy list functionality for TOC. This configuration is not available to
  74. // OSCAR clients.
  75. SetTOCConfig(ctx context.Context, user state.IdentScreenName, config string) error
  76. User(ctx context.Context, screenName state.IdentScreenName) (*state.User, error)
  77. }
  78. // CookieBaker defines methods for issuing and verifying AIM authentication tokens ("cookies").
  79. // These tokens are used for authenticating client sessions with AIM services.
  80. type CookieBaker interface {
  81. // Crack verifies and decodes a previously issued authentication token.
  82. // Returns the original payload if the token is valid.
  83. Crack(data []byte) ([]byte, error)
  84. // Issue creates a new authentication token from the given payload.
  85. // The resulting token can later be verified using Crack.
  86. Issue(data []byte) ([]byte, error)
  87. }
  88. type AdminService interface {
  89. InfoChangeRequest(ctx context.Context, instance *state.SessionInstance, inFrame wire.SNACFrame, inBody wire.SNAC_0x07_0x04_AdminInfoChangeRequest) (wire.SNACMessage, error)
  90. }
  91. // SessionRetriever provides methods to retrieve OSCAR sessions.
  92. type SessionRetriever interface {
  93. AllSessions() []*state.Session
  94. RetrieveSession(screenName state.IdentScreenName) *state.Session
  95. }
  96. // FeedbagRetriever provides methods to retrieve buddy list data.
  97. type FeedbagRetriever interface {
  98. RetrieveFeedbag(ctx context.Context, screenName state.IdentScreenName) ([]wire.FeedbagItem, error)
  99. RelationshipsByUser(ctx context.Context, screenName state.IdentScreenName) ([]state.IdentScreenName, error)
  100. }
  101. // FeedbagManager provides methods to manage buddy lists.
  102. type FeedbagManager interface {
  103. RetrieveFeedbag(ctx context.Context, screenName state.IdentScreenName) ([]wire.FeedbagItem, error)
  104. InsertItem(ctx context.Context, screenName state.IdentScreenName, item wire.FeedbagItem) error
  105. UpdateItem(ctx context.Context, screenName state.IdentScreenName, item wire.FeedbagItem) error
  106. DeleteItem(ctx context.Context, screenName state.IdentScreenName, item wire.FeedbagItem) error
  107. }
  108. // Phase 2: Additional interfaces for messaging and presence
  109. // MessageRelayer relays messages between users
  110. type MessageRelayer interface {
  111. RelayToScreenName(ctx context.Context, recipient state.IdentScreenName, msg wire.SNACMessage)
  112. }
  113. // OfflineMessageManager manages offline message storage and retrieval
  114. type OfflineMessageManager interface {
  115. SaveMessage(ctx context.Context, msg state.OfflineMessage) (int, error)
  116. RetrieveMessages(ctx context.Context, recipient state.IdentScreenName) ([]state.OfflineMessage, error)
  117. DeleteMessages(ctx context.Context, recipient state.IdentScreenName) error
  118. }
  119. // BuddyBroadcaster broadcasts buddy presence updates
  120. type BuddyBroadcaster interface {
  121. BroadcastBuddyArrived(ctx context.Context, screenName state.IdentScreenName, userInfo wire.TLVUserInfo) error
  122. BroadcastBuddyDeparted(ctx context.Context, instance *state.SessionInstance) error
  123. }
  124. // ProfileManager manages user profiles
  125. type ProfileManager interface {
  126. SetProfile(ctx context.Context, screenName state.IdentScreenName, profile state.UserProfile) error
  127. Profile(ctx context.Context, screenName state.IdentScreenName) (state.UserProfile, error)
  128. }
  129. // UserManager defines methods for user authentication.
  130. type UserManager interface {
  131. // AuthenticateUser verifies username and password
  132. AuthenticateUser(ctx context.Context, username, password string) (*state.User, error)
  133. // FindUserByScreenName finds a user by their screen name
  134. FindUserByScreenName(ctx context.Context, screenName state.IdentScreenName) (*state.User, error)
  135. // InsertUser creates a new user (for DISABLE_AUTH mode)
  136. InsertUser(ctx context.Context, u state.User) error
  137. }
  138. // TokenStore manages authentication tokens.
  139. type TokenStore interface {
  140. // StoreToken saves an authentication token for a user
  141. StoreToken(ctx context.Context, token string, screenName state.IdentScreenName, expiresAt time.Time) error
  142. // ValidateToken checks if a token is valid and returns the associated screen name
  143. ValidateToken(ctx context.Context, token string) (state.IdentScreenName, error)
  144. // DeleteToken removes a token
  145. DeleteToken(ctx context.Context, token string) error
  146. }
  147. // Phase 3: Preference interfaces
  148. // PreferenceManager provides methods to manage user preferences.
  149. type PreferenceManager interface {
  150. SetPreferences(ctx context.Context, screenName state.IdentScreenName, prefs map[string]interface{}) error
  151. GetPreferences(ctx context.Context, screenName state.IdentScreenName) (map[string]interface{}, error)
  152. }
  153. // PermitDenyManager provides methods to manage permit/deny lists.
  154. type PermitDenyManager interface {
  155. SetPDMode(ctx context.Context, screenName state.IdentScreenName, mode wire.FeedbagPDMode) error
  156. GetPDMode(ctx context.Context, screenName state.IdentScreenName) (wire.FeedbagPDMode, error)
  157. GetPermitList(ctx context.Context, screenName state.IdentScreenName) ([]state.IdentScreenName, error)
  158. GetDenyList(ctx context.Context, screenName state.IdentScreenName) ([]state.IdentScreenName, error)
  159. AddPermitBuddy(ctx context.Context, me state.IdentScreenName, them state.IdentScreenName) error
  160. RemovePermitBuddy(ctx context.Context, me state.IdentScreenName, them state.IdentScreenName) error
  161. AddDenyBuddy(ctx context.Context, me state.IdentScreenName, them state.IdentScreenName) error
  162. RemoveDenyBuddy(ctx context.Context, me state.IdentScreenName, them state.IdentScreenName) error
  163. }
  164. // Phase 4: OSCAR Bridge interfaces
  165. // OSCARBridgeStore manages the persistence of OSCAR bridge sessions.
  166. type OSCARBridgeStore interface {
  167. SaveBridgeSession(ctx context.Context, webSessionID string, oscarCookie []byte, bosHost string, bosPort int) error
  168. SaveBridgeSessionWithDetails(ctx context.Context, session *state.OSCARBridgeSession) error
  169. GetBridgeSession(ctx context.Context, webSessionID string) (*state.OSCARBridgeSession, error)
  170. DeleteBridgeSession(ctx context.Context, webSessionID string) error
  171. }
  172. // OSCARConfig provides configuration for OSCAR services.
  173. type OSCARConfig interface {
  174. GetBOSAddress() (host string, port int)
  175. GetSSLBOSAddress() (host string, port int)
  176. IsSSLAvailable() bool
  177. IsAuthDisabled() bool
  178. }