/** Set mode for a feature. * * @pre feature_set_ initialized for this camera * * @param finfo pointer to information for this feature * @param mode DC1394 mode desired * @return true if mode set successfully */ bool Features::setMode(dc1394feature_info_t *finfo, dc1394feature_mode_t mode) { dc1394feature_t feature = finfo->id; if (hasMode(finfo, mode)) { // first, make sure the feature is powered on setPower(finfo, DC1394_ON); ROS_DEBUG_STREAM("setting feature " << featureName(feature) << " mode to " << modeName(mode)); if (DC1394_SUCCESS != dc1394_feature_set_mode(camera_, feature, mode)) { ROS_WARN_STREAM("failed to set feature " << featureName(feature) << " mode to " << modeName(mode)); return false; } } else { // device does not support this mode for this feature ROS_DEBUG_STREAM("no " << modeName(mode) << " mode for feature " << featureName(feature)); return false; } return true; }
void handle_NAMES(char **params, int socket){ char msgbuf[512]; char * chanName; channel * chan; userInChannel * currUIC; char smallbuf[25]; if(params[1] == NULL) { //RPL_NAMREPLY for everything pthread_mutex_lock(&chanListLock); if(list_iterator_start(&channelList) == 0) { printf("Error iterating the list.\n"); return; } while(list_iterator_hasnext(&channelList)) { chan = (channel *)list_iterator_next(&channelList); sprintf(msgbuf, ":%s 353 = %s :", host, chan->name); pthread_mutex_lock(&(chan->UICListLock)); if(list_iterator_start(&(chan->userInChannelList)) == 0) { printf("Error iterating the list.\n"); return; } while(list_iterator_hasnext(&(chan->userInChannelList))) { currUIC = (userInChannel *)list_iterator_next(&chan->userInChannelList); if(hasMode(currUIC->userChanModes, 'O')) { sprintf(smallbuf, "@%s", (currUIC->user)->nick); strcat(msgbuf, smallbuf); } else if(hasMode(currUIC->userChanModes, 'v')) { sprintf(smallbuf, "+%s", (currUIC->user)->nick); strcat(msgbuf, smallbuf); } else { sprintf(smallbuf, "+%s", (currUIC->user)->nick); strcat(msgbuf, smallbuf); } } if(list_iterator_stop(&(chan->userInChannelList)) == 0) { printf("Error iterating the list.\n"); return; } pthread_mutex_unlock(&(chan->UICListLock)); sendMessage(msgbuf, socket); sprintf(msgbuf, ":%s 366 %s :End of NAMES list", host, chan->name); sendMessage(msgbuf, socket); } if(list_iterator_stop(&(channelList)) == 0) { printf("Error iterating the list.\n"); return; } pthread_mutex_unlock(&chanListLock); } else { //RPLY_NAMREPLY for the channel chanName = params[1]; chan = (channel *) findChannel(chanName); sprintf(msgbuf, ":%s 353 = %s :", host, chan->name); pthread_mutex_lock(&(chan->UICListLock)); if(list_iterator_start(&(chan->userInChannelList)) == 0) { printf("Error iterating the list.\n"); return; } while(list_iterator_hasnext(&(chan->userInChannelList))) { currUIC = (userInChannel *)list_iterator_next(&chan->userInChannelList); if(hasMode(currUIC->userChanModes, 'O')) { sprintf(smallbuf, "@%s", (currUIC->user)->nick); strcat(msgbuf, smallbuf); } else if(hasMode(currUIC->userChanModes, 'v')) { sprintf(smallbuf, "+%s", (currUIC->user)->nick); strcat(msgbuf, smallbuf); } else { sprintf(smallbuf, "+%s", (currUIC->user)->nick); strcat(msgbuf, smallbuf); } } if(list_iterator_stop(&(chan->userInChannelList)) == 0) { printf("Error iterating the list.\n"); return; } pthread_mutex_unlock(&(chan->UICListLock)); sendMessage(msgbuf, socket); sprintf(msgbuf, ":%s 366 %s :End of NAMES list", host, chan->name); sendMessage(msgbuf, socket); } }
void handle_MODE(char **params, int socket) { //only should really care about -o for user and channel stuff char * NickorChan = params[1]; char msgbuf[512]; pthread_mutex_lock(&listLock); struct ClientData * ourCli = (struct ClientData *)list_seek(&clientList, &socket); pthread_mutex_unlock(&listLock); if(ourCli == NULL) { printf("Failing on list seek.\n"); } char * name = ourCli->nick; char * user = ourCli->user; if(NickorChan[0] == '#') { //channel MODE command or member status MODE command channel * theChan = findChannel(NickorChan); if(theChan==NULL) { //not a channel sprintf(msgbuf, ":%s 403 %s %s :No such channel\r\n", host, name, NickorChan); sendMessage(msgbuf, socket); return; } if(params[2]==NULL) { //no mode- print out our modes sprintf(msgbuf, ":%s 324 %s %s +%s\r\n", host, name, NickorChan, theChan->chanModes); sendMessage(msgbuf, socket); } else { //we have a mode, but dont know if channel or user status char * modeStr = params[2]; char PoM = modeStr[0]; char mode = modeStr[1]; //CHECK IF CHANOP OR SERVEROP int position = isUserInChannel(socket, theChan); pthread_mutex_lock(&(theChan->UICListLock)); userInChannel * theUIC = list_get_at(&(theChan->userInChannelList), position); pthread_mutex_unlock(&(theChan->UICListLock)); int hasCOp = hasMode(theUIC->userChanModes, 'O'); int hasSOp = hasMode(ourCli->userModes, 'o'); if(params[3]==NULL) { // Just a channel command if( (mode != 'm') & (mode != 't') ) { sprintf(msgbuf, ":%s 472 %s %c :is unknown mode char to me for %s\r\n", host, name, mode, theChan->name); sendMessage(msgbuf, socket); return; } if(hasCOp || hasSOp) { //case tree on if we set or delete the mode if(PoM == '-') { removeMode(theChan->chanModes, mode); } else {//PoM == '+' setMode(theChan->chanModes, mode); } sprintf(msgbuf, ":%s!%[email protected] MODE %s %c%c\r\n", name, user, NickorChan, PoM, mode); messageAllUsers(msgbuf, theChan, socket); sendMessage(msgbuf, socket); return; } else {//not an op sprintf(msgbuf, ":%s 482 %s %s :You're not channel operator\r\n", host, name, theChan->name); sendMessage(msgbuf, socket); return; } } else { //It's a member status command char * dude = params[3]; if( (mode != 'v') & (mode != 'o') ) { sprintf(msgbuf, ":%s 472 %s %c :is unknown mode char to me for %s\r\n", host, name, mode, theChan->name); sendMessage(msgbuf, socket); return; } else { // valid mode, check if operator if(hasCOp || hasSOp) { //case tree on if we set or delete the mode //check if dude exists and is in the channel struct ClientData * userDude = findUser(dude, &clientList); if(userDude == NULL){ printf("We just don't find the user in our server.\n"); sprintf(msgbuf, ":%s 441 %s %s %s :They aren't on that channel\r\n", host, name, dude, theChan->name); sendMessage(msgbuf, socket); return; } int dudePos = isUserInChannel(userDude->ourSocket, theChan); if(dudePos == -1) { printf("We don't find the user in the channel.\n"); sprintf(msgbuf, ":%s 441 %s %s %s :They aren't on that channel\r\n", host, name, dude, theChan->name); sendMessage(msgbuf, socket); return; } else { //wow, dude's actually in the channel way to go! pthread_mutex_lock(&(theChan->UICListLock)); userInChannel * dudeUIC = list_get_at(&theChan->userInChannelList, dudePos); pthread_mutex_unlock(&(theChan->UICListLock)); if(PoM == '-') { removeMode(dudeUIC->userChanModes, mode); } else {//PoM == '+' setMode(dudeUIC->userChanModes, mode); } //messageAllUsers(the message that came in, theChan); would we strcat on params or what? return; } } else {//not an op sprintf(msgbuf, ":%s 482 %s %s :You're not channel operator\r\n", host, name, theChan->name); sendMessage(msgbuf, socket); return; } } } } } else { //NickorChan is a user, user MODE command if(strcmp(NickorChan, ourCli->nick) != 0) { sprintf(msgbuf, ":%s 502 %s :Cannot change mode for other users\r\n", host, name); sendMessage(msgbuf, socket); return; } if(params[2]==NULL) { //no mode- print out our modes -> apparently should be the no such channel thing? /*sprintf(msgbuf, ":%s MODE %s :%c%c\r\n", NickorChan, NickorChan, PoM, mode); sendMessage(msgbuf, socket);*/ sprintf(msgbuf, ":%s 403 %s %s :No such channel\r\n", host, name, NickorChan); sendMessage(msgbuf, socket); return; } else { //we have a mode char * modeStr = params[2]; char PoM = modeStr[0]; char mode = modeStr[1]; if(mode == 'o') { //if PoM == +, ignore it must use OPER if (PoM == '-') { removeMode(ourCli->userModes, mode); sprintf(msgbuf, ":%s!%[email protected] MODE %s :%c%c\r\n", user, name, name, PoM, mode); sendMessage(msgbuf, socket); } return; } else if (mode == 'a') { return; }//ignore it completely only AWAY works else { sprintf(msgbuf, ":%s 501 %s :Unknown MODE flag\r\n", host, name); sendMessage(msgbuf, socket); return; } } } printf("Apparently there's a mode I don't deal with?\n"); }