types.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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. // ProfileRetriever defines a method for retrieving a user's free-form profile.
  104. type ProfileRetriever interface {
  105. // Profile returns the user's profile information for the given screen name.
  106. Profile(ctx context.Context, screenName state.IdentScreenName) (state.UserProfile, error)
  107. }
  108. // SessionRetriever defines methods for retrieving active sessions,
  109. // either all of them or by screen name.
  110. type SessionRetriever interface {
  111. // AllSessions returns all active user sessions.
  112. AllSessions() []*state.Session
  113. // RetrieveSession returns the session associated with the given screen name,
  114. // or nil if no active session exists. Returns the Session object if there
  115. // are active instances with complete signon.
  116. RetrieveSession(screenName state.IdentScreenName) *state.Session
  117. }
  118. // UserManager defines methods for accessing and inserting AIM user records.
  119. type UserManager interface {
  120. // AllUsers returns all registered users.
  121. AllUsers(ctx context.Context) ([]state.User, error)
  122. // DeleteUser removes a user from the system by screen name.
  123. DeleteUser(ctx context.Context, screenName state.IdentScreenName) error
  124. // InsertUser inserts a new user into the system. Return state.ErrDupUser
  125. // if a user with the same screen name already exists.
  126. InsertUser(ctx context.Context, u state.User) error
  127. // SetUserPassword sets the user's password hashes and auth key.
  128. SetUserPassword(ctx context.Context, screenName state.IdentScreenName, newPassword string) error
  129. // User returns all attributes for a user.
  130. User(ctx context.Context, screenName state.IdentScreenName) (*state.User, error)
  131. }
  132. // ICQProfileManager defines methods for getting and setting ICQ user profile data.
  133. type ICQProfileManager interface {
  134. // User returns all attributes for a user.
  135. User(ctx context.Context, screenName state.IdentScreenName) (*state.User, error)
  136. // SetBasicInfo updates the user's basic ICQ profile info.
  137. SetBasicInfo(ctx context.Context, name state.IdentScreenName, data state.ICQBasicInfo) error
  138. // SetMoreInfo updates the user's additional ICQ info.
  139. SetMoreInfo(ctx context.Context, name state.IdentScreenName, data state.ICQMoreInfo) error
  140. // SetWorkInfo updates the user's work info.
  141. SetWorkInfo(ctx context.Context, name state.IdentScreenName, data state.ICQWorkInfo) error
  142. // SetUserNotes updates the user's notes.
  143. SetUserNotes(ctx context.Context, name state.IdentScreenName, data state.ICQUserNotes) error
  144. // SetInterests updates the user's interests.
  145. SetInterests(ctx context.Context, name state.IdentScreenName, data state.ICQInterests) error
  146. // SetAffiliations updates the user's affiliations.
  147. SetAffiliations(ctx context.Context, name state.IdentScreenName, data state.ICQAffiliations) error
  148. // SetPermissions updates the user's privacy permissions.
  149. SetPermissions(ctx context.Context, name state.IdentScreenName, data state.ICQPermissions) error
  150. // SetICQInfo updates all ICQ profile columns for the user in one operation.
  151. SetICQInfo(ctx context.Context, name state.IdentScreenName, info state.ICQInfo) error
  152. }
  153. // LinkedAccountManager manages linked account relationships.
  154. type LinkedAccountManager interface {
  155. LinkedAccounts(ctx context.Context, screenName state.IdentScreenName) ([]state.IdentScreenName, error)
  156. InsertLinkedAccount(ctx context.Context, screenName state.IdentScreenName, linkedScreenName state.IdentScreenName) error
  157. DeleteLinkedAccount(ctx context.Context, screenName state.IdentScreenName, linkedScreenName state.IdentScreenName) error
  158. DeleteAllLinkedAccounts(ctx context.Context, screenName state.IdentScreenName) error
  159. }
  160. type userWithPassword struct {
  161. ScreenName string `json:"screen_name"`
  162. Password string `json:"password,omitempty"`
  163. }
  164. type onlineUsers struct {
  165. Count int `json:"count"`
  166. Sessions []sessionHandle `json:"sessions"`
  167. }
  168. type userHandle struct {
  169. ID string `json:"id"`
  170. ScreenName string `json:"screen_name"`
  171. IsICQ bool `json:"is_icq"`
  172. SuspendedStatus string `json:"suspended_status"`
  173. IsBot bool `json:"is_bot"`
  174. }
  175. type aimChatUserHandle struct {
  176. ID string `json:"id"`
  177. ScreenName string `json:"screen_name"`
  178. }
  179. type userAccountHandle struct {
  180. ID string `json:"id"`
  181. ScreenName string `json:"screen_name"`
  182. Profile string `json:"profile"`
  183. EmailAddress string `json:"email_address"`
  184. RegStatus uint16 `json:"reg_status"`
  185. Confirmed bool `json:"confirmed"`
  186. IsICQ bool `json:"is_icq"`
  187. SuspendedStatus string `json:"suspended_status"`
  188. IsBot bool `json:"is_bot"`
  189. }
  190. type userAccountPatch struct {
  191. SuspendedStatusText *string `json:"suspended_status"`
  192. IsBot *bool `json:"is_bot"`
  193. }
  194. type sessionHandle struct {
  195. ID string `json:"id"`
  196. ScreenName string `json:"screen_name"`
  197. OnlineSeconds int `json:"online_seconds"`
  198. IsAway bool `json:"is_away"`
  199. AwayMessage string `json:"away_message"`
  200. IdleSeconds int `json:"idle_seconds"`
  201. IsInvisible bool `json:"is_invisible"`
  202. IsICQ bool `json:"is_icq"`
  203. InstanceCount int `json:"instance_count"`
  204. Instances []instanceHandle `json:"instances"`
  205. }
  206. type instanceHandle struct {
  207. Num int `json:"num"`
  208. IdleSeconds int `json:"idle_seconds"`
  209. IsAway bool `json:"is_away"`
  210. AwayMessage string `json:"away_message"`
  211. IsInvisible bool `json:"is_invisible"`
  212. RemoteAddr string `json:"remote_addr"`
  213. RemotePort int `json:"remote_port"`
  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. }
  233. type directoryKeyword struct {
  234. ID uint8 `json:"id"`
  235. Name string `json:"name"`
  236. }
  237. type directoryCategory struct {
  238. ID uint8 `json:"id"`
  239. Name string `json:"name"`
  240. }
  241. type directoryCategoryCreate struct {
  242. Name string `json:"name"`
  243. }
  244. type directoryKeywordCreate struct {
  245. CategoryID uint8 `json:"category_id"`
  246. Name string `json:"name"`
  247. }
  248. type messageBody struct {
  249. Message string `json:"message"`
  250. }
  251. type feedbagGroupHandle struct {
  252. GroupID uint16 `json:"group_id"`
  253. GroupName string `json:"group_name"`
  254. }
  255. func feedbagGroupFromItem(item wire.FeedbagItem) feedbagGroupHandle {
  256. return feedbagGroupHandle{
  257. GroupID: item.GroupID,
  258. GroupName: item.Name,
  259. }
  260. }
  261. // Web API key management types
  262. type createWebAPIKeyRequest struct {
  263. AppName string `json:"app_name"`
  264. AllowedOrigins []string `json:"allowed_origins,omitempty"`
  265. RateLimit int `json:"rate_limit,omitempty"`
  266. Capabilities []string `json:"capabilities,omitempty"`
  267. }
  268. type webAPIKeyResponse struct {
  269. DevID string `json:"dev_id"`
  270. DevKey string `json:"dev_key,omitempty"` // Only shown on creation
  271. AppName string `json:"app_name"`
  272. CreatedAt time.Time `json:"created_at"`
  273. LastUsed *time.Time `json:"last_used,omitempty"`
  274. IsActive bool `json:"is_active"`
  275. RateLimit int `json:"rate_limit"`
  276. AllowedOrigins []string `json:"allowed_origins,omitempty"`
  277. Capabilities []string `json:"capabilities,omitempty"`
  278. }
  279. // icqProfileHandle is the JSON representation of a full ICQ user profile.
  280. type icqProfileHandle struct {
  281. UIN uint32 `json:"uin"`
  282. BasicInfo icqBasicInfoHandle `json:"basic_info"`
  283. MoreInfo icqMoreInfoHandle `json:"more_info"`
  284. WorkInfo icqWorkInfoHandle `json:"work_info"`
  285. Notes string `json:"notes"`
  286. Interests icqInterestsHandle `json:"interests"`
  287. Affiliations icqAffiliationsHandle `json:"affiliations"`
  288. Permissions icqPermissionsHandle `json:"permissions"`
  289. }
  290. type icqBasicInfoHandle struct {
  291. Nickname string `json:"nickname"`
  292. FirstName string `json:"first_name"`
  293. LastName string `json:"last_name"`
  294. EmailAddress string `json:"email"`
  295. City string `json:"city"`
  296. State string `json:"state"`
  297. Phone string `json:"phone"`
  298. Fax string `json:"fax"`
  299. Address string `json:"address"`
  300. CellPhone string `json:"cell_phone"`
  301. ZIPCode string `json:"zip"`
  302. CountryCode uint16 `json:"country_code"`
  303. GMTOffset uint8 `json:"gmt_offset"`
  304. PublishEmail bool `json:"publish_email"`
  305. OriginCity string `json:"origin_city"`
  306. OriginState string `json:"origin_state"`
  307. // OriginCountryCode is the ICQ country code for the user's original home.
  308. OriginCountryCode uint16 `json:"origin_country_code"`
  309. }
  310. type icqMoreInfoHandle struct {
  311. Gender uint16 `json:"gender"`
  312. HomePageAddr string `json:"homepage"`
  313. BirthYear uint16 `json:"birth_year"`
  314. BirthMonth uint8 `json:"birth_month"`
  315. BirthDay uint8 `json:"birth_day"`
  316. Lang1 uint8 `json:"lang1"`
  317. Lang2 uint8 `json:"lang2"`
  318. Lang3 uint8 `json:"lang3"`
  319. }
  320. type icqWorkInfoHandle struct {
  321. Company string `json:"company"`
  322. Department string `json:"department"`
  323. Position string `json:"position"`
  324. OccupationCode uint16 `json:"occupation_code"`
  325. Address string `json:"address"`
  326. City string `json:"city"`
  327. State string `json:"state"`
  328. ZIPCode string `json:"zip"`
  329. CountryCode uint16 `json:"country_code"`
  330. Phone string `json:"phone"`
  331. Fax string `json:"fax"`
  332. WebPage string `json:"web_page"`
  333. }
  334. type icqInterestsHandle struct {
  335. Code1 uint16 `json:"code1"`
  336. Keyword1 string `json:"keyword1"`
  337. Code2 uint16 `json:"code2"`
  338. Keyword2 string `json:"keyword2"`
  339. Code3 uint16 `json:"code3"`
  340. Keyword3 string `json:"keyword3"`
  341. Code4 uint16 `json:"code4"`
  342. Keyword4 string `json:"keyword4"`
  343. }
  344. type icqAffiliationsHandle struct {
  345. PastCode1 uint16 `json:"past_code1"`
  346. PastKeyword1 string `json:"past_keyword1"`
  347. PastCode2 uint16 `json:"past_code2"`
  348. PastKeyword2 string `json:"past_keyword2"`
  349. PastCode3 uint16 `json:"past_code3"`
  350. PastKeyword3 string `json:"past_keyword3"`
  351. CurrentCode1 uint16 `json:"current_code1"`
  352. CurrentKeyword1 string `json:"current_keyword1"`
  353. CurrentCode2 uint16 `json:"current_code2"`
  354. CurrentKeyword2 string `json:"current_keyword2"`
  355. CurrentCode3 uint16 `json:"current_code3"`
  356. CurrentKeyword3 string `json:"current_keyword3"`
  357. }
  358. type icqPermissionsHandle struct {
  359. AuthRequired bool `json:"auth_required"`
  360. WebAware bool `json:"web_aware"`
  361. AllowSpam bool `json:"allow_spam"`
  362. }
  363. type updateWebAPIKeyRequest struct {
  364. AppName *string `json:"app_name,omitempty"`
  365. IsActive *bool `json:"is_active,omitempty"`
  366. RateLimit *int `json:"rate_limit,omitempty"`
  367. AllowedOrigins *[]string `json:"allowed_origins,omitempty"`
  368. Capabilities *[]string `json:"capabilities,omitempty"`
  369. }