2 * libyahoo2: yahoo2_callbacks.h
4 * Copyright (C) 2002-2004, Philip S Tellis <philip.tellis AT gmx.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * The functions in this file *must* be defined in your client program
24 * If you want to use a callback structure instead of direct functions,
25 * then you must define USE_STRUCT_CALLBACKS in all files that #include
28 * Register the callback structure by calling yahoo_register_callbacks -
29 * declared in this file and defined in libyahoo2.c
32 #ifndef YAHOO2_CALLBACKS_H
33 #define YAHOO2_CALLBACKS_H
39 #include "yahoo2_types.h"
44 * Callback interface for libyahoo2
48 YAHOO_INPUT_READ
= 1 << 0,
49 YAHOO_INPUT_WRITE
= 1 << 1,
50 YAHOO_INPUT_EXCEPTION
= 1 << 2
51 } yahoo_input_condition
;
54 * A callback function called when an asynchronous connect completes.
57 * fd - The file descriptor object that has been connected, or NULL on
59 * error - The value of errno set by the call to connect or 0 if no error
60 * Set both fd and error to 0 if the connect was cancelled by the
62 * callback_data - the callback_data passed to the ext_yahoo_connect_async
65 typedef void (*yahoo_connect_callback
) (void *fd
, int error
,
69 * The following functions need to be implemented in the client
70 * interface. They will be called by the library when each
75 * should we use a callback structure or directly call functions
76 * if you want the structure, you *must* define USE_STRUCT_CALLBACKS
77 * both when you compile the library, and when you compile your code
78 * that uses the library
81 #define YAHOO_CALLBACK_TYPE(x) (*x)
82 struct yahoo_callbacks
{
85 * Name: ext_yahoo_login_response
86 * Called when the login process is complete
88 * id - the id that identifies the server connection
89 * succ - enum yahoo_login_status
90 * url - url to reactivate account if locked
92 void YAHOO_CALLBACK_TYPE(ext_yahoo_login_response
) (int id
, int succ
,
96 * Name: ext_yahoo_got_buddies
97 * Called when the contact list is got from the server
99 * id - the id that identifies the server connection
100 * buds - the buddy list
102 void YAHOO_CALLBACK_TYPE(ext_yahoo_got_buddies
) (int id
, YList
*buds
);
105 * Name: ext_yahoo_got_ignore
106 * Called when the ignore list is got from the server
108 * id - the id that identifies the server connection
109 * igns - the ignore list
111 void YAHOO_CALLBACK_TYPE(ext_yahoo_got_ignore
) (int id
, YList
*igns
);
114 * Name: ext_yahoo_got_identities
115 * Called when the contact list is got from the server
117 * id - the id that identifies the server connection
118 * ids - the identity list
120 void YAHOO_CALLBACK_TYPE(ext_yahoo_got_identities
) (int id
, YList
*ids
);
123 * Name: ext_yahoo_got_cookies
124 * Called when the cookie list is got from the server
126 * id - the id that identifies the server connection
128 void YAHOO_CALLBACK_TYPE(ext_yahoo_got_cookies
) (int id
);
131 * Name: ext_yahoo_got_ping
132 * Called when the ping packet is received from the server
134 * id - the id that identifies the server connection
135 * errormsg - optional error message
137 void YAHOO_CALLBACK_TYPE(ext_yahoo_got_ping
) (int id
,
138 const char *errormsg
);
141 * Name: ext_yahoo_status_changed
142 * Called when remote user's status changes.
144 * id - the id that identifies the server connection
145 * who - the handle of the remote user
146 * stat - status code (enum yahoo_status)
147 * msg - the message if stat == YAHOO_STATUS_CUSTOM
148 * away - whether the contact is away or not (YAHOO_STATUS_CUSTOM)
149 * idle - this is the number of seconds he is idle [if he is idle]
150 * mobile - this is set for mobile users/buddies
151 * TODO: add support for pager, chat, and game states
153 void YAHOO_CALLBACK_TYPE(ext_yahoo_status_changed
) (int id
,
154 const char *who
, int stat
, const char *msg
, int away
, int idle
,
158 * Name: ext_yahoo_got_buzz
159 * Called when remote user sends you a buzz.
161 * id - the id that identifies the server connection
162 * me - the identity the message was sent to
163 * who - the handle of the remote user
164 * tm - timestamp of message if offline
166 void YAHOO_CALLBACK_TYPE(ext_yahoo_got_buzz
) (int id
, const char *me
,
167 const char *who
, long tm
);
170 * Name: ext_yahoo_got_im
171 * Called when remote user sends you a message.
173 * id - the id that identifies the server connection
174 * me - the identity the message was sent to
175 * who - the handle of the remote user
176 * msg - the message - NULL if stat == 2
177 * tm - timestamp of message if offline
178 * stat - message status - 0
180 * 2 == error sending message
182 * utf8 - whether the message is encoded as utf8 or not
184 void YAHOO_CALLBACK_TYPE(ext_yahoo_got_im
) (int id
, const char *me
,
185 const char *who
, const char *msg
, long tm
, int stat
, int utf8
);
188 * Name: ext_yahoo_got_conf_invite
189 * Called when remote user sends you a conference invitation.
191 * id - the id that identifies the server connection
192 * me - the identity the invitation was sent to
193 * who - the user inviting you
194 * room - the room to join
196 * members - the initial members of the conference (null terminated list)
198 void YAHOO_CALLBACK_TYPE(ext_yahoo_got_conf_invite
) (int id
,
199 const char *me
, const char *who
, const char *room
,
200 const char *msg
, YList
*members
);
203 * Name: ext_yahoo_conf_userdecline
204 * Called when someone declines to join the conference.
206 * id - the id that identifies the server connection
207 * me - the identity in the conference
208 * who - the user who has declined
210 * msg - the declining message
212 void YAHOO_CALLBACK_TYPE(ext_yahoo_conf_userdecline
) (int id
,
213 const char *me
, const char *who
, const char *room
,
217 * Name: ext_yahoo_conf_userjoin
218 * Called when someone joins the conference.
220 * id - the id that identifies the server connection
221 * me - the identity in the conference
222 * who - the user who has joined
223 * room - the room joined
225 void YAHOO_CALLBACK_TYPE(ext_yahoo_conf_userjoin
) (int id
,
226 const char *me
, const char *who
, const char *room
);
229 * Name: ext_yahoo_conf_userleave
230 * Called when someone leaves the conference.
232 * id - the id that identifies the server connection
233 * me - the identity in the conference
234 * who - the user who has left
235 * room - the room left
237 void YAHOO_CALLBACK_TYPE(ext_yahoo_conf_userleave
) (int id
,
238 const char *me
, const char *who
, const char *room
);
241 * Name: ext_yahoo_chat_cat_xml
244 * id - the id that identifies the server connection
247 void YAHOO_CALLBACK_TYPE(ext_yahoo_chat_cat_xml
) (int id
,
251 * Name: ext_yahoo_chat_join
252 * Called when joining the chatroom.
254 * id - the id that identifies the server connection
255 * me - the identity in the chatroom
256 * room - the room joined, used in all other chat calls, freed by
258 * topic - the topic of the room, freed by library after call
259 * members - the initial members of the chatroom (null terminated YList
260 * of yahoo_chat_member's) Must be freed by the client
261 * fd - the object where the connection is coming from (for tracking)
263 void YAHOO_CALLBACK_TYPE(ext_yahoo_chat_join
) (int id
, const char *me
,
264 const char *room
, const char *topic
, YList
*members
, void *fd
);
267 * Name: ext_yahoo_chat_userjoin
268 * Called when someone joins the chatroom.
270 * id - the id that identifies the server connection
271 * me - the identity in the chatroom
272 * room - the room joined
273 * who - the user who has joined, Must be freed by the client
275 void YAHOO_CALLBACK_TYPE(ext_yahoo_chat_userjoin
) (int id
,
276 const char *me
, const char *room
,
277 struct yahoo_chat_member
*who
);
280 * Name: ext_yahoo_chat_userleave
281 * Called when someone leaves the chatroom.
283 * id - the id that identifies the server connection
284 * me - the identity in the chatroom
285 * room - the room left
286 * who - the user who has left (Just the User ID)
288 void YAHOO_CALLBACK_TYPE(ext_yahoo_chat_userleave
) (int id
,
289 const char *me
, const char *room
, const char *who
);
292 * Name: ext_yahoo_chat_message
293 * Called when someone messages in the chatroom.
295 * id - the id that identifies the server connection
296 * me - the identity in the chatroom
298 * who - the user who messaged (Just the user id)
300 * msgtype - 1 = Normal message
301 * 2 = /me type message
302 * utf8 - whether the message is utf8 encoded or not
304 void YAHOO_CALLBACK_TYPE(ext_yahoo_chat_message
) (int id
,
305 const char *me
, const char *who
, const char *room
,
306 const char *msg
, int msgtype
, int utf8
);
310 * Name: ext_yahoo_chat_yahoologout
311 * called when yahoo disconnects your chat session
312 * Note this is called whenver a disconnect happens, client or server
313 * requested. Care should be taken to make sure you know the origin
314 * of the disconnect request before doing anything here (auto-join's etc)
316 * id - the id that identifies this connection
317 * me - the identity in the chatroom
321 void YAHOO_CALLBACK_TYPE(ext_yahoo_chat_yahoologout
) (int id
,
326 * Name: ext_yahoo_chat_yahooerror
327 * called when yahoo sends back an error to you
328 * Note this is called whenver chat message is sent into a room
329 * in error (fd not connected, room doesn't exists etc)
330 * Care should be taken to make sure you know the origin
331 * of the error before doing anything about it.
333 * id - the id that identifies this connection
334 * me - the identity in the chatroom
338 void YAHOO_CALLBACK_TYPE(ext_yahoo_chat_yahooerror
) (int id
,
342 * Name: ext_yahoo_conf_message
343 * Called when someone messages in the conference.
345 * id - the id that identifies the server connection
346 * me - the identity the conf message was sent to
347 * who - the user who messaged
350 * utf8 - whether the message is utf8 encoded or not
352 void YAHOO_CALLBACK_TYPE(ext_yahoo_conf_message
) (int id
,
353 const char *me
, const char *who
, const char *room
,
354 const char *msg
, int utf8
);
357 * Name: ext_yahoo_got_file
358 * Called when someone sends you a file
360 * id - the id that identifies the server connection
361 * me - the identity the file was sent to
362 * who - the user who sent the file
364 * fname- the file name if direct transfer
365 * fsize- the file size if direct transfer
366 * trid - transfer id. Unique for this transfer
368 * NOTE: Subsequent callbacks for file transfer do not send all of this
369 * information again since it is wasteful. Implementations are expected to
370 * save this information and supply it as callback data when the file or
371 * confirmation is sent
373 void YAHOO_CALLBACK_TYPE(ext_yahoo_got_file
) (int id
, const char *me
,
374 const char *who
, const char *msg
, const char *fname
,
375 unsigned long fesize
, char *trid
);
378 * Name: ext_yahoo_got_ft_data
379 * Called multiple times when parts of the file are received
381 * id - the id that identifies the server connection
383 * len - Length of the data
384 * data - callback data
386 void YAHOO_CALLBACK_TYPE(ext_yahoo_got_ft_data
) (int id
,
387 const unsigned char *in
, int len
, void *data
);
390 * Name: ext_yahoo_file_transfer_done
391 * File transfer is done
393 * id - the id that identifies the server connection
394 * result - To notify if it finished successfully or with a failure
395 * data - callback data
397 void YAHOO_CALLBACK_TYPE(ext_yahoo_file_transfer_done
) (int id
,
398 int result
, void *data
);
401 * Name: ext_yahoo_contact_added
402 * Called when a contact is added to your list
404 * id - the id that identifies the server connection
405 * myid - the identity he was added to
406 * who - who was added
407 * msg - any message sent
409 void YAHOO_CALLBACK_TYPE(ext_yahoo_contact_added
) (int id
,
410 const char *myid
, const char *who
, const char *msg
);
413 * Name: ext_yahoo_rejected
414 * Called when a contact rejects your add
416 * id - the id that identifies the server connection
417 * who - who rejected you
418 * msg - any message sent
420 void YAHOO_CALLBACK_TYPE(ext_yahoo_rejected
) (int id
, const char *who
,
424 * Name: ext_yahoo_typing_notify
425 * Called when remote user starts or stops typing.
427 * id - the id that identifies the server connection
428 * me - the handle of the identity the notification is sent to
429 * who - the handle of the remote user
430 * stat - 1 if typing, 0 if stopped typing
432 void YAHOO_CALLBACK_TYPE(ext_yahoo_typing_notify
) (int id
,
433 const char *me
, const char *who
, int stat
);
436 * Name: ext_yahoo_game_notify
437 * Called when remote user starts or stops a game.
439 * id - the id that identifies the server connection
440 * me - the handle of the identity the notification is sent to
441 * who - the handle of the remote user
442 * stat - 1 if game, 0 if stopped gaming
443 * msg - game description and/or other text
445 void YAHOO_CALLBACK_TYPE(ext_yahoo_game_notify
) (int id
, const char *me
,
446 const char *who
, int stat
, const char *msg
);
449 * Name: ext_yahoo_mail_notify
450 * Called when you receive mail, or with number of messages
452 * id - the id that identifies the server connection
453 * from - who the mail is from - NULL if only mail count
454 * subj - the subject of the mail - NULL if only mail count
455 * cnt - mail count - 0 if new mail notification
457 void YAHOO_CALLBACK_TYPE(ext_yahoo_mail_notify
) (int id
,
458 const char *from
, const char *subj
, int cnt
);
461 * Name: ext_yahoo_system_message
464 * id - the id that identifies the server connection
465 * me - the handle of the identity the notification is sent to
466 * who - the source of the system message (there are different types)
469 void YAHOO_CALLBACK_TYPE(ext_yahoo_system_message
) (int id
,
470 const char *me
, const char *who
, const char *msg
);
473 * Name: ext_yahoo_got_buddyicon
474 * Buddy icon received
476 * id - the id that identifies the server connection
477 * me - the handle of the identity the notification is sent to
478 * who - the person the buddy icon is for
479 * url - the url to use to load the icon
480 * checksum - the checksum of the icon content
482 void YAHOO_CALLBACK_TYPE(ext_yahoo_got_buddyicon
) (int id
,
483 const char *me
, const char *who
, const char *url
, int checksum
);
486 * Name: ext_yahoo_got_buddyicon_checksum
487 * Buddy icon checksum received
489 * id - the id that identifies the server connection
490 * me - the handle of the identity the notification is sent to
491 * who - the yahoo id of the buddy icon checksum is for
492 * checksum - the checksum of the icon content
494 void YAHOO_CALLBACK_TYPE(ext_yahoo_got_buddyicon_checksum
) (int id
,
495 const char *me
, const char *who
, int checksum
);
498 * Name: ext_yahoo_got_buddyicon_request
499 * Buddy icon request received
501 * id - the id that identifies the server connection
502 * me - the handle of the identity the notification is sent to
503 * who - the yahoo id of the buddy that requested the buddy icon
505 void YAHOO_CALLBACK_TYPE(ext_yahoo_got_buddyicon_request
) (int id
,
506 const char *me
, const char *who
);
509 * Name: ext_yahoo_got_buddyicon_request
510 * Buddy icon request received
512 * id - the id that identifies the server connection
513 * url - remote url, the uploaded buddy icon can be fetched from
515 void YAHOO_CALLBACK_TYPE(ext_yahoo_buddyicon_uploaded
) (int id
,
519 * Name: ext_yahoo_got_webcam_image
520 * Called when you get a webcam update
521 * An update can either be receiving an image, a part of an image or
522 * just an update with a timestamp
524 * id - the id that identifies the server connection
525 * who - the user who's webcam we're viewing
527 * image_size - length of the image in bytes
528 * real_size - actual length of image data
529 * timestamp - milliseconds since the webcam started
531 * If the real_size is smaller then the image_size then only part of
532 * the image has been read. This function will keep being called till
533 * the total amount of bytes in image_size has been read. The image
534 * received is in JPEG-2000 Code Stream Syntax (ISO/IEC 15444-1).
535 * The size of the image will be either 160x120 or 320x240.
536 * Each webcam image contains a timestamp. This timestamp should be
537 * used to keep the image in sync since some images can take longer
538 * to transport then others. When image_size is 0 we can still receive
539 * a timestamp to stay in sync
541 void YAHOO_CALLBACK_TYPE(ext_yahoo_got_webcam_image
) (int id
,
542 const char *who
, const unsigned char *image
,
543 unsigned int image_size
, unsigned int real_size
,
544 unsigned int timestamp
);
547 * Name: ext_yahoo_webcam_invite
548 * Called when you get a webcam invitation
550 * id - the id that identifies the server connection
551 * me - identity the invitation is to
552 * from - who the invitation is from
554 void YAHOO_CALLBACK_TYPE(ext_yahoo_webcam_invite
) (int id
,
555 const char *me
, const char *from
);
558 * Name: ext_yahoo_webcam_invite_reply
559 * Called when you get a response to a webcam invitation
561 * id - the id that identifies the server connection
562 * me - identity the invitation response is to
563 * from - who the invitation response is from
564 * accept - 0 (decline), 1 (accept)
566 void YAHOO_CALLBACK_TYPE(ext_yahoo_webcam_invite_reply
) (int id
,
567 const char *me
, const char *from
, int accept
);
570 * Name: ext_yahoo_webcam_closed
571 * Called when the webcam connection closed
573 * id - the id that identifies the server connection
574 * who - the user who we where connected to
575 * reason - reason why the connection closed
576 * 1 = user stopped broadcasting
577 * 2 = user cancelled viewing permission
578 * 3 = user declines permission
579 * 4 = user does not have webcam online
581 void YAHOO_CALLBACK_TYPE(ext_yahoo_webcam_closed
) (int id
,
582 const char *who
, int reason
);
585 * Name: ext_yahoo_got_search_result
586 * Called when the search result received from server
588 * id - the id that identifies the server connection
589 * found - total number of results returned in the current result set
590 * start - offset from where the current result set starts
591 * total - total number of results available (start + found <= total)
592 * contacts - the list of results as a YList of yahoo_found_contact
593 * these will be freed after this function returns, so
594 * if you need to use the information, make a copy
596 void YAHOO_CALLBACK_TYPE(ext_yahoo_got_search_result
) (int id
,
597 int found
, int start
, int total
, YList
*contacts
);
600 * Name: ext_yahoo_error
603 * id - the id that identifies the server connection
604 * err - the error message
605 * fatal- whether this error is fatal to the connection or not
606 * num - Which error is this
608 void YAHOO_CALLBACK_TYPE(ext_yahoo_error
) (int id
, const char *err
,
612 * Name: ext_yahoo_webcam_viewer
613 * Called when a viewer disconnects/connects/requests to connect
615 * id - the id that identifies the server connection
617 * connect - 0=disconnect 1=connect 2=request
619 void YAHOO_CALLBACK_TYPE(ext_yahoo_webcam_viewer
) (int id
,
620 const char *who
, int connect
);
623 * Name: ext_yahoo_webcam_data_request
624 * Called when you get a request for webcam images
626 * id - the id that identifies the server connection
627 * send - whether to send images or not
629 void YAHOO_CALLBACK_TYPE(ext_yahoo_webcam_data_request
) (int id
,
633 * Name: ext_yahoo_log
634 * Called to log a message.
636 * fmt - the printf formatted message
640 int YAHOO_CALLBACK_TYPE(ext_yahoo_log
) (const char *fmt
, ...);
643 * Name: ext_yahoo_add_handler
644 * Add a listener for the fd. Must call yahoo_read_ready
645 * when a YAHOO_INPUT_READ fd is ready and yahoo_write_ready
646 * when a YAHOO_INPUT_WRITE fd is ready.
648 * id - the id that identifies the server connection
649 * fd - the fd object on which to listen
650 * cond - the condition on which to call the callback
651 * data - callback data to pass to yahoo_*_ready
653 * Returns: a tag to be used when removing the handler
655 int YAHOO_CALLBACK_TYPE(ext_yahoo_add_handler
) (int id
, void *fd
,
656 yahoo_input_condition cond
, void *data
);
659 * Name: ext_yahoo_remove_handler
660 * Remove the listener for the fd.
662 * id - the id that identifies the connection
663 * tag - the handler tag to remove
665 void YAHOO_CALLBACK_TYPE(ext_yahoo_remove_handler
) (int id
, int tag
);
668 * Name: ext_yahoo_connect
669 * Connect to a host:port
671 * host - the host to connect to
672 * port - the port to connect on
674 * a unix file descriptor to the socket
676 int YAHOO_CALLBACK_TYPE(ext_yahoo_connect
) (const char *host
, int port
);
679 * Name: ext_yahoo_connect_async
680 * Connect to a host:port asynchronously. This function should return
681 * immediately returing a tag used to identify the connection handler,
682 * or a pre-connect error (eg: host name lookup failure).
683 * Once the connect completes (successfully or unsuccessfully), callback
684 * should be called (see the signature for yahoo_connect_callback).
685 * The callback may safely be called before this function returns, but
686 * it should not be called twice.
688 * id - the id that identifies this connection
689 * host - the host to connect to
690 * port - the port to connect on
691 * callback - function to call when connect completes
692 * callback_data - data to pass to the callback function
693 * use_ssl - Whether we need an SSL connection
695 * a tag signifying the connection attempt
697 int YAHOO_CALLBACK_TYPE(ext_yahoo_connect_async
) (int id
,
698 const char *host
, int port
, yahoo_connect_callback callback
,
699 void *callback_data
, int use_ssl
);
702 * Name: ext_yahoo_get_ip_addr
703 * get IP Address for a domain name
705 * domain - Domain name
707 * Newly allocated string containing the IP Address in IPv4 notation
709 char *YAHOO_CALLBACK_TYPE(ext_yahoo_get_ip_addr
) (const char *domain
);
712 * Name: ext_yahoo_write
713 * Write data from the buffer into the socket for the specified connection
715 * fd - the file descriptor object that identifies this connection
716 * buf - Buffer to write the data from
717 * len - Length of the data
719 * Number of bytes written or -1 for error
721 int YAHOO_CALLBACK_TYPE(ext_yahoo_write
) (void *fd
, char *buf
, int len
);
724 * Name: ext_yahoo_read
725 * Read data into a buffer from socket for the specified connection
727 * fd - the file descriptor object that identifies this connection
728 * buf - Buffer to read the data into
729 * len - Max length to read
731 * Number of bytes read or -1 for error
733 int YAHOO_CALLBACK_TYPE(ext_yahoo_read
) (void *fd
, char *buf
, int len
);
736 * Name: ext_yahoo_close
737 * Close the file descriptor object and free its resources. Libyahoo2 will not
738 * use this object again.
740 * fd - the file descriptor object that identifies this connection
744 void YAHOO_CALLBACK_TYPE(ext_yahoo_close
) (void *fd
);
747 * Name: ext_yahoo_got_buddy_change_group
748 * Acknowledgement of buddy changing group
753 * old_group: Old group name
754 * new_group: New group name
758 void YAHOO_CALLBACK_TYPE(ext_yahoo_got_buddy_change_group
) (int id
,
759 const char *me
, const char *who
, const char *old_group
,
760 const char *new_group
);
765 * if using a callback structure, call yahoo_register_callbacks
766 * before doing anything else
768 void yahoo_register_callbacks(struct yahoo_callbacks
*tyc
);
770 #undef YAHOO_CALLBACK_TYPE