Пример #1
0
/* -------------------------------------------------------- */
BOT* ircBOT_new	(const char *nick, const char *pwd) {
    /* -------------------------------------------------------- */
    int x = 0;
    BOT *bot 	= (BOT*) CALLOC(1, sizeof(BOT));
    if(bot) {
        if(!nick)
            ERROR_EXIT("ircBOT_new: Error no NICK!!!\n");
        bot->nick 			= strdup(nick);
        if(pwd)
            bot->pwd 		= strdup(pwd);
        else
            bot->pwd 		= NULL;
        bot->srv.state 		= IRC_SYS_NEEDCONNECT;
        bot->srv.sendbuf	= NULL;
        bot->cmd_handler 	= LIST_new();
        bot->tee_handler 	= LIST_new();
        for(x=0; x<MAX_TIMER; x++)
            bot->timer[x].id = -1;
    }
    /* add this bot to the global ones */
    if(!all_bots)
        all_bots = LIST_new();
    if(!LIST_add(all_bots, bot))
        ERROR_EXIT("ircBOT_new: Error adding bot to global BOT-List!!\n");
    DEBUG("BOT with nick '%s' created.\n", bot->nick);
    return bot;
};
Пример #2
0
/* -------------------------------------------------------- */
int ircBOT_join	(BOT *me, const char *channel) {
    /* -------------------------------------------------------- */
    CHAN *chan 	= CALLOC(1,sizeof(CHAN));
    chan->name 	= strdup(channel);
    LIST_add(me->srv.channels, chan);

    MSG_out(me, NULL, irc_build_msg(NULL, "JOIN", channel, NULL));
    return IRC_OK;
}
Пример #3
0
/* -------------------------------------------------------- */
int irc_add_tee	(BOT *me, int event_type, TEE_FUN *fun) {
    /* -------------------------------------------------------- */
    tee_tab * tt 	= (tee_tab*) CALLOC(1, sizeof(tee_tab));
    tt->event_type 	= event_type;
    tt->fun 		= fun;
    if( ! LIST_add(me->tee_handler, tt) ) {
        ERROR("irc_add_tee: Error adding fun off event_type '%i'!\n", event_type);
        return IRC_ERROR;
    }
    return IRC_OK;
};
Пример #4
0
/* -------------------------------------------------------- */
MSG* MSG_out(BOT *me, MSG * mymsg, char * raw_msg) {
    /* -------------------------------------------------------- */
    MSG * msg = mymsg;
    if( !msg )
        msg = MSG_new(me);
    msg->raw_msg = raw_msg;
    if(!me->srv.sendbuf)
        me->srv.sendbuf = LIST_new();
    LIST_add(me->srv.sendbuf, msg);
    return msg;
}
Пример #5
0
/* -------------------------------------------------------- */
int irc_add_cmd	(BOT *me, const char *cmd, cmd_property prop, int min_user_level, CMD_FUN *fun) {
    /* -------------------------------------------------------- */
    cmd_tab * ct = (cmd_tab*) CALLOC(1,sizeof(cmd_tab));
    ct->cmd 			= strdup(cmd);
    ct->min_user_level 	= min_user_level;
    ct->property 		= prop;
    ct->fun 			= fun;
    if( ! LIST_add(me->cmd_handler, ct) ) {
        ERROR("irc_add_cmd: Error adding command '%s' to LIST.\n", cmd);
        return IRC_ERROR;
    }
    return IRC_OK;
};
Пример #6
0
/* -------------------------------------------------------- */
USER* irc_sys_find_user_or_add	(BOT *me, USER *this_user) {
    /* -------------------------------------------------------- */
    LIST *l = me->srv.users;
    USER *user = NULL;
    if(!this_user) {
        ERROR("irc_sys_find_user_or_add: NO 'this_user' in Parameter\n");
        return NULL;
    }
    while( (user = LIST_next(l)) ) {
        if(	strcmp(SICHER_STR(this_user->name), 	SICHER_STR(user->name)) == 0 &&
                strcmp(SICHER_STR(this_user->host_user),SICHER_STR(user->host_user)) == 0 &&
                strcmp(SICHER_STR(this_user->host), 	SICHER_STR(user->host)) == 0
          )
            return user;
    }
    if(!me->srv.users)
        me->srv.users = LIST_new();
    LIST_add(me->srv.users, this_user);
    return NULL;
};
Пример #7
0
void sub_music_browse()
{
    int items_added = 0;
    struct stat statbuf;
    struct dirent **namelist;
    int files = scandir(music_path, &namelist, 0, alphasort);
    unsigned int typeloop = 0, i = 0;
    if (files < 0)
    {
        perror("scandir");
        return;
    }

    /* Loop twice 1 = directories, 2 = files ... should sort as well */
    for (typeloop = 0; typeloop < 2; typeloop++)
        for (i = 0; i < files; i++)
        {
            if (strcmp(namelist[i]->d_name, ".")
                && strcmp(namelist[i]->d_name, ".."))
            {
                char *tpath = (char *) calloc(1, 1024);
                char subtitle[64];
                SDL_Surface *icon = NULL, *typeicon = NULL;

                memset(&subtitle, 0, sizeof(subtitle));

                sprintf(tpath, "%s/%s", music_path, namelist[i]->d_name);
                stat(tpath, &statbuf);

                if (S_ISDIR(statbuf.st_mode) && typeloop == 0)
                {
                    icon = gfx_load_image("images/icons/folder.png", 0);
                    LIST_add(icon, typeicon, namelist[i]->d_name, NULL,
                             tpath);
                    items_added++;
                }
                else if (S_ISREG(statbuf.st_mode) && typeloop == 1)
                {
                    char *ext = sub_music_ext(namelist[i]->d_name);
                    if (ext)
                    {
                        char extimg_path[1024];
                        char *stmp = NULL;
                        char martist[1024], mtitle[1024];
                        memset(martist, 0, sizeof(martist));
                        memset(mtitle, 0, sizeof(mtitle));


                        stmp = op_metainfo(tpath, OVMARTIST);
                        if (stmp)
                            strncpy(martist, stmp, sizeof(martist) - 1);
                        stmp = op_metainfo(tpath, OVMTITLE);
                        if (stmp)
                            strncpy(mtitle, stmp, sizeof(mtitle) - 1);

                        memset(&extimg_path, 0, sizeof(extimg_path));

                        namelist[i]->d_name[strlen(namelist[i]->d_name) -
                                            strlen(ext)] = '\0';
                        ext =
                            &(namelist[i]->
                              d_name[strlen(namelist[i]->d_name) + 1]);

                        sprintf(extimg_path, "images/icons/%s.png", ext);
                        typeicon = gfx_load_image(extimg_path, 0);

                        icon =
                            gfx_load_image("images/icons/media_num.png",
                                           1);
                        if (!martist[0])
                            martist[0] = '-';

                        if (!mtitle[0])
                            strncpy(mtitle, namelist[i]->d_name,
                                    sizeof(mtitle) - 1);

                        LIST_add(gfx_clone_surface(icon), typeicon, mtitle, martist, tpath);
                        items_added++;
                    }
                }
            }

            if (typeloop)
                free(namelist[i]);
        }

    free(namelist);

    if (!items_added)
    {
        LIST_setEmptyMsg("There are no tracks.");
    }
    else if (LIST_getSelected())
    {
        LIST_setEmptyMsg(NULL);
    }

    return;
}
Пример #8
0
Bus* BUS_list_add(Bus* bus_list, Bus* bus_new) {
  LIST_add(Bus,bus_list,bus_new,next);
  return bus_list;
}
Пример #9
0
/* -------------------------------------------------------- */
int irc_sys_state_maschine(BOT *me) {
    /* -------------------------------------------------------- */
    BOT *this 	= me;
    int i = 0, bufsize = MAX_MSG;
    MSG *msg 	= NULL;
    LIST* out_list	= this->srv.sendbuf;
    while( this->srv.state != IRC_SYS_IDLE ) {
        switch( this->srv.state ) {
        case IRC_SYS_READ_EVENT:
            msg = MSG_new(this);
            msg->raw_msg = CALLOC(1, MAX_MSG);
            this->srv.state = IRC_SYS_READ;
            break;
        case IRC_SYS_WRITE_EVENT:
            if( this->srv.sendbuf )
                this->srv.state = IRC_SYS_WRITE;
            else
                this->srv.state = IRC_SYS_IDLE; /* nix zum schreiben, daher retour */
            break;
        case IRC_SYS_READ:
            /* only read a line */
            while ( (recv(this->srv.socket, &msg->raw_msg[i], 1, 0) == 1) ) {
                if (msg->raw_msg[i] == '\n' || bufsize == i + 1) {
                    msg->raw_msg[i] = '\0';
                    break;
                }
                if (msg->raw_msg[i] == '\r')
                    msg->raw_msg[i] = '\0';
                i++;
            }
            /* if a line exist */
            if( i > 0 ) {
                LIST_add(this->srv.history, msg);
                irc_sys_parse_msg(this, msg);

                fprintf(stdout, "%s\n", msg->raw_msg);
                printf("-------------------------------------\n");
                this->srv.state = IRC_SYS_TEELOOP;
            }
            else {
                DEBUG("nix gelesen ????\n");
                free(msg->raw_msg);
                free(msg);
                this->srv.state = IRC_SYS_IDLE;
                //if( i < 0 )
                ERROR_EXIT("Error recv: '%s'\n", strerror(errno));
            }
            break;
        case IRC_SYS_WRITE:
            if( (msg = LIST_next( out_list )) ) {
                send(this->srv.socket, msg->raw_msg, strlen(msg->raw_msg), 0);
                DEBUG("---------->message written:%s", msg->raw_msg);
                LIST_add(this->srv.history, msg);
                LIST_del(this->srv.sendbuf, msg);
                this->srv.state = IRC_SYS_TEELOOP;
            }
            else if( this->srv.sendbuf ) {
                free( this->srv.sendbuf );
                this->srv.sendbuf = NULL;
                this->srv.state = IRC_SYS_IDLE;
            }
            break;
        case IRC_SYS_TEELOOP:
            /* TODO: implement TEELOOP */
            this->srv.state = IRC_SYS_CMDLOOP;
            break;
        case IRC_SYS_CMDLOOP:
            irc_sys_cmd_loop(this, msg);
            this->srv.state = IRC_SYS_IDLE;
            break;
        default:
            return IRC_ERROR;
        }
    }
    return IRC_ERROR;
}
Пример #10
0
Gen* GEN_list_reg_add(Gen* reg_gen_list, Gen* reg_gen) {
  LIST_add(reg_gen_list,reg_gen,reg_next);
  return reg_gen_list;
}
Пример #11
0
Gen* GEN_list_add(Gen *gen_list, Gen* gen) {
  LIST_add(gen_list,gen,next);
  return gen_list;
}