| 1 | /* |
|---|
| 2 | * Family 0x0010 - Server stored buddy art |
|---|
| 3 | * |
|---|
| 4 | * Used for storing and retrieving your cute little buddy icon |
|---|
| 5 | * from the AIM servers. |
|---|
| 6 | * |
|---|
| 7 | */ |
|---|
| 8 | |
|---|
| 9 | #define FAIM_INTERNAL |
|---|
| 10 | #include <aim.h> |
|---|
| 11 | |
|---|
| 12 | /** |
|---|
| 13 | * Subtype 0x0002 - Upload your icon. |
|---|
| 14 | * |
|---|
| 15 | * @param sess The oscar session. |
|---|
| 16 | * @param conn The icon connection for this session. |
|---|
| 17 | * @param icon The raw data of the icon image file. |
|---|
| 18 | * @param iconlen Length of the raw data of the icon image file. |
|---|
| 19 | * @return Return 0 if no errors, otherwise return the error number. |
|---|
| 20 | */ |
|---|
| 21 | faim_export int aim_bart_upload(aim_session_t *sess, const fu8_t *icon, fu16_t iconlen) |
|---|
| 22 | { |
|---|
| 23 | aim_conn_t *conn; |
|---|
| 24 | aim_frame_t *fr; |
|---|
| 25 | aim_snacid_t snacid; |
|---|
| 26 | |
|---|
| 27 | if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0010)) || !icon || !iconlen) |
|---|
| 28 | return -EINVAL; |
|---|
| 29 | |
|---|
| 30 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 2 + 2+iconlen))) |
|---|
| 31 | return -ENOMEM; |
|---|
| 32 | snacid = aim_cachesnac(sess, 0x0010, 0x0002, 0x0000, NULL, 0); |
|---|
| 33 | aim_putsnac(&fr->data, 0x0010, 0x0002, 0x0000, snacid); |
|---|
| 34 | |
|---|
| 35 | /* The reference number for the icon */ |
|---|
| 36 | aimbs_put16(&fr->data, 1); |
|---|
| 37 | |
|---|
| 38 | /* The icon */ |
|---|
| 39 | aimbs_put16(&fr->data, iconlen); |
|---|
| 40 | aimbs_putraw(&fr->data, icon, iconlen); |
|---|
| 41 | |
|---|
| 42 | aim_tx_enqueue(sess, fr); |
|---|
| 43 | |
|---|
| 44 | return 0; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | /** |
|---|
| 48 | * Subtype 0x0003 - Acknowledgement for uploading a buddy icon. |
|---|
| 49 | * |
|---|
| 50 | * You get this honky after you upload a buddy icon. |
|---|
| 51 | */ |
|---|
| 52 | static int uploadack(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
|---|
| 53 | { |
|---|
| 54 | int ret = 0; |
|---|
| 55 | aim_rxcallback_t userfunc; |
|---|
| 56 | fu16_t something, somethingelse; |
|---|
| 57 | fu8_t onemorething; |
|---|
| 58 | |
|---|
| 59 | something = aimbs_get16(bs); |
|---|
| 60 | somethingelse = aimbs_get16(bs); |
|---|
| 61 | onemorething = aimbs_get8(bs); |
|---|
| 62 | |
|---|
| 63 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
|---|
| 64 | ret = userfunc(sess, rx); |
|---|
| 65 | |
|---|
| 66 | return ret; |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | /** |
|---|
| 70 | * Subtype 0x0004 - Request someone's icon. |
|---|
| 71 | * |
|---|
| 72 | * @param sess The oscar session. |
|---|
| 73 | * @param conn The icon connection for this session. |
|---|
| 74 | * @param sn The screen name of the person who's icon you are requesting. |
|---|
| 75 | * @param iconcsum The MD5 checksum of the icon you are requesting. |
|---|
| 76 | * @param iconcsumlen Length of the MD5 checksum given above. Should be 10 bytes. |
|---|
| 77 | * @return Return 0 if no errors, otherwise return the error number. |
|---|
| 78 | */ |
|---|
| 79 | faim_export int aim_bart_request(aim_session_t *sess, const char *sn, const fu8_t *iconcsum, fu16_t iconcsumlen) |
|---|
| 80 | { |
|---|
| 81 | aim_conn_t *conn; |
|---|
| 82 | aim_frame_t *fr; |
|---|
| 83 | aim_snacid_t snacid; |
|---|
| 84 | |
|---|
| 85 | if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0010)) || !sn || !strlen(sn) || !iconcsum || !iconcsumlen) |
|---|
| 86 | return -EINVAL; |
|---|
| 87 | |
|---|
| 88 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 1+strlen(sn) + 4 + 1+iconcsumlen))) |
|---|
| 89 | return -ENOMEM; |
|---|
| 90 | snacid = aim_cachesnac(sess, 0x0010, 0x0004, 0x0000, NULL, 0); |
|---|
| 91 | aim_putsnac(&fr->data, 0x0010, 0x0004, 0x0000, snacid); |
|---|
| 92 | |
|---|
| 93 | /* Screen name */ |
|---|
| 94 | aimbs_put8(&fr->data, strlen(sn)); |
|---|
| 95 | aimbs_putraw(&fr->data, sn, strlen(sn)); |
|---|
| 96 | |
|---|
| 97 | /* Some numbers. You like numbers, right? */ |
|---|
| 98 | aimbs_put8(&fr->data, 0x01); |
|---|
| 99 | aimbs_put16(&fr->data, 0x0001); |
|---|
| 100 | aimbs_put8(&fr->data, 0x01); |
|---|
| 101 | |
|---|
| 102 | /* Icon string */ |
|---|
| 103 | aimbs_put8(&fr->data, iconcsumlen); |
|---|
| 104 | aimbs_putraw(&fr->data, iconcsum, iconcsumlen); |
|---|
| 105 | |
|---|
| 106 | aim_tx_enqueue(sess, fr); |
|---|
| 107 | |
|---|
| 108 | return 0; |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | /** |
|---|
| 112 | * Subtype 0x0005 - Receive a buddy icon. |
|---|
| 113 | * |
|---|
| 114 | * This is sent in response to a buddy icon request. |
|---|
| 115 | */ |
|---|
| 116 | static int parseicon(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
|---|
| 117 | { |
|---|
| 118 | int ret = 0; |
|---|
| 119 | aim_rxcallback_t userfunc; |
|---|
| 120 | char *sn; |
|---|
| 121 | fu16_t flags, iconlen; |
|---|
| 122 | fu8_t number, iconcsumlen, *iconcsum, *icon; |
|---|
| 123 | |
|---|
| 124 | sn = aimbs_getstr(bs, aimbs_get8(bs)); |
|---|
| 125 | flags = aimbs_get16(bs); |
|---|
| 126 | number = aimbs_get8(bs); |
|---|
| 127 | iconcsumlen = aimbs_get8(bs); |
|---|
| 128 | iconcsum = aimbs_getraw(bs, iconcsumlen); |
|---|
| 129 | iconlen = aimbs_get16(bs); |
|---|
| 130 | icon = aimbs_getraw(bs, iconlen); |
|---|
| 131 | |
|---|
| 132 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
|---|
| 133 | ret = userfunc(sess, rx, sn, iconcsum, iconcsumlen, icon, iconlen); |
|---|
| 134 | |
|---|
| 135 | free(sn); |
|---|
| 136 | free(iconcsum); |
|---|
| 137 | free(icon); |
|---|
| 138 | |
|---|
| 139 | return ret; |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
|---|
| 143 | { |
|---|
| 144 | |
|---|
| 145 | if (snac->subtype == 0x0003) |
|---|
| 146 | return uploadack(sess, mod, rx, snac, bs); |
|---|
| 147 | else if (snac->subtype == 0x0005) |
|---|
| 148 | return parseicon(sess, mod, rx, snac, bs); |
|---|
| 149 | |
|---|
| 150 | return 0; |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | faim_internal int bart_modfirst(aim_session_t *sess, aim_module_t *mod) |
|---|
| 154 | { |
|---|
| 155 | |
|---|
| 156 | mod->family = 0x0010; |
|---|
| 157 | mod->version = 0x0001; |
|---|
| 158 | mod->toolid = 0x0010; |
|---|
| 159 | mod->toolversion = 0x0629; |
|---|
| 160 | mod->flags = 0; |
|---|
| 161 | strncpy(mod->name, "bart", sizeof(mod->name)); |
|---|
| 162 | mod->snachandler = snachandler; |
|---|
| 163 | |
|---|
| 164 | return 0; |
|---|
| 165 | } |
|---|