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