Tue, 14 Oct 2003 04:35:46 +0000
[gaim-migrate @ 7836]
Correctly handle failed get info requests.
This should fix that bug that's assigned to me, and also the
problem SimGuy (and other people) have had where you need to
Get Info twice before it works.
| 3694 | 1 | /* |
| 2 | * Family 0x0018 - Email notification | |
| 3 | * | |
| 4 | * Used for being alerted when the email address(es) associated with | |
| 5 | * your screen name get new electronic-m. For normal AIM accounts, you | |
| 6 | * get the email address screenname@netscape.net. AOL accounts have | |
| 7 | * screenname@aol.com, and can also activate a netscape.net account. | |
| 8 | * | |
| 9 | */ | |
| 10 | ||
| 11 | #define FAIM_INTERNAL | |
| 12 | #include <aim.h> | |
| 13 | ||
| 3725 | 14 | /** |
| 3694 | 15 | * Subtype 0x0006 - Request information about your email account |
| 3725 | 16 | * |
| 17 | * @param sess The oscar session. | |
| 18 | * @param conn The email connection for this session. | |
| 19 | * @return Return 0 if no errors, otherwise return the error number. | |
| 3694 | 20 | */ |
| 21 | faim_export int aim_email_sendcookies(aim_session_t *sess, aim_conn_t *conn) | |
| 22 | { | |
| 23 | aim_frame_t *fr; | |
| 24 | aim_snacid_t snacid; | |
| 25 | ||
| 26 | if (!sess || !conn) | |
| 27 | return -EINVAL; | |
| 28 | ||
| 29 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+16+16))) | |
| 30 | return -ENOMEM; | |
| 31 | snacid = aim_cachesnac(sess, 0x0018, 0x0006, 0x0000, NULL, 0); | |
| 32 | aim_putsnac(&fr->data, 0x0018, 0x0006, 0x0000, snacid); | |
| 33 | ||
| 34 | /* Number of cookies to follow */ | |
| 35 | aimbs_put16(&fr->data, 0x0002); | |
| 36 | ||
| 37 | /* Cookie */ | |
| 38 | aimbs_put16(&fr->data, 0x5d5e); | |
| 39 | aimbs_put16(&fr->data, 0x1708); | |
| 40 | aimbs_put16(&fr->data, 0x55aa); | |
| 41 | aimbs_put16(&fr->data, 0x11d3); | |
| 42 | aimbs_put16(&fr->data, 0xb143); | |
| 43 | aimbs_put16(&fr->data, 0x0060); | |
| 44 | aimbs_put16(&fr->data, 0xb0fb); | |
| 45 | aimbs_put16(&fr->data, 0x1ecb); | |
| 46 | ||
| 47 | /* Cookie */ | |
| 48 | aimbs_put16(&fr->data, 0xb380); | |
| 49 | aimbs_put16(&fr->data, 0x9ad8); | |
| 50 | aimbs_put16(&fr->data, 0x0dba); | |
| 51 | aimbs_put16(&fr->data, 0x11d5); | |
| 52 | aimbs_put16(&fr->data, 0x9f8a); | |
| 53 | aimbs_put16(&fr->data, 0x0060); | |
| 54 | aimbs_put16(&fr->data, 0xb0ee); | |
| 55 | aimbs_put16(&fr->data, 0x0631); | |
| 56 | ||
| 57 | aim_tx_enqueue(sess, fr); | |
| 58 | ||
| 59 | return 0; | |
| 60 | } | |
| 61 | ||
| 62 | ||
| 3725 | 63 | /** |
| 3694 | 64 | * Subtype 0x0007 - Receive information about your email account |
|
4804
e6e0e6d50d39
[gaim-migrate @ 5124]
Mark Doliner <markdoliner@pidgin.im>
parents:
3952
diff
changeset
|
65 | * |
| 3725 | 66 | * So I don't even know if you can have multiple 16 byte keys, |
| 3694 | 67 | * but this is coded so it will handle that, and handle it well. |
| 3725 | 68 | * This tells you if you have unread mail or not, the URL you |
| 69 | * should use to access that mail, and the domain name for the | |
| 70 | * email account (screenname@domainname.com). If this is the | |
| 71 | * first 0x0007 SNAC you've received since you signed on, or if | |
| 72 | * this is just a periodic status update, this will also contain | |
| 73 | * the number of unread emails that you have. | |
| 3694 | 74 | */ |
| 75 | static int parseinfo(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) | |
| 76 | { | |
|
4871
962860053dcd
[gaim-migrate @ 5201]
Mark Doliner <markdoliner@pidgin.im>
parents:
4804
diff
changeset
|
77 | int ret = 0; |
| 3694 | 78 | aim_rxcallback_t userfunc; |
| 79 | struct aim_emailinfo *new; | |
| 80 | aim_tlvlist_t *tlvlist; | |
| 81 | fu8_t *cookie8, *cookie16; | |
| 3725 | 82 | int tmp, havenewmail = 0; /* Used to tell the client we have _new_ mail */ |
| 3694 | 83 | |
| 84 | cookie8 = aimbs_getraw(bs, 8); /* Possibly the code used to log you in to mail? */ | |
| 85 | cookie16 = aimbs_getraw(bs, 16); /* Mail cookie sent above */ | |
| 86 | ||
| 87 | /* See if we already have some info associated with this cookie */ | |
|
7045
458b55091f8b
[gaim-migrate @ 7608]
Mark Doliner <markdoliner@pidgin.im>
parents:
7011
diff
changeset
|
88 | for (new=sess->emailinfo; (new && strncmp(cookie16, new->cookie16, 16)); new=new->next); |
| 3694 | 89 | if (new) { |
| 90 | /* Free some of the old info, if existant */ | |
|
3952
d13e1fde68d8
[gaim-migrate @ 4133]
Mark Doliner <markdoliner@pidgin.im>
parents:
3725
diff
changeset
|
91 | free(new->cookie8); |
|
d13e1fde68d8
[gaim-migrate @ 4133]
Mark Doliner <markdoliner@pidgin.im>
parents:
3725
diff
changeset
|
92 | free(new->cookie16); |
|
d13e1fde68d8
[gaim-migrate @ 4133]
Mark Doliner <markdoliner@pidgin.im>
parents:
3725
diff
changeset
|
93 | free(new->url); |
|
d13e1fde68d8
[gaim-migrate @ 4133]
Mark Doliner <markdoliner@pidgin.im>
parents:
3725
diff
changeset
|
94 | free(new->domain); |
| 3694 | 95 | } else { |
| 96 | /* We don't already have info, so create a new struct for it */ | |
| 97 | if (!(new = malloc(sizeof(struct aim_emailinfo)))) | |
| 98 | return -ENOMEM; | |
| 3725 | 99 | memset(new, 0, sizeof(struct aim_emailinfo)); |
|
7045
458b55091f8b
[gaim-migrate @ 7608]
Mark Doliner <markdoliner@pidgin.im>
parents:
7011
diff
changeset
|
100 | new->next = sess->emailinfo; |
|
458b55091f8b
[gaim-migrate @ 7608]
Mark Doliner <markdoliner@pidgin.im>
parents:
7011
diff
changeset
|
101 | sess->emailinfo = new; |
| 3694 | 102 | } |
| 103 | ||
| 104 | new->cookie8 = cookie8; | |
| 105 | new->cookie16 = cookie16; | |
| 106 | ||
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7045
diff
changeset
|
107 | tlvlist = aim_tlvlist_readnum(bs, aimbs_get16(bs)); |
| 3694 | 108 | |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7045
diff
changeset
|
109 | tmp = aim_tlv_get16(tlvlist, 0x0080, 1); |
| 3725 | 110 | if (tmp) { |
| 111 | if (new->nummsgs < tmp) | |
| 112 | havenewmail = 1; | |
| 113 | new->nummsgs = tmp; | |
| 114 | } else { | |
| 115 | /* If they don't send a 0x0080 TLV, it means we definately have new mail */ | |
| 116 | /* (ie. this is not just another status update) */ | |
| 117 | havenewmail = 1; | |
| 118 | new->nummsgs++; /* We know we have at least 1 new email */ | |
| 119 | } | |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7045
diff
changeset
|
120 | new->url = aim_tlv_getstr(tlvlist, 0x0007, 1); |
|
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7045
diff
changeset
|
121 | if (!(new->unread = aim_tlv_get8(tlvlist, 0x0081, 1))) { |
| 3725 | 122 | havenewmail = 0; |
| 123 | new->nummsgs = 0; | |
| 124 | } | |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7045
diff
changeset
|
125 | new->domain = aim_tlv_getstr(tlvlist, 0x0082, 1); |
|
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7045
diff
changeset
|
126 | new->flag = aim_tlv_get16(tlvlist, 0x0084, 1); |
| 3694 | 127 | |
| 128 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
|
4871
962860053dcd
[gaim-migrate @ 5201]
Mark Doliner <markdoliner@pidgin.im>
parents:
4804
diff
changeset
|
129 | ret = userfunc(sess, rx, new, havenewmail); |
| 3694 | 130 | |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7045
diff
changeset
|
131 | aim_tlvlist_free(&tlvlist); |
|
4875
3aefead7212b
[gaim-migrate @ 5205]
Mark Doliner <markdoliner@pidgin.im>
parents:
4871
diff
changeset
|
132 | |
|
4871
962860053dcd
[gaim-migrate @ 5201]
Mark Doliner <markdoliner@pidgin.im>
parents:
4804
diff
changeset
|
133 | return ret; |
| 3694 | 134 | } |
| 135 | ||
| 3725 | 136 | /** |
| 3694 | 137 | * Subtype 0x0016 - Send something or other |
| 3725 | 138 | * |
| 139 | * @param sess The oscar session. | |
| 140 | * @param conn The email connection for this session. | |
| 141 | * @return Return 0 if no errors, otherwise return the error number. | |
| 3694 | 142 | */ |
| 143 | faim_export int aim_email_activate(aim_session_t *sess, aim_conn_t *conn) | |
| 144 | { | |
| 145 | aim_frame_t *fr; | |
| 146 | aim_snacid_t snacid; | |
| 147 | ||
| 148 | if (!sess || !conn) | |
| 149 | return -EINVAL; | |
| 150 | ||
| 151 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+16))) | |
| 152 | return -ENOMEM; | |
| 153 | snacid = aim_cachesnac(sess, 0x0018, 0x0016, 0x0000, NULL, 0); | |
| 154 | aim_putsnac(&fr->data, 0x0018, 0x0016, 0x0000, snacid); | |
| 155 | ||
| 156 | /* I would guess this tells AIM that you want updates for your mail accounts */ | |
| 157 | /* ...but I really have no idea */ | |
| 158 | aimbs_put8(&fr->data, 0x02); | |
| 159 | aimbs_put32(&fr->data, 0x04000000); | |
| 160 | aimbs_put32(&fr->data, 0x04000000); | |
| 161 | aimbs_put32(&fr->data, 0x04000000); | |
| 162 | aimbs_put32(&fr->data, 0x00000000); | |
| 163 | ||
| 164 | aim_tx_enqueue(sess, fr); | |
| 165 | ||
| 166 | return 0; | |
| 167 | } | |
| 168 | ||
| 169 | static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) | |
| 170 | { | |
| 171 | ||
| 172 | if (snac->subtype == 0x0007) | |
| 173 | return parseinfo(sess, mod, rx, snac, bs); | |
| 174 | ||
| 175 | return 0; | |
| 176 | } | |
| 177 | ||
| 178 | static void email_shutdown(aim_session_t *sess, aim_module_t *mod) | |
| 179 | { | |
|
7045
458b55091f8b
[gaim-migrate @ 7608]
Mark Doliner <markdoliner@pidgin.im>
parents:
7011
diff
changeset
|
180 | while (sess->emailinfo) { |
|
458b55091f8b
[gaim-migrate @ 7608]
Mark Doliner <markdoliner@pidgin.im>
parents:
7011
diff
changeset
|
181 | struct aim_emailinfo *tmp = sess->emailinfo; |
|
458b55091f8b
[gaim-migrate @ 7608]
Mark Doliner <markdoliner@pidgin.im>
parents:
7011
diff
changeset
|
182 | sess->emailinfo = sess->emailinfo->next; |
|
3952
d13e1fde68d8
[gaim-migrate @ 4133]
Mark Doliner <markdoliner@pidgin.im>
parents:
3725
diff
changeset
|
183 | free(tmp->cookie16); |
|
d13e1fde68d8
[gaim-migrate @ 4133]
Mark Doliner <markdoliner@pidgin.im>
parents:
3725
diff
changeset
|
184 | free(tmp->cookie8); |
|
d13e1fde68d8
[gaim-migrate @ 4133]
Mark Doliner <markdoliner@pidgin.im>
parents:
3725
diff
changeset
|
185 | free(tmp->url); |
|
d13e1fde68d8
[gaim-migrate @ 4133]
Mark Doliner <markdoliner@pidgin.im>
parents:
3725
diff
changeset
|
186 | free(tmp->domain); |
| 3694 | 187 | free(tmp); |
| 188 | } | |
| 189 | ||
| 190 | return; | |
| 191 | } | |
| 192 | ||
| 193 | faim_internal int email_modfirst(aim_session_t *sess, aim_module_t *mod) | |
| 194 | { | |
| 195 | ||
| 196 | mod->family = 0x0018; | |
| 197 | mod->version = 0x0001; | |
| 198 | mod->toolid = 0x0010; | |
| 199 | mod->toolversion = 0x0629; | |
| 200 | mod->flags = 0; | |
| 201 | strncpy(mod->name, "email", sizeof(mod->name)); | |
| 202 | mod->snachandler = snachandler; | |
| 203 | mod->shutdown = email_shutdown; | |
| 204 | ||
| 205 | return 0; | |
| 206 | } |