1 | /* |
---|
2 | * misc.c |
---|
3 | * |
---|
4 | * Random stuff. Basically just a few functions for sending |
---|
5 | * simple SNACs, and then the generic error handler. |
---|
6 | * |
---|
7 | */ |
---|
8 | |
---|
9 | #define FAIM_INTERNAL |
---|
10 | #include <aim.h> |
---|
11 | |
---|
12 | /* |
---|
13 | * Generic routine for sending commands. |
---|
14 | * |
---|
15 | * |
---|
16 | * I know I can do this in a smarter way...but I'm not thinking straight |
---|
17 | * right now... |
---|
18 | * |
---|
19 | * I had one big function that handled all three cases, but then it broke |
---|
20 | * and I split it up into three. But then I fixed it. I just never went |
---|
21 | * back to the single. I don't see any advantage to doing it either way. |
---|
22 | * |
---|
23 | */ |
---|
24 | faim_internal int aim_genericreq_n(aim_session_t *sess, aim_conn_t *conn, fu16_t family, fu16_t subtype) |
---|
25 | { |
---|
26 | aim_frame_t *fr; |
---|
27 | aim_snacid_t snacid = 0x00000000; |
---|
28 | |
---|
29 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10))) |
---|
30 | return -ENOMEM; |
---|
31 | |
---|
32 | aim_putsnac(&fr->data, family, subtype, 0x0000, snacid); |
---|
33 | |
---|
34 | aim_tx_enqueue(sess, fr); |
---|
35 | |
---|
36 | return 0; |
---|
37 | } |
---|
38 | |
---|
39 | faim_internal int aim_genericreq_n_snacid(aim_session_t *sess, aim_conn_t *conn, fu16_t family, fu16_t subtype) |
---|
40 | { |
---|
41 | aim_frame_t *fr; |
---|
42 | aim_snacid_t snacid; |
---|
43 | |
---|
44 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10))) |
---|
45 | return -ENOMEM; |
---|
46 | |
---|
47 | snacid = aim_cachesnac(sess, family, subtype, 0x0000, NULL, 0); |
---|
48 | aim_putsnac(&fr->data, family, subtype, 0x0000, snacid); |
---|
49 | |
---|
50 | aim_tx_enqueue(sess, fr); |
---|
51 | |
---|
52 | return 0; |
---|
53 | } |
---|
54 | |
---|
55 | faim_internal int aim_genericreq_l(aim_session_t *sess, aim_conn_t *conn, fu16_t family, fu16_t subtype, fu32_t *longdata) |
---|
56 | { |
---|
57 | aim_frame_t *fr; |
---|
58 | aim_snacid_t snacid; |
---|
59 | |
---|
60 | if (!longdata) |
---|
61 | return aim_genericreq_n(sess, conn, family, subtype); |
---|
62 | |
---|
63 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+4))) |
---|
64 | return -ENOMEM; |
---|
65 | |
---|
66 | snacid = aim_cachesnac(sess, family, subtype, 0x0000, NULL, 0); |
---|
67 | |
---|
68 | aim_putsnac(&fr->data, family, subtype, 0x0000, snacid); |
---|
69 | aimbs_put32(&fr->data, *longdata); |
---|
70 | |
---|
71 | aim_tx_enqueue(sess, fr); |
---|
72 | |
---|
73 | return 0; |
---|
74 | } |
---|
75 | |
---|
76 | faim_internal int aim_genericreq_s(aim_session_t *sess, aim_conn_t *conn, fu16_t family, fu16_t subtype, fu16_t *shortdata) |
---|
77 | { |
---|
78 | aim_frame_t *fr; |
---|
79 | aim_snacid_t snacid; |
---|
80 | |
---|
81 | if (!shortdata) |
---|
82 | return aim_genericreq_n(sess, conn, family, subtype); |
---|
83 | |
---|
84 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2))) |
---|
85 | return -ENOMEM; |
---|
86 | |
---|
87 | snacid = aim_cachesnac(sess, family, subtype, 0x0000, NULL, 0); |
---|
88 | |
---|
89 | aim_putsnac(&fr->data, family, subtype, 0x0000, snacid); |
---|
90 | aimbs_put16(&fr->data, *shortdata); |
---|
91 | |
---|
92 | aim_tx_enqueue(sess, fr); |
---|
93 | |
---|
94 | return 0; |
---|
95 | } |
---|
96 | |
---|
97 | /* |
---|
98 | * Should be generic enough to handle the errors for all groups. |
---|
99 | * |
---|
100 | */ |
---|
101 | static int generror(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
102 | { |
---|
103 | int ret = 0; |
---|
104 | int error = 0; |
---|
105 | aim_rxcallback_t userfunc; |
---|
106 | aim_snac_t *snac2; |
---|
107 | |
---|
108 | snac2 = aim_remsnac(sess, snac->id); |
---|
109 | |
---|
110 | if (aim_bstream_empty(bs)) |
---|
111 | error = aimbs_get16(bs); |
---|
112 | |
---|
113 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
---|
114 | ret = userfunc(sess, rx, error, snac2 ? snac2->data : NULL); |
---|
115 | |
---|
116 | if (snac2) |
---|
117 | free(snac2->data); |
---|
118 | free(snac2); |
---|
119 | |
---|
120 | return ret; |
---|
121 | } |
---|
122 | |
---|
123 | static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
124 | { |
---|
125 | |
---|
126 | if (snac->subtype == 0x0001) |
---|
127 | return generror(sess, mod, rx, snac, bs); |
---|
128 | else if ((snac->family == 0xffff) && (snac->subtype == 0xffff)) { |
---|
129 | aim_rxcallback_t userfunc; |
---|
130 | |
---|
131 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
---|
132 | return userfunc(sess, rx); |
---|
133 | } |
---|
134 | |
---|
135 | return 0; |
---|
136 | } |
---|
137 | |
---|
138 | faim_internal int misc_modfirst(aim_session_t *sess, aim_module_t *mod) |
---|
139 | { |
---|
140 | |
---|
141 | mod->family = 0xffff; |
---|
142 | mod->version = 0x0000; |
---|
143 | mod->flags = AIM_MODFLAG_MULTIFAMILY; |
---|
144 | strncpy(mod->name, "misc", sizeof(mod->name)); |
---|
145 | mod->snachandler = snachandler; |
---|
146 | |
---|
147 | return 0; |
---|
148 | } |
---|