types.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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. // AIMDirectoryEntries returns the user directory listing of every user
  70. // who has directory info or keywords set.
  71. AIMDirectoryEntries(ctx context.Context) ([]state.AIMDirectoryEntry, error)
  72. // Categories returns all existing directory categories.
  73. Categories(ctx context.Context) ([]state.Category, error)
  74. // CreateCategory adds a new directory category.
  75. CreateCategory(ctx context.Context, name string) (state.Category, error)
  76. // CreateKeyword adds a new keyword to the specified category.
  77. CreateKeyword(ctx context.Context, name string, categoryID uint8) (state.Keyword, error)
  78. // DeleteCategory removes a directory category by ID.
  79. DeleteCategory(ctx context.Context, categoryID uint8) error
  80. // DeleteKeyword removes a keyword by ID.
  81. DeleteKeyword(ctx context.Context, id uint8) error
  82. // KeywordsByCategory returns all keywords under the specified category.
  83. KeywordsByCategory(ctx context.Context, categoryID uint8) ([]state.Keyword, error)
  84. }
  85. // FeedBagRetriever defines methods for retrieving buddy list metadata.
  86. type FeedBagRetriever interface {
  87. // BuddyIconMetadata retrieves a user's buddy icon metadata. It returns nil
  88. // if the user does not have a buddy icon.
  89. BuddyIconMetadata(ctx context.Context, screenName state.IdentScreenName) (*wire.BARTID, error)
  90. }
  91. // FeedbagManager defines methods for managing feedbag (buddy list) entries.
  92. // This interface matches foodgroup.FeedbagManager and is implemented by state.SQLiteUserStore.
  93. type FeedbagManager interface {
  94. // Feedbag retrieves all feedbag items for a user.
  95. Feedbag(ctx context.Context, screenName state.IdentScreenName) ([]wire.FeedbagItem, error)
  96. // FeedbagUpsert inserts or updates feedbag items.
  97. FeedbagUpsert(ctx context.Context, screenName state.IdentScreenName, items []wire.FeedbagItem) error
  98. // FeedbagDelete deletes feedbag items.
  99. FeedbagDelete(ctx context.Context, screenName state.IdentScreenName, items []wire.FeedbagItem) error
  100. }
  101. // MessageRelayer defines a method for sending a SNAC message to a specific screen name.
  102. type MessageRelayer interface {
  103. // RelayToScreenName sends the given SNAC message to the specified screen name.
  104. RelayToScreenName(ctx context.Context, screenName state.IdentScreenName, msg wire.SNACMessage)
  105. }
  106. // ICBMSender sends an instant message from the given sender instance as if
  107. // the sender submitted wire.ICBMChannelMsgToHost.
  108. type ICBMSender func(ctx context.Context, instance *state.SessionInstance, inFrame wire.SNACFrame, inBody wire.SNAC_0x04_0x06_ICBMChannelMsgToHost) (*wire.SNACMessage, error)
  109. // ProfileRetriever defines a method for retrieving a user's free-form profile.
  110. type ProfileRetriever interface {
  111. // Profile returns the user's profile information for the given screen name.
  112. Profile(ctx context.Context, screenName state.IdentScreenName) (state.UserProfile, error)
  113. }
  114. // SessionRetriever defines methods for retrieving active sessions,
  115. // either all of them or by screen name.
  116. type SessionRetriever interface {
  117. // AllSessions returns all active user sessions.
  118. AllSessions() []*state.Session
  119. // RetrieveSession returns the session associated with the given screen name,
  120. // or nil if no active session exists. Returns the Session object if there
  121. // are active instances with complete signon.
  122. RetrieveSession(screenName state.IdentScreenName) *state.Session
  123. }
  124. // UserManager defines methods for accessing and inserting AIM user records.
  125. type UserManager interface {
  126. // AllUsers returns all registered users.
  127. AllUsers(ctx context.Context) ([]state.User, error)
  128. // DeleteUser removes a user from the system by screen name.
  129. DeleteUser(ctx context.Context, screenName state.IdentScreenName) error
  130. // InsertUser inserts a new user into the system. Return state.ErrDupUser
  131. // if a user with the same screen name already exists.
  132. InsertUser(ctx context.Context, u state.User) error
  133. // SetUserPassword sets the user's password hashes and auth key.
  134. SetUserPassword(ctx context.Context, screenName state.IdentScreenName, newPassword string) error
  135. // User returns all attributes for a user.
  136. User(ctx context.Context, screenName state.IdentScreenName) (*state.User, error)
  137. }
  138. // ICQProfileManager defines methods for getting and setting ICQ user profile data.
  139. type ICQProfileManager interface {
  140. // User returns all attributes for a user.
  141. User(ctx context.Context, screenName state.IdentScreenName) (*state.User, error)
  142. // SetBasicInfo updates the user's basic ICQ profile info.
  143. SetBasicInfo(ctx context.Context, name state.IdentScreenName, data state.ICQBasicInfo) error
  144. // SetMoreInfo updates the user's additional ICQ info.
  145. SetMoreInfo(ctx context.Context, name state.IdentScreenName, data state.ICQMoreInfo) error
  146. // SetWorkInfo updates the user's work info.
  147. SetWorkInfo(ctx context.Context, name state.IdentScreenName, data state.ICQWorkInfo) error
  148. // SetUserNotes updates the user's notes.
  149. SetUserNotes(ctx context.Context, name state.IdentScreenName, data state.ICQUserNotes) error
  150. // SetInterests updates the user's interests.
  151. SetInterests(ctx context.Context, name state.IdentScreenName, data state.ICQInterests) error
  152. // SetAffiliations updates the user's affiliations.
  153. SetAffiliations(ctx context.Context, name state.IdentScreenName, data state.ICQAffiliations) error
  154. // SetPermissions updates the user's privacy permissions.
  155. SetPermissions(ctx context.Context, name state.IdentScreenName, data state.ICQPermissions) error
  156. // SetICQInfo updates all ICQ profile columns for the user in one operation.
  157. SetICQInfo(ctx context.Context, name state.IdentScreenName, info state.ICQInfo) error
  158. }
  159. type userWithPassword struct {
  160. ScreenName string `json:"screen_name"`
  161. Password string `json:"password,omitempty"`
  162. }
  163. type onlineUsers struct {
  164. Count int `json:"count"`
  165. Sessions []sessionHandle `json:"sessions"`
  166. }
  167. type userHandle struct {
  168. ID string `json:"id"`
  169. ScreenName string `json:"screen_name"`
  170. IsICQ bool `json:"is_icq"`
  171. SuspendedStatus string `json:"suspended_status"`
  172. IsBot bool `json:"is_bot"`
  173. }
  174. type aimChatUserHandle struct {
  175. ID string `json:"id"`
  176. ScreenName string `json:"screen_name"`
  177. }
  178. type userAccountHandle struct {
  179. ID string `json:"id"`
  180. ScreenName string `json:"screen_name"`
  181. Profile string `json:"profile"`
  182. EmailAddress string `json:"email_address"`
  183. RegStatus uint16 `json:"reg_status"`
  184. Confirmed bool `json:"confirmed"`
  185. IsICQ bool `json:"is_icq"`
  186. SuspendedStatus string `json:"suspended_status"`
  187. IsBot bool `json:"is_bot"`
  188. }
  189. type userAccountPatch struct {
  190. SuspendedStatusText *string `json:"suspended_status"`
  191. IsBot *bool `json:"is_bot"`
  192. }
  193. type sessionHandle struct {
  194. ID string `json:"id"`
  195. ScreenName string `json:"screen_name"`
  196. OnlineSeconds int `json:"online_seconds"`
  197. IsAway bool `json:"is_away"`
  198. AwayMessage string `json:"away_message"`
  199. IdleSeconds int `json:"idle_seconds"`
  200. IsInvisible bool `json:"is_invisible"`
  201. IsICQ bool `json:"is_icq"`
  202. InstanceCount int `json:"instance_count"`
  203. Instances []instanceHandle `json:"instances"`
  204. }
  205. type instanceHandle struct {
  206. Num int `json:"num"`
  207. IdleSeconds int `json:"idle_seconds"`
  208. IsAway bool `json:"is_away"`
  209. AwayMessage string `json:"away_message"`
  210. IsInvisible bool `json:"is_invisible"`
  211. RemoteAddr string `json:"remote_addr"`
  212. RemotePort int `json:"remote_port"`
  213. ClientID string `json:"client_id"`
  214. }
  215. type chatRoomCreate struct {
  216. Name string `json:"name"`
  217. }
  218. type chatRoomDelete struct {
  219. Names []string `json:"names"`
  220. }
  221. type chatRoom struct {
  222. Name string `json:"name"`
  223. CreateTime time.Time `json:"create_time"`
  224. CreatorID string `json:"creator_id,omitempty"`
  225. URL string `json:"url"`
  226. Participants []aimChatUserHandle `json:"participants"`
  227. }
  228. type instantMessage struct {
  229. From string `json:"from"`
  230. To string `json:"to"`
  231. Text string `json:"text"`
  232. StoreOffline bool `json:"storeOffline"`
  233. }
  234. type directoryKeyword struct {
  235. ID uint8 `json:"id"`
  236. Name string `json:"name"`
  237. }
  238. type directoryCategory struct {
  239. ID uint8 `json:"id"`
  240. Name string `json:"name"`
  241. }
  242. type aimDirectoryEntryHandle struct {
  243. ScreenName string `json:"screen_name"`
  244. FirstName string `json:"first_name"`
  245. MiddleName string `json:"middle_name"`
  246. LastName string `json:"last_name"`
  247. MaidenName string `json:"maiden_name"`
  248. Nickname string `json:"nickname"`
  249. City string `json:"city"`
  250. State string `json:"state"`
  251. Country string `json:"country"`
  252. Address string `json:"address"`
  253. ZIP string `json:"zip"`
  254. Keywords []string `json:"keywords"`
  255. }
  256. type directoryCategoryCreate struct {
  257. Name string `json:"name"`
  258. }
  259. type directoryKeywordCreate struct {
  260. CategoryID uint8 `json:"category_id"`
  261. Name string `json:"name"`
  262. }
  263. type messageBody struct {
  264. Message string `json:"message"`
  265. }
  266. type feedbagGroupHandle struct {
  267. GroupID uint16 `json:"group_id"`
  268. GroupName string `json:"group_name"`
  269. }
  270. func feedbagGroupFromItem(item wire.FeedbagItem) feedbagGroupHandle {
  271. return feedbagGroupHandle{
  272. GroupID: item.GroupID,
  273. GroupName: item.Name,
  274. }
  275. }
  276. // icqProfileHandle is the JSON representation of a full ICQ user profile.
  277. type icqProfileHandle struct {
  278. UIN uint32 `json:"uin"`
  279. BasicInfo icqBasicInfoHandle `json:"basic_info"`
  280. MoreInfo icqMoreInfoHandle `json:"more_info"`
  281. WorkInfo icqWorkInfoHandle `json:"work_info"`
  282. Notes string `json:"notes"`
  283. Interests icqInterestsHandle `json:"interests"`
  284. Affiliations icqAffiliationsHandle `json:"affiliations"`
  285. Permissions icqPermissionsHandle `json:"permissions"`
  286. }
  287. type icqBasicInfoHandle struct {
  288. Nickname string `json:"nickname"`
  289. FirstName string `json:"first_name"`
  290. LastName string `json:"last_name"`
  291. EmailAddress string `json:"email"`
  292. City string `json:"city"`
  293. State string `json:"state"`
  294. Phone string `json:"phone"`
  295. Fax string `json:"fax"`
  296. Address string `json:"address"`
  297. CellPhone string `json:"cell_phone"`
  298. ZIPCode string `json:"zip"`
  299. CountryCode uint16 `json:"country_code"`
  300. GMTOffset uint8 `json:"gmt_offset"`
  301. PublishEmail bool `json:"publish_email"`
  302. OriginCity string `json:"origin_city"`
  303. OriginState string `json:"origin_state"`
  304. // OriginCountryCode is the ICQ country code for the user's original home.
  305. OriginCountryCode uint16 `json:"origin_country_code"`
  306. }
  307. type icqMoreInfoHandle struct {
  308. Gender uint16 `json:"gender"`
  309. HomePageAddr string `json:"homepage"`
  310. BirthYear uint16 `json:"birth_year"`
  311. BirthMonth uint8 `json:"birth_month"`
  312. BirthDay uint8 `json:"birth_day"`
  313. Lang1 uint8 `json:"lang1"`
  314. Lang2 uint8 `json:"lang2"`
  315. Lang3 uint8 `json:"lang3"`
  316. }
  317. type icqWorkInfoHandle struct {
  318. Company string `json:"company"`
  319. Department string `json:"department"`
  320. Position string `json:"position"`
  321. OccupationCode uint16 `json:"occupation_code"`
  322. Address string `json:"address"`
  323. City string `json:"city"`
  324. State string `json:"state"`
  325. ZIPCode string `json:"zip"`
  326. CountryCode uint16 `json:"country_code"`
  327. Phone string `json:"phone"`
  328. Fax string `json:"fax"`
  329. WebPage string `json:"web_page"`
  330. }
  331. type icqInterestsHandle struct {
  332. Code1 uint16 `json:"code1"`
  333. Keyword1 string `json:"keyword1"`
  334. Code2 uint16 `json:"code2"`
  335. Keyword2 string `json:"keyword2"`
  336. Code3 uint16 `json:"code3"`
  337. Keyword3 string `json:"keyword3"`
  338. Code4 uint16 `json:"code4"`
  339. Keyword4 string `json:"keyword4"`
  340. }
  341. type icqAffiliationsHandle struct {
  342. PastCode1 uint16 `json:"past_code1"`
  343. PastKeyword1 string `json:"past_keyword1"`
  344. PastCode2 uint16 `json:"past_code2"`
  345. PastKeyword2 string `json:"past_keyword2"`
  346. PastCode3 uint16 `json:"past_code3"`
  347. PastKeyword3 string `json:"past_keyword3"`
  348. CurrentCode1 uint16 `json:"current_code1"`
  349. CurrentKeyword1 string `json:"current_keyword1"`
  350. CurrentCode2 uint16 `json:"current_code2"`
  351. CurrentKeyword2 string `json:"current_keyword2"`
  352. CurrentCode3 uint16 `json:"current_code3"`
  353. CurrentKeyword3 string `json:"current_keyword3"`
  354. }
  355. type icqPermissionsHandle struct {
  356. AuthRequired bool `json:"auth_required"`
  357. WebAware bool `json:"web_aware"`
  358. AllowSpam bool `json:"allow_spam"`
  359. }