src/irc_chan.h
changeset 72 43084f103c2a
parent 69 6f298b6e0d5f
child 74 11ec458d1cbf
equal deleted inserted replaced
71:0a13030f795d 72:43084f103c2a
     8  */
     8  */
     9 struct irc_chan_info;
     9 struct irc_chan_info;
    10 struct irc_chan;
    10 struct irc_chan;
    11 
    11 
    12 #include "irc_net.h"
    12 #include "irc_net.h"
       
    13 #include "irc_user.h"
    13 #include "irc_cmd.h"
    14 #include "irc_cmd.h"
    14 #include "irc_proto.h"
    15 #include "irc_proto.h"
    15 #include "error.h"
    16 #include "error.h"
    16 #include <sys/queue.h>
    17 #include <sys/queue.h>
    17 
    18 
    31  */
    32  */
    32 struct irc_chan_callbacks {
    33 struct irc_chan_callbacks {
    33     /** Joined the channel */
    34     /** Joined the channel */
    34     void (*on_self_join) (struct irc_chan *chan, void *arg);
    35     void (*on_self_join) (struct irc_chan *chan, void *arg);
    35 
    36 
       
    37     /** Someone joined the channel */
       
    38     void (*on_join) (struct irc_chan *chan, const struct irc_nm *source, void *arg);
       
    39 
    36     /** Someone sent a message to the channel */
    40     /** Someone sent a message to the channel */
    37     void (*on_msg) (struct irc_chan *chan, const struct irc_nm *source, const char *msg, void *arg);
    41     void (*on_msg) (struct irc_chan *chan, const struct irc_nm *source, const char *msg, void *arg);
    38 };
    42 };
    39 
    43 
    40 /**
    44 /**
    51                 callbacks->_cb_name_((chan), ## __VA_ARGS__, head->arg);    \
    55                 callbacks->_cb_name_((chan), ## __VA_ARGS__, head->arg);    \
    52         }                                                       \
    56         }                                                       \
    53     } while (0);
    57     } while (0);
    54 
    58 
    55 /**
    59 /**
       
    60  * Per-channel-user state
       
    61  */
       
    62 struct irc_chan_user {
       
    63     /** The per-network user info */
       
    64     struct irc_user *user;
       
    65 
       
    66     /** The irc_chan list */
       
    67     LIST_ENTRY(irc_chan_user) chan_users;
       
    68 };
       
    69 
       
    70 /**
    56  * IRC channel state
    71  * IRC channel state
    57  */
    72  */
    58 struct irc_chan {
    73 struct irc_chan {
    59     /** The irc_net.channels list */
    74     /** The irc_net.channels list */
    60     TAILQ_ENTRY(irc_chan) node;
    75     TAILQ_ENTRY(irc_chan) node;
    63     struct irc_net *net;
    78     struct irc_net *net;
    64 
    79 
    65     /** Our identifying info */
    80     /** Our identifying info */
    66     struct irc_chan_info info;
    81     struct irc_chan_info info;
    67     
    82     
    68     /** State flags @{ */
    83     /** 
    69         /** JOIN request sent, waiting for reply */
    84      * @group State flags 
    70         bool joining;
    85      * @{ 
       
    86      */
    71 
    87 
    72         /** Currently joined to channel */
    88     /** JOIN request sent, waiting for reply */
    73         bool joined;
    89     bool joining;
       
    90 
       
    91     /** Currently joined to channel */
       
    92     bool joined;
    74 
    93 
    75     // @}
    94     // @}
       
    95     
       
    96     /** List of users on channel */
       
    97     LIST_HEAD(irc_chan_users_list, irc_chan_user) users;
    76     
    98     
    77     /** General command handlers */
    99     /** General command handlers */
    78     irc_cmd_handlers_t handlers;
   100     irc_cmd_handlers_t handlers;
    79 
   101 
    80     /** High-level user callbacks */
   102     /** High-level user callbacks */
   112  * Remove high-level irc_chan callbacks.
   134  * Remove high-level irc_chan callbacks.
   113  */
   135  */
   114 void irc_chan_remove_callbacks (struct irc_chan *chan, const struct irc_chan_callbacks *callbacks, void *arg);
   136 void irc_chan_remove_callbacks (struct irc_chan *chan, const struct irc_chan_callbacks *callbacks, void *arg);
   115 
   137 
   116 /**
   138 /**
       
   139  * Look up an irc_chan_user struct by nickname for this channel, returning NULL if no such chan_user exists.
       
   140  *
       
   141  * @param chan the channel context
       
   142  * @param nickname the user's current nickname
       
   143  * @param return the irc_chan_user state, or NULL if nickname not found
       
   144  */
       
   145 struct irc_chan_user* irc_chan_get_user (struct irc_chan *chan, const char *nickname);
       
   146 
       
   147 /**
   117  * Send the initial JOIN message.
   148  * Send the initial JOIN message.
   118  *
   149  *
   119  * The channel must be in the IRC_CHAN_INIT state, and will transition to the IRC_CHAN_JOINING state.
   150  * The channel must be in the IRC_CHAN_INIT state, and will transition to the IRC_CHAN_JOINING state.
   120  *
   151  *
   121  * @param chan the channel to JOIN
   152  * @param chan the channel to JOIN