types.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. package http
  2. import (
  3. "context"
  4. "net/mail"
  5. "time"
  6. "github.com/mk6i/open-oscar-server/state"
  7. "github.com/mk6i/open-oscar-server/wire"
  8. )
  9. // AccountManager defines methods for managing user account attributes
  10. // such as email, confirmation status, registration status, and suspension.
  11. type AccountManager interface {
  12. // ConfirmStatus returns whether a user account has been confirmed.
  13. ConfirmStatus(ctx context.Context, screenName state.IdentScreenName) (bool, error)
  14. // EmailAddress looks up a user's email address by screen name.
  15. EmailAddress(ctx context.Context, screenName state.IdentScreenName) (*mail.Address, error)
  16. // RegStatus looks up a user's registration status by screen name.
  17. // It returns one of the following values:
  18. // - wire.AdminInfoRegStatusFullDisclosure
  19. // - wire.AdminInfoRegStatusLimitDisclosure
  20. // - wire.AdminInfoRegStatusNoDisclosure
  21. RegStatus(ctx context.Context, screenName state.IdentScreenName) (uint16, error)
  22. // UpdateSuspendedStatus updates the suspension status of a user account.
  23. UpdateSuspendedStatus(ctx context.Context, suspendedStatus uint16, screenName state.IdentScreenName) error
  24. // SetBotStatus updates the flag that indicates whether the user is a bot.
  25. SetBotStatus(ctx context.Context, isBot bool, screenName state.IdentScreenName) error
  26. }
  27. // BARTAssetManager defines methods for managing BART (Buddy ART) assets.
  28. type BARTAssetManager interface {
  29. // BARTItem retrieves a BART asset by its hash.
  30. BARTItem(ctx context.Context, hash []byte) ([]byte, error)
  31. // InsertBARTItem inserts a BART asset.
  32. InsertBARTItem(ctx context.Context, hash []byte, blob []byte, itemType uint16) error
  33. // ListBARTItems returns BART assets filtered by type.
  34. ListBARTItems(ctx context.Context, itemType uint16) ([]state.BARTItem, error)
  35. // DeleteBARTItem deletes a BART asset by hash.
  36. DeleteBARTItem(ctx context.Context, hash []byte) error
  37. }
  38. // BuddyBroadcaster defines a method for broadcasting presence updates.
  39. type BuddyBroadcaster interface {
  40. // BroadcastVisibility sends presence updates to the specified filter list.
  41. // If sendDepartures is true, departure events are sent as well.
  42. BroadcastVisibility(ctx context.Context, you *state.SessionInstance, filter []state.IdentScreenName, sendDepartures bool) error
  43. }
  44. // ChatRoomCreator defines a method for creating a new chat room.
  45. type ChatRoomCreator interface {
  46. // CreateChatRoom creates a new chat room.
  47. CreateChatRoom(ctx context.Context, chatRoom *state.ChatRoom) error
  48. }
  49. // ChatRoomRetriever defines a method for retrieving all chat rooms
  50. // under a specific exchange.
  51. type ChatRoomRetriever interface {
  52. // AllChatRooms returns all chat rooms associated with the given exchange ID.
  53. AllChatRooms(ctx context.Context, exchange uint16) ([]state.ChatRoom, error)
  54. }
  55. // ChatRoomDeleter defines a method for deleting chat rooms.
  56. type ChatRoomDeleter interface {
  57. // DeleteChatRooms deletes chat rooms by their names under a specific exchange.
  58. DeleteChatRooms(ctx context.Context, exchange uint16, names []string) error
  59. }
  60. // ChatSessionRetriever defines a method for retrieving all sessions
  61. // associated with a specific chat room.
  62. type ChatSessionRetriever interface {
  63. // AllSessions returns all active sessions in the chat room identified by cookie.
  64. AllSessions(cookie string) []*state.Session
  65. }
  66. // DirectoryManager defines methods for managing interest categories and keywords
  67. // used in user profiles and directory listings.
  68. type DirectoryManager interface {
  69. // Categories returns all existing directory categories.
  70. Categories(ctx context.Context) ([]state.Category, error)
  71. // CreateCategory adds a new directory category.
  72. CreateCategory(ctx context.Context, name string) (state.Category, error)
  73. // CreateKeyword adds a new keyword to the specified category.
  74. CreateKeyword(ctx context.Context, name string, categoryID uint8) (state.Keyword, error)
  75. // DeleteCategory removes a directory category by ID.
  76. DeleteCategory(ctx context.Context, categoryID uint8) error
  77. // DeleteKeyword removes a keyword by ID.
  78. DeleteKeyword(ctx context.Context, id uint8) error
  79. // KeywordsByCategory returns all keywords under the specified category.
  80. KeywordsByCategory(ctx context.Context, categoryID uint8) ([]state.Keyword, error)
  81. }
  82. // FeedBagRetriever defines methods for retrieving buddy list metadata.
  83. type FeedBagRetriever interface {
  84. // BuddyIconMetadata retrieves a user's buddy icon metadata. It returns nil
  85. // if the user does not have a buddy icon.
  86. BuddyIconMetadata(ctx context.Context, screenName state.IdentScreenName) (*wire.BARTID, error)
  87. }
  88. // FeedbagManager defines methods for managing feedbag (buddy list) entries.
  89. // This interface matches foodgroup.FeedbagManager and is implemented by state.SQLiteUserStore.
  90. type FeedbagManager interface {
  91. // Feedbag retrieves all feedbag items for a user.
  92. Feedbag(ctx context.Context, screenName state.IdentScreenName) ([]wire.FeedbagItem, error)
  93. // FeedbagUpsert inserts or updates feedbag items.
  94. FeedbagUpsert(ctx context.Context, screenName state.IdentScreenName, items []wire.FeedbagItem) error
  95. // FeedbagDelete deletes feedbag items.
  96. FeedbagDelete(ctx context.Context, screenName state.IdentScreenName, items []wire.FeedbagItem) error
  97. }
  98. // MessageRelayer defines a method for sending a SNAC message to a specific screen name.
  99. type MessageRelayer interface {
  100. // RelayToScreenName sends the given SNAC message to the specified screen name.
  101. RelayToScreenName(ctx context.Context, screenName state.IdentScreenName, msg wire.SNACMessage)
  102. }
  103. // ICBMSender sends an instant message from the given sender instance as if
  104. // the sender submitted wire.ICBMChannelMsgToHost.
  105. type ICBMSender func(ctx context.Context, instance *state.SessionInstance, inFrame wire.SNACFrame, inBody wire.SNAC_0x04_0x06_ICBMChannelMsgToHost) (*wire.SNACMessage, error)
  106. // ProfileRetriever defines a method for retrieving a user's free-form profile.
  107. type ProfileRetriever interface {
  108. // Profile returns the user's profile information for the given screen name.
  109. Profile(ctx context.Context, screenName state.IdentScreenName) (state.UserProfile, error)
  110. }
  111. // SessionRetriever defines methods for retrieving active sessions,
  112. // either all of them or by screen name.
  113. type SessionRetriever interface {
  114. // AllSessions returns all active user sessions.
  115. AllSessions() []*state.Session
  116. // RetrieveSession returns the session associated with the given screen name,
  117. // or nil if no active session exists. Returns the Session object if there
  118. // are active instances with complete signon.
  119. RetrieveSession(screenName state.IdentScreenName) *state.Session
  120. }
  121. // UserManager defines methods for accessing and inserting AIM user records.
  122. type UserManager interface {
  123. // AllUsers returns all registered users.
  124. AllUsers(ctx context.Context) ([]state.User, error)
  125. // DeleteUser removes a user from the system by screen name.
  126. DeleteUser(ctx context.Context, screenName state.IdentScreenName) error
  127. // InsertUser inserts a new user into the system. Return state.ErrDupUser
  128. // if a user with the same screen name already exists.
  129. InsertUser(ctx context.Context, u state.User) error
  130. // SetUserPassword sets the user's password hashes and auth key.
  131. SetUserPassword(ctx context.Context, screenName state.IdentScreenName, newPassword string) error
  132. // User returns all attributes for a user.
  133. User(ctx context.Context, screenName state.IdentScreenName) (*state.User, error)
  134. }
  135. // ICQProfileManager defines methods for getting and setting ICQ user profile data.
  136. type ICQProfileManager interface {
  137. // User returns all attributes for a user.
  138. User(ctx context.Context, screenName state.IdentScreenName) (*state.User, error)
  139. // SetBasicInfo updates the user's basic ICQ profile info.
  140. SetBasicInfo(ctx context.Context, name state.IdentScreenName, data state.ICQBasicInfo) error
  141. // SetMoreInfo updates the user's additional ICQ info.
  142. SetMoreInfo(ctx context.Context, name state.IdentScreenName, data state.ICQMoreInfo) error
  143. // SetWorkInfo updates the user's work info.
  144. SetWorkInfo(ctx context.Context, name state.IdentScreenName, data state.ICQWorkInfo) error
  145. // SetUserNotes updates the user's notes.
  146. SetUserNotes(ctx context.Context, name state.IdentScreenName, data state.ICQUserNotes) error
  147. // SetInterests updates the user's interests.
  148. SetInterests(ctx context.Context, name state.IdentScreenName, data state.ICQInterests) error
  149. // SetAffiliations updates the user's affiliations.
  150. SetAffiliations(ctx context.Context, name state.IdentScreenName, data state.ICQAffiliations) error
  151. // SetPermissions updates the user's privacy permissions.
  152. SetPermissions(ctx context.Context, name state.IdentScreenName, data state.ICQPermissions) error
  153. // SetICQInfo updates all ICQ profile columns for the user in one operation.
  154. SetICQInfo(ctx context.Context, name state.IdentScreenName, info state.ICQInfo) error
  155. }
  156. type userWithPassword struct {
  157. ScreenName string `json:"screen_name"`
  158. Password string `json:"password,omitempty"`
  159. }
  160. type onlineUsers struct {
  161. Count int `json:"count"`
  162. Sessions []sessionHandle `json:"sessions"`
  163. }
  164. type userHandle struct {
  165. ID string `json:"id"`
  166. ScreenName string `json:"screen_name"`
  167. IsICQ bool `json:"is_icq"`
  168. SuspendedStatus string `json:"suspended_status"`
  169. IsBot bool `json:"is_bot"`
  170. }
  171. type aimChatUserHandle struct {
  172. ID string `json:"id"`
  173. ScreenName string `json:"screen_name"`
  174. }
  175. type userAccountHandle struct {
  176. ID string `json:"id"`
  177. ScreenName string `json:"screen_name"`
  178. Profile string `json:"profile"`
  179. EmailAddress string `json:"email_address"`
  180. RegStatus uint16 `json:"reg_status"`
  181. Confirmed bool `json:"confirmed"`
  182. IsICQ bool `json:"is_icq"`
  183. SuspendedStatus string `json:"suspended_status"`
  184. IsBot bool `json:"is_bot"`
  185. }
  186. type userAccountPatch struct {
  187. SuspendedStatusText *string `json:"suspended_status"`
  188. IsBot *bool `json:"is_bot"`
  189. }
  190. type sessionHandle struct {
  191. ID string `json:"id"`
  192. ScreenName string `json:"screen_name"`
  193. OnlineSeconds int `json:"online_seconds"`
  194. IsAway bool `json:"is_away"`
  195. AwayMessage string `json:"away_message"`
  196. IdleSeconds int `json:"idle_seconds"`
  197. IsInvisible bool `json:"is_invisible"`
  198. IsICQ bool `json:"is_icq"`
  199. InstanceCount int `json:"instance_count"`
  200. Instances []instanceHandle `json:"instances"`
  201. }
  202. type instanceHandle struct {
  203. Num int `json:"num"`
  204. IdleSeconds int `json:"idle_seconds"`
  205. IsAway bool `json:"is_away"`
  206. AwayMessage string `json:"away_message"`
  207. IsInvisible bool `json:"is_invisible"`
  208. RemoteAddr string `json:"remote_addr"`
  209. RemotePort int `json:"remote_port"`
  210. }
  211. type chatRoomCreate struct {
  212. Name string `json:"name"`
  213. }
  214. type chatRoomDelete struct {
  215. Names []string `json:"names"`
  216. }
  217. type chatRoom struct {
  218. Name string `json:"name"`
  219. CreateTime time.Time `json:"create_time"`
  220. CreatorID string `json:"creator_id,omitempty"`
  221. URL string `json:"url"`
  222. Participants []aimChatUserHandle `json:"participants"`
  223. }
  224. type instantMessage struct {
  225. From string `json:"from"`
  226. To string `json:"to"`
  227. Text string `json:"text"`
  228. StoreOffline bool `json:"storeOffline"`
  229. }
  230. type directoryKeyword struct {
  231. ID uint8 `json:"id"`
  232. Name string `json:"name"`
  233. }
  234. type directoryCategory struct {
  235. ID uint8 `json:"id"`
  236. Name string `json:"name"`
  237. }
  238. type directoryCategoryCreate struct {
  239. Name string `json:"name"`
  240. }
  241. type directoryKeywordCreate struct {
  242. CategoryID uint8 `json:"category_id"`
  243. Name string `json:"name"`
  244. }
  245. type messageBody struct {
  246. Message string `json:"message"`
  247. }
  248. type feedbagGroupHandle struct {
  249. GroupID uint16 `json:"group_id"`
  250. GroupName string `json:"group_name"`
  251. }
  252. func feedbagGroupFromItem(item wire.FeedbagItem) feedbagGroupHandle {
  253. return feedbagGroupHandle{
  254. GroupID: item.GroupID,
  255. GroupName: item.Name,
  256. }
  257. }
  258. // icqProfileHandle is the JSON representation of a full ICQ user profile.
  259. type icqProfileHandle struct {
  260. UIN uint32 `json:"uin"`
  261. BasicInfo icqBasicInfoHandle `json:"basic_info"`
  262. MoreInfo icqMoreInfoHandle `json:"more_info"`
  263. WorkInfo icqWorkInfoHandle `json:"work_info"`
  264. Notes string `json:"notes"`
  265. Interests icqInterestsHandle `json:"interests"`
  266. Affiliations icqAffiliationsHandle `json:"affiliations"`
  267. Permissions icqPermissionsHandle `json:"permissions"`
  268. }
  269. type icqBasicInfoHandle struct {
  270. Nickname string `json:"nickname"`
  271. FirstName string `json:"first_name"`
  272. LastName string `json:"last_name"`
  273. EmailAddress string `json:"email"`
  274. City string `json:"city"`
  275. State string `json:"state"`
  276. Phone string `json:"phone"`
  277. Fax string `json:"fax"`
  278. Address string `json:"address"`
  279. CellPhone string `json:"cell_phone"`
  280. ZIPCode string `json:"zip"`
  281. CountryCode uint16 `json:"country_code"`
  282. GMTOffset uint8 `json:"gmt_offset"`
  283. PublishEmail bool `json:"publish_email"`
  284. OriginCity string `json:"origin_city"`
  285. OriginState string `json:"origin_state"`
  286. // OriginCountryCode is the ICQ country code for the user's original home.
  287. OriginCountryCode uint16 `json:"origin_country_code"`
  288. }
  289. type icqMoreInfoHandle struct {
  290. Gender uint16 `json:"gender"`
  291. HomePageAddr string `json:"homepage"`
  292. BirthYear uint16 `json:"birth_year"`
  293. BirthMonth uint8 `json:"birth_month"`
  294. BirthDay uint8 `json:"birth_day"`
  295. Lang1 uint8 `json:"lang1"`
  296. Lang2 uint8 `json:"lang2"`
  297. Lang3 uint8 `json:"lang3"`
  298. }
  299. type icqWorkInfoHandle struct {
  300. Company string `json:"company"`
  301. Department string `json:"department"`
  302. Position string `json:"position"`
  303. OccupationCode uint16 `json:"occupation_code"`
  304. Address string `json:"address"`
  305. City string `json:"city"`
  306. State string `json:"state"`
  307. ZIPCode string `json:"zip"`
  308. CountryCode uint16 `json:"country_code"`
  309. Phone string `json:"phone"`
  310. Fax string `json:"fax"`
  311. WebPage string `json:"web_page"`
  312. }
  313. type icqInterestsHandle struct {
  314. Code1 uint16 `json:"code1"`
  315. Keyword1 string `json:"keyword1"`
  316. Code2 uint16 `json:"code2"`
  317. Keyword2 string `json:"keyword2"`
  318. Code3 uint16 `json:"code3"`
  319. Keyword3 string `json:"keyword3"`
  320. Code4 uint16 `json:"code4"`
  321. Keyword4 string `json:"keyword4"`
  322. }
  323. type icqAffiliationsHandle struct {
  324. PastCode1 uint16 `json:"past_code1"`
  325. PastKeyword1 string `json:"past_keyword1"`
  326. PastCode2 uint16 `json:"past_code2"`
  327. PastKeyword2 string `json:"past_keyword2"`
  328. PastCode3 uint16 `json:"past_code3"`
  329. PastKeyword3 string `json:"past_keyword3"`
  330. CurrentCode1 uint16 `json:"current_code1"`
  331. CurrentKeyword1 string `json:"current_keyword1"`
  332. CurrentCode2 uint16 `json:"current_code2"`
  333. CurrentKeyword2 string `json:"current_keyword2"`
  334. CurrentCode3 uint16 `json:"current_code3"`
  335. CurrentKeyword3 string `json:"current_keyword3"`
  336. }
  337. type icqPermissionsHandle struct {
  338. AuthRequired bool `json:"auth_required"`
  339. WebAware bool `json:"web_aware"`
  340. AllowSpam bool `json:"allow_spam"`
  341. }