Просмотр исходного кода

Revert "replace ICQ Interests and Affiliations slices (#111)"

This reverts commit ddde769b87783896396e39de2de39cb972642e6f.
Mike 1 год назад
Родитель
Сommit
1454027ed0
4 измененных файлов с 69 добавлено и 16 удалено
  1. 8 2
      foodgroup/icq.go
  2. 52 5
      foodgroup/icq_test.go
  3. 6 6
      server/oscar/handler/icq_test.go
  4. 3 3
      wire/snacs.go

+ 8 - 2
foodgroup/icq.go

@@ -461,6 +461,9 @@ func (s ICQService) OfflineMsgReq(ctx context.Context, sess *state.Session, seq
 }
 
 func (s ICQService) SetAffiliations(ctx context.Context, sess *state.Session, req wire.ICQ_0x07D0_0x041A_DBQueryMetaReqSetAffiliations, seq uint16) error {
+	if len(req.PastAffiliations) != 3 || len(req.Affiliations) != 3 {
+		return fmt.Errorf("%w: expected 3 past affiliations and 3 affiliations", errICQBadRequest)
+	}
 	u := state.ICQAffiliations{
 		PastCode1:       req.PastAffiliations[0].Code,
 		PastKeyword1:    req.PastAffiliations[0].Keyword,
@@ -516,6 +519,9 @@ func (s ICQService) SetEmails(ctx context.Context, sess *state.Session, req wire
 }
 
 func (s ICQService) SetInterests(ctx context.Context, sess *state.Session, req wire.ICQ_0x07D0_0x0410_DBQueryMetaReqSetInterests, seq uint16) error {
+	if len(req.Interests) != 4 {
+		return fmt.Errorf("%w: expected 4 interests", errICQBadRequest)
+	}
 	u := state.ICQInterests{
 		Code1:    req.Interests[0].Code,
 		Keyword1: req.Interests[0].Keyword,
@@ -650,7 +656,7 @@ func (s ICQService) affiliations(ctx context.Context, sess *state.Session, user
 			ReqSubType: wire.ICQDBQueryMetaReplyAffiliations,
 			Success:    wire.ICQStatusCodeOK,
 			ICQ_0x07D0_0x041A_DBQueryMetaReqSetAffiliations: wire.ICQ_0x07D0_0x041A_DBQueryMetaReqSetAffiliations{
-				PastAffiliations: [3]struct {
+				PastAffiliations: []struct {
 					Code    uint16
 					Keyword string `oscar:"len_prefix=uint16,nullterm"`
 				}{
@@ -667,7 +673,7 @@ func (s ICQService) affiliations(ctx context.Context, sess *state.Session, user
 						Keyword: user.ICQAffiliations.PastKeyword3,
 					},
 				},
-				Affiliations: [3]struct {
+				Affiliations: []struct {
 					Code    uint16
 					Keyword string `oscar:"len_prefix=uint16,nullterm"`
 				}{

+ 52 - 5
foodgroup/icq_test.go

@@ -1706,7 +1706,7 @@ func TestICQService_FullUserInfo(t *testing.T) {
 													Success:    wire.ICQStatusCodeOK,
 													ReqSubType: wire.ICQDBQueryMetaReplyAffiliations,
 													ICQ_0x07D0_0x041A_DBQueryMetaReqSetAffiliations: wire.ICQ_0x07D0_0x041A_DBQueryMetaReqSetAffiliations{
-														PastAffiliations: [3]struct {
+														PastAffiliations: []struct {
 															Code    uint16
 															Keyword string `oscar:"len_prefix=uint16,nullterm"`
 														}{
@@ -1723,7 +1723,7 @@ func TestICQService_FullUserInfo(t *testing.T) {
 																Keyword: "Previous Job",
 															},
 														},
-														Affiliations: [3]struct {
+														Affiliations: []struct {
 															Code    uint16
 															Keyword string `oscar:"len_prefix=uint16,nullterm"`
 														}{
@@ -1978,7 +1978,7 @@ func TestICQService_SetAffiliations(t *testing.T) {
 			seq:  1,
 			sess: newTestSession("100003", sessOptUIN(100003)),
 			req: wire.ICQ_0x07D0_0x041A_DBQueryMetaReqSetAffiliations{
-				PastAffiliations: [3]struct {
+				PastAffiliations: []struct {
 					Code    uint16
 					Keyword string `oscar:"len_prefix=uint16,nullterm"`
 				}{
@@ -1995,7 +1995,7 @@ func TestICQService_SetAffiliations(t *testing.T) {
 						Keyword: "kw3",
 					},
 				},
-				Affiliations: [3]struct {
+				Affiliations: []struct {
 					Code    uint16
 					Keyword string `oscar:"len_prefix=uint16,nullterm"`
 				}{
@@ -2067,6 +2067,32 @@ func TestICQService_SetAffiliations(t *testing.T) {
 				},
 			},
 		},
+		{
+			name: "err: unexpected affiliations count",
+			seq:  1,
+			sess: newTestSession("100003", sessOptUIN(100003)),
+			req: wire.ICQ_0x07D0_0x041A_DBQueryMetaReqSetAffiliations{
+				PastAffiliations: []struct {
+					Code    uint16
+					Keyword string `oscar:"len_prefix=uint16,nullterm"`
+				}{
+					{
+						Code:    1,
+						Keyword: "kw1",
+					},
+				},
+				Affiliations: []struct {
+					Code    uint16
+					Keyword string `oscar:"len_prefix=uint16,nullterm"`
+				}{
+					{
+						Code:    4,
+						Keyword: "kw4",
+					},
+				},
+			},
+			wantErr: errICQBadRequest,
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
@@ -2291,7 +2317,7 @@ func TestICQService_SetInterests(t *testing.T) {
 			seq:  1,
 			sess: newTestSession("100003", sessOptUIN(100003)),
 			req: wire.ICQ_0x07D0_0x0410_DBQueryMetaReqSetInterests{
-				Interests: [4]struct {
+				Interests: []struct {
 					Code    uint16
 					Keyword string `oscar:"len_prefix=uint16,nullterm"`
 				}{
@@ -2363,6 +2389,27 @@ func TestICQService_SetInterests(t *testing.T) {
 				},
 			},
 		},
+		{
+			name: "err: unexpected interest count",
+			seq:  1,
+			sess: newTestSession("100003", sessOptUIN(100003)),
+			req: wire.ICQ_0x07D0_0x0410_DBQueryMetaReqSetInterests{
+				Interests: []struct {
+					Code    uint16
+					Keyword string `oscar:"len_prefix=uint16,nullterm"`
+				}{
+					{
+						Code:    1,
+						Keyword: "kw1",
+					},
+					{
+						Code:    2,
+						Keyword: "kw2",
+					},
+				},
+			},
+			wantErr: errICQBadRequest,
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {

+ 6 - 6
server/oscar/handler/icq_test.go

@@ -657,7 +657,7 @@ func TestICQHandler_DBQuery(t *testing.T) {
 									},
 									ReqSubType: wire.ICQDBQueryMetaReqSetInterests,
 									MetaRequest: wire.ICQ_0x07D0_0x0410_DBQueryMetaReqSetInterests{
-										Interests: [4]struct {
+										Interests: []struct {
 											Code    uint16
 											Keyword string `oscar:"len_prefix=uint16,nullterm"`
 										}{
@@ -676,7 +676,7 @@ func TestICQHandler_DBQuery(t *testing.T) {
 			allMockParams: allMockParams{
 				setInterests: &mockParam{
 					req: wire.ICQ_0x07D0_0x0410_DBQueryMetaReqSetInterests{
-						Interests: [4]struct {
+						Interests: []struct {
 							Code    uint16
 							Keyword string `oscar:"len_prefix=uint16,nullterm"`
 						}{
@@ -703,7 +703,7 @@ func TestICQHandler_DBQuery(t *testing.T) {
 									},
 									ReqSubType: wire.ICQDBQueryMetaReqSetAffiliations,
 									MetaRequest: wire.ICQ_0x07D0_0x041A_DBQueryMetaReqSetAffiliations{
-										PastAffiliations: [3]struct {
+										PastAffiliations: []struct {
 											Code    uint16
 											Keyword string `oscar:"len_prefix=uint16,nullterm"`
 										}{
@@ -711,7 +711,7 @@ func TestICQHandler_DBQuery(t *testing.T) {
 												Keyword: "a_past_affiliation",
 											},
 										},
-										Affiliations: [3]struct {
+										Affiliations: []struct {
 											Code    uint16
 											Keyword string `oscar:"len_prefix=uint16,nullterm"`
 										}{
@@ -730,7 +730,7 @@ func TestICQHandler_DBQuery(t *testing.T) {
 			allMockParams: allMockParams{
 				setAffiliations: &mockParam{
 					req: wire.ICQ_0x07D0_0x041A_DBQueryMetaReqSetAffiliations{
-						PastAffiliations: [3]struct {
+						PastAffiliations: []struct {
 							Code    uint16
 							Keyword string `oscar:"len_prefix=uint16,nullterm"`
 						}{
@@ -738,7 +738,7 @@ func TestICQHandler_DBQuery(t *testing.T) {
 								Keyword: "a_past_affiliation",
 							},
 						},
-						Affiliations: [3]struct {
+						Affiliations: []struct {
 							Code    uint16
 							Keyword string `oscar:"len_prefix=uint16,nullterm"`
 						}{

+ 3 - 3
wire/snacs.go

@@ -1802,18 +1802,18 @@ type ICQ_0x07D0_0x0406_DBQueryMetaReqSetNotes struct {
 }
 
 type ICQ_0x07D0_0x0410_DBQueryMetaReqSetInterests struct {
-	Interests [4]struct {
+	Interests []struct {
 		Code    uint16
 		Keyword string `oscar:"len_prefix=uint16,nullterm"`
 	} `oscar:"count_prefix=uint8"`
 }
 
 type ICQ_0x07D0_0x041A_DBQueryMetaReqSetAffiliations struct {
-	PastAffiliations [3]struct {
+	PastAffiliations []struct {
 		Code    uint16
 		Keyword string `oscar:"len_prefix=uint16,nullterm"`
 	} `oscar:"count_prefix=uint8"`
-	Affiliations [3]struct {
+	Affiliations []struct {
 		Code    uint16
 		Keyword string `oscar:"len_prefix=uint16,nullterm"`
 	} `oscar:"count_prefix=uint8"`