예제 #1
0
std::istream* FTPStreamFactory::open(const URI& uri)
{
	poco_assert (uri.getScheme() == "ftp");

	FTPClientSession* pSession = new FTPClientSession(uri.getHost(), uri.getPort());
	try
	{
		std::string username;
		std::string password;
		getUserInfo(uri, username, password);
		
		std::string path;
		char        type;
		getPathAndType(uri, path, type);
			
		pSession->login(username, password);
		if (type == 'a')
			pSession->setFileType(FTPClientSession::TYPE_TEXT);
			
		Path p(path, Path::PATH_UNIX);
		p.makeFile();
		for (int i = 0; i < p.depth(); ++i)
			pSession->setWorkingDirectory(p[i]);
		std::string file(p.getFileName());
		std::istream& istr = (type == 'd' ? pSession->beginList(file) : pSession->beginDownload(file));
		return new FTPStream(istr, pSession);
	}
	catch (...)
	{
		delete pSession;
		throw;
	}
}
예제 #2
0
// Takes care of all the choices the user can
// make with the menu.
void LogIn::menuChoices()
{
	switch(choice)
	{
	case 1:
		createAccount();
		cout << endl;
		mainMenu();
		break;
	case 2:
		getUserInfo();
		cout << endl;
		mainMenu();
		break;
	case 3: 
		deleteQuery();
		deleteAccount();
		break;
	case 4:
		displayContents();
		mainMenu();
		break;
	case 9:
		cout << "You have exitted the program.\n";
		exit(EXIT_SUCCESS);
	}
}
예제 #3
0
void Channel::setTopic(Client *setter, char *str) {
	chanClient *info;
	chanClient tinfo;
	char *nick;
	bool set=true;
	memset(&tinfo,0,sizeof(tinfo));
	bool operoverride=false;
	if(setter->getRights()&OPERPRIVS_OPEROVERRIDE) operoverride=true;
	if(setter->getRights()&OPERPRIVS_GLOBALOWNER)  operoverride=true;
	if(!this->topic_protect) operoverride = true;
	info = getUserInfo(setter);
	if(info == NULL) info = &tinfo;
	if(!operoverride) {
		if(!info->halfop && !info->op && !info->owner) {
			if((this->onlyowner == 1 && !info->owner) || this->onlyowner == 0) {
				sendNotEnoughPrivs(ENotEnough_HALFOP,setter,"Set Topic");
				return;
			}
		}
	}
	memset(&this->topic,0,sizeof(this->topic));
	memset(&this->topicsetter,0,sizeof(this->topicsetter));
	strncpy(this->topic,str,strlen(str)%sizeof(this->topic));
	sendMessage(false,false,setter,"TOPIC %s :%s",getName(),this->topic);
	setter->getUserInfo(&nick,NULL,NULL,NULL);
	strcpy(this->topicsetter,nick);
	this->topictime = time(NULL);
}
예제 #4
0
// Is called if either the username or password does 
// not match any in the system.
void LogIn::errorMessage()
{
	cout << "The username/password could not be found in the system.\n";
	cout << "Try again\n";
	system("pause");
	system("cls");			
	getUserInfo();
}
예제 #5
0
파일: upload.cpp 프로젝트: mtboswell/syncer
Upload::Upload(QWidget* parent):QWizard(parent){
	setupUi(this);

	rsh = new RemoteShellRunner();

	if(!getUserInfo()) this->reject();

}
예제 #6
0
파일: netMgr.cpp 프로젝트: roger912/breeze
bool NetMgr::sendToUser(UserID uID, const char * block, unsigned int len)
{
    auto user = getUserInfo(uID);
    if (user && user->sID != InvalidSessionID)
    {
        SessionManager::getRef().sendSessionData(user->sID, block, len);
        return true;
    }
    return false;
}
예제 #7
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    getQuestionInfo();
    getAnswerInfo();
    getUserInfo();
    return a.exec();
}
예제 #8
0
파일: netMgr.cpp 프로젝트: roger912/breeze
void NetMgr::msg_onAttachLogicReq(TcpSessionPtr session, ReadStream & rs)
{
    if (std::get<TupleParamNumber>(session->getUserParam(UPARAM_SESSION_STATUS)) != SSTATUS_UNKNOW)
    {
        return;
    }
    
    AttachLogicAck ack;
    ack.retCode = EC_SUCCESS;
    AttachLogicReq req;
    rs >> req;
    LOGD("enter msg_loginReq token=" << req.token << ", uID=" << req.uID);
    do 
    {
        auto info = getUserInfo(req.uID);
        if (!info)
        {
            ack.retCode = EC_TARGET_NOT_EXIST;
            break;
        }
        if (info->token.token != req.token)
        {
            ack.retCode = EC_PERMISSION_DENIED;
            break;
        }
        if (info->token.expire < time(NULL))
        {
            ack.retCode = EC_REQUEST_EXPIRE;
            break;
        }

        if (info->sID != InvalidSessionID)
        {
            event_onLogout(info);
            SessionManager::getRef().kickSession(info->sID);
            _mapSession.erase(info->sID);
        }

        info->sID = session->getSessionID();
        session->setUserParam(UPARAM_USER_ID, info->base.uID);
        session->setUserParam(UPARAM_SESSION_STATUS, SSTATUS_LOGINED);
        session->setUserParam(UPARAM_LAST_ACTIVE_TIME, time(NULL));
        session->setUserParam(UPARAM_LOGIN_TIME, time(NULL));
        _mapSession.insert(std::make_pair(session->getSessionID(), info));

        sendMessage(session, ack);
        session->setUserParam(UPARAM_LAST_ACTIVE_TIME, time(NULL));

        event_onLogin(info);
        
        return;
    } while (0);
    
    sendMessage(session, ack);
}
예제 #9
0
파일: netMgr.cpp 프로젝트: roger912/breeze
void NetMgr::msg_onSelectUserReq(TcpSessionPtr session, ReadStream & rs)
{
    if (session->getUserParamNumber(UPARAM_SESSION_STATUS) != SSTATUS_PLAT_LOGINED)
    {
        LOGE("NetMgr::msg_onSelectUserReq. status error. session id=" << session->getSessionID() << ", status = " << session->getUserParamNumber(UPARAM_SESSION_STATUS));
        session->close();
        return;
    }

    auto founder = _mapAccounts.find(session->getUserParamString(UPARAM_ACCOUNT));
    if (founder == _mapAccounts.end())
    {
        LOGW("Login::msg_onSelectUserReq session have no account info. sID=" << session->getSessionID());
        return;
    }

    SelectUserReq req;
    rs >> req;

    auto base = founder->second.find(req.uID);
    if (base == founder->second.end())
    {
        LOGW("Login::msg_onSelectUserReq session have no user info. sID=" << session->getSessionID());
        return;
    }


    MD5Data data;
    data.append(base->second.account);
    data.append(base->second.nickName);
    data.append(toString(rand()));

    //模拟通知logic刷新token
    auto ptr = getUserInfo(req.uID);
    if (!ptr)
    {
        return;
    }
    ptr->token.uID = req.uID;
    ptr->token.token = data.genMD5();
    ptr->token.expire = (unsigned int)time(NULL) + 600;

    //模拟断开连接
    session->setUserParam(UPARAM_SESSION_STATUS, SSTATUS_UNKNOW);


    SelectUserAck ack;
    ack.retCode = EC_SUCCESS;
    ack.uID = req.uID;
    ack.token = data.genMD5();
    ack.ip = ServerConfig::getRef().getConfigListen(LogicServer)._wip;
    ack.port = ServerConfig::getRef().getConfigListen(LogicServer)._wport;

    sendMessage(session, ack);
}
예제 #10
0
/**
  * This slot function open users dialog.
  */
void MainWindow::openUsersDialog()
{
    if(!usersDialog)
        usersDialog = new UsersDialog;

    connect(usersDialog, SIGNAL(getUserInfo(QString)), this, SLOT(requestGetUserInfo(QString)));
    //connect(usersDialog, SIGNAL(getUsers()), this, SLOT(requestGetUsers()));
    requestGetUsers();
    connect(usersDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
    usersDialog->show();
}
예제 #11
0
// update file transfer data
void
FileTransferServer::updateData() {

  std::string clientMachineName;
  std::string userId;

  getUserInfo(clientMachineName, userId);

  mfileTransfer.setTransferId( vishnu::getObjectId(vishnu::FILETRANSFERT, clientMachineName) );
  mfileTransfer.setClientMachineId(clientMachineName);
  mfileTransfer.setUserId(userId);
}
예제 #12
0
Player::Player(const GenericSocket &sock, int id) : myid(id)
{
    myrelay = new Analyzer(sock, id);
    lockCount = 0;
    battleSearch() = false;
    myip = relay().ip();
    rating() = -1;
    waiting_team = NULL;
    server_pass_sent = false;

    m_state = NotLoggedIn;
    myauth = 0;

    connect(&relay(), SIGNAL(disconnected()), SLOT(disconnected()));
    connect(&relay(), SIGNAL(loggedIn(TeamInfo&,bool,bool,QColor)), SLOT(loggedIn(TeamInfo&,bool,bool,QColor)));
    connect(&relay(), SIGNAL(serverPasswordSent(const QString&)), SLOT(serverPasswordSent(const QString&)));
    connect(&relay(), SIGNAL(messageReceived(int, QString)), SLOT(recvMessage(int, QString)));
    connect(&relay(), SIGNAL(teamReceived(TeamInfo&)), SLOT(recvTeam(TeamInfo&)));
    connect(&relay(), SIGNAL(challengeStuff(ChallengeInfo)), SLOT(challengeStuff(ChallengeInfo)));
    connect(&relay(), SIGNAL(forfeitBattle(int)), SLOT(battleForfeited(int)));
    connect(&relay(), SIGNAL(battleMessage(int,BattleChoice)), SLOT(battleMessage(int,BattleChoice)));
    connect(&relay(), SIGNAL(battleChat(int,QString)), SLOT(battleChat(int,QString)));
    connect(&relay(), SIGNAL(sentHash(QString)), SLOT(hashReceived(QString)));
    connect(&relay(), SIGNAL(wannaRegister()), SLOT(registerRequest()));
    connect(&relay(), SIGNAL(kick(int)), SLOT(playerKick(int)));
    connect(&relay(), SIGNAL(ban(int)), SLOT(playerBan(int)));
    connect(&relay(), SIGNAL(banRequested(QString)), SLOT(CPBan(QString)));
    connect(&relay(), SIGNAL(tempBanRequested(QString,int)), SLOT(CPTBan(QString,int)));
    connect(&relay(), SIGNAL(unbanRequested(QString)), SLOT(CPUnban(QString)));
    connect(&relay(), SIGNAL(PMsent(int,QString)), SLOT(receivePM(int,QString)));
    connect(&relay(), SIGNAL(getUserInfo(QString)), SLOT(userInfoAsked(QString)));
    connect(&relay(), SIGNAL(tbanListRequested()), SLOT(giveTBanList()));
    connect(&relay(), SIGNAL(banListRequested()), SLOT(giveBanList()));
    connect(&relay(), SIGNAL(awayChange(bool)), SLOT(awayChange(bool)));
    connect(&relay(), SIGNAL(battleSpectateRequested(int)), SLOT(spectatingRequested(int)));
    connect(&relay(), SIGNAL(battleSpectateEnded(int)), SLOT(quitSpectating(int)));
    connect(&relay(), SIGNAL(battleSpectateChat(int,QString)), SLOT(spectatingChat(int,QString)));
    connect(&relay(), SIGNAL(ladderChange(bool)), SLOT(ladderChange(bool)));
    connect(&relay(), SIGNAL(showTeamChange(bool)), SLOT(showTeamChange(bool)));
    connect(&relay(), SIGNAL(tierChanged(QString)), SLOT(changeTier(QString)));
    connect(&relay(), SIGNAL(findBattle(FindBattleData)), SLOT(findBattle(FindBattleData)));
    connect(&relay(), SIGNAL(showRankings(QString,int)), SLOT(getRankingsByPage(QString, int)));
    connect(&relay(), SIGNAL(showRankings(QString,QString)), SLOT(getRankingsByName(QString, QString)));
    connect(&relay(), SIGNAL(joinRequested(QString)), SLOT(joinRequested(QString)));
    connect(&relay(), SIGNAL(leaveChannel(int)), SLOT(leaveRequested(int)));
    connect(&relay(), SIGNAL(ipChangeRequested(QString)), SLOT(ipChangeRequested(QString)));
    /* To avoid threading / simulateneous calls problems, it's queued */
    connect(this, SIGNAL(unlocked()), &relay(), SLOT(undelay()),Qt::QueuedConnection);

    /* Autokick after 3 minutes if still not logged in */
    QTimer::singleShot(1000*180, this, SLOT(autoKick()));
}
예제 #13
0
파일: main.c 프로젝트: ecs0/lab1ex2.c
int main() {
    char fullname[100];
    char msg[99];
    //version 1, using strcpy and strcat
    int lucky = getUserInfo(fullname);
    printf("%s's lucky number is %d.\n", fullname, lucky);
    //version 2, using sprintf, strlen and memcpy
    lucky = getUserInfo2(fullname);
    sprintf(msg, "%s's lucky number is %d.\n", fullname, lucky);
    puts(msg);

    return 0;
}
예제 #14
0
void PreferencesDialog::on_button_login_clicked()
{
    if(!loggedIn)
    {
        LoginDialog loginDialog(this);
        if(loginDialog.exec() == QDialog::Accepted)
        {
            //Refresh after login
            loadSettings();
            setupUi();
            getUserInfo();
        }
    }
}
예제 #15
0
void FbTalker::parseResponseListFriends(const QByteArray& data)
{
    int errCode = -1;
    QString errMsg;
    QDomDocument doc("getFriends");
    if (!doc.setContent(data))
        return;

    kDebug() << "Parse Friends response:" << endl << data;

    QDomElement docElem = doc.documentElement();
    QString friendsUIDs;
    if (docElem.tagName() == "friends_get_response")
    {
        for (QDomNode node = docElem.firstChild();
             !node.isNull();
             node = node.nextSibling())
        {
            if (!node.isElement())
                continue;
            if (node.nodeName() == "uid")
            {
                if (!friendsUIDs.isEmpty())
                    friendsUIDs.append(',');
                friendsUIDs.append(node.toElement().text());
            }
        }
        errCode = 0;
    }
    else if (docElem.tagName() == "error_response")
    {
        errCode = parseErrorResponse(docElem, errMsg);
    }

    if (friendsUIDs.isEmpty())
    {
        emit signalBusy(false);

        QList<FbUser> noFriends;
        emit signalListFriendsDone(errCode, errorToText(errCode, errMsg),
                                   noFriends);
    }
    else
    {
        // get user info for those users
        getUserInfo(friendsUIDs);
    }
}
예제 #16
0
int storageUsers(int(*$)(user_info*,void*arg),void*arg){
	FILE *f=fopen(files.users,"rt");
	user_info u;
	if (f){
		while(feof(f)==0){
			memset(&u,0,sizeof(u));
			if (getUserInfo(f, &u)==2){
				$(&u, arg);
			}
		}
		fclose(f);
		return 0;
	}
	perror("fopen");
	return 1;
}
예제 #17
0
void Player::doConnections()
{
    /* The reason for Queued Connection is that for example a disconnect signal could be received when
      a script sends a message to the client.

      If that happens we want the disconnect signal to happen after the script function*/
    connect(&relay(), SIGNAL(disconnected()), SLOT(disconnected()), Qt::QueuedConnection);
    connect(&relay(), SIGNAL(loggedIn(LoginInfo*)), SLOT(loggedIn(LoginInfo*)));
    connect(&relay(), SIGNAL(logout()), SLOT(logout()));
    connect(&relay(), SIGNAL(serverPasswordSent(const QByteArray&)), SLOT(serverPasswordSent(const QByteArray&)));
    connect(&relay(), SIGNAL(messageReceived(int, QString)), SLOT(recvMessage(int, QString)));
    connect(&relay(), SIGNAL(playerDataRequested(int)), SLOT(recvPlayerDataRequest(int)));
    connect(&relay(), SIGNAL(teamChanged(const ChangeTeamInfo&)), SLOT(recvTeam(const ChangeTeamInfo&)));
    connect(&relay(), SIGNAL(challengeStuff(ChallengeInfo)), SLOT(challengeStuff(ChallengeInfo)));
    connect(&relay(), SIGNAL(forfeitBattle(int)), SLOT(battleForfeited(int)));
    connect(&relay(), SIGNAL(battleMessage(int,BattleChoice)), SLOT(battleMessage(int,BattleChoice)));
    connect(&relay(), SIGNAL(battleChat(int,QString)), SLOT(battleChat(int,QString)));
    connect(&relay(), SIGNAL(sentHash(QByteArray)), SLOT(hashReceived(QByteArray)));
    connect(&relay(), SIGNAL(wannaRegister()), SLOT(registerRequest()));
    connect(&relay(), SIGNAL(kick(int)), SLOT(playerKick(int)));
    connect(&relay(), SIGNAL(ban(int)), SLOT(playerBan(int)));
    connect(&relay(), SIGNAL(tempBan(int,int)), SLOT(playerTempBan(int,int)));
    connect(&relay(), SIGNAL(banRequested(QString,int)), SLOT(CPBan(QString,int)));
    connect(&relay(), SIGNAL(unbanRequested(QString)), SLOT(CPUnban(QString)));
    connect(&relay(), SIGNAL(PMsent(int,QString)), SLOT(receivePM(int,QString)));
    connect(&relay(), SIGNAL(getUserInfo(QString)), SLOT(userInfoAsked(QString)));
    connect(&relay(), SIGNAL(banListRequested()), SLOT(giveBanList()));
    connect(&relay(), SIGNAL(awayChange(bool)), SLOT(awayChange(bool)));
    connect(&relay(), SIGNAL(battleSpectateRequested(int)), SLOT(spectatingRequested(int)));
    connect(&relay(), SIGNAL(battleSpectateEnded(int)), SLOT(quitSpectating(int)));
    connect(&relay(), SIGNAL(battleSpectateChat(int,QString)), SLOT(spectatingChat(int,QString)));
    connect(&relay(), SIGNAL(ladderChange(bool)), SLOT(ladderChange(bool)));
    connect(&relay(), SIGNAL(tierChanged(quint8,QString)), SLOT(changeTier(quint8,QString)));
    connect(&relay(), SIGNAL(findBattle(FindBattleData)), SLOT(findBattle(FindBattleData)));
    connect(&relay(), SIGNAL(showRankings(QString,int)), SLOT(getRankingsByPage(QString, int)));
    connect(&relay(), SIGNAL(showRankings(QString,QString)), SLOT(getRankingsByName(QString, QString)));
    connect(&relay(), SIGNAL(showRankings(int)), SLOT(getRankingsForPlayer(int)));
    connect(&relay(), SIGNAL(joinRequested(QString)), SLOT(joinRequested(QString)));
    connect(&relay(), SIGNAL(leaveChannel(int)), SLOT(leaveRequested(int)));
    connect(&relay(), SIGNAL(ipChangeRequested(QString)), SLOT(ipChangeRequested(QString)));
    connect(&relay(), SIGNAL(endCommand()), SLOT(sendUpdatedIfNeeded()));
    connect(&relay(), SIGNAL(reconnect(int,QByteArray)), SLOT(onReconnect(int,QByteArray)));
    connect(&relay(), SIGNAL(showRankings(int)), SLOT(getRankingsForPlayer(int)));

    /* To avoid threading / simulateneous calls problems, it's queued */
    connect(this, SIGNAL(unlocked()), &relay(), SLOT(undelay()),Qt::QueuedConnection);
}
예제 #18
0
int storageUserById(int id, user_info* u){
	FILE *f=fopen(files.users,"rt");
	if (f){
		while(feof(f)==0){
			getUserInfo(f, u);
			if (u->id==id){
				printf("user with id %d found\n", id);
				break;
			}
		}
		fclose(f);
		if (u->id==id)
			return 0;
		printf("user with id %d not found\n", id);
		memset(u,0,sizeof(*u));
		return -1;
	}
	perror("fopen");
	return 1;
}
예제 #19
0
void FbTalker::parseResponseGetLoggedInUser(const QByteArray& data)
{
    int errCode = -1;
    QString errMsg;

    QDomDocument doc("getLoggedInUser");
    if (!doc.setContent(data))
        return;

    emit signalLoginProgress(4);

    kDebug() << "Parse GetLoggedInUser response:" << endl << data;

    QDomElement docElem = doc.documentElement();
    if (docElem.tagName() == "users_getLoggedInUser_response")
    {
        m_user.id = docElem.text().toLongLong();
        errCode   = 0;
    }
    else if (docElem.tagName() == "error_response")
        errCode = parseErrorResponse(docElem, errMsg);

    if (errCode == 0)
    {
        // session is still valid -> get full user info
        getUserInfo();
    }
    else
    {
        // it seems that session expired -> create new token and session
        m_accessToken.clear();
        m_sessionExpires = 0;
        m_user.clear();

        doOAuth();
    }
}
예제 #20
0
void Channel::setModes(Client *setter, char *modestr) {
	chanClient *info;
	chanClient tinfo;
	bool set=true;
	char tbuff[64];
	int modep=0;
	bool canVoice;
	char oldMode = this->auditorium;
	char *p=strchr(modestr,' ');
	if(p != NULL) *p++ = 0;
	memset(&tinfo,0,sizeof(tinfo));
	bool operoverride=false;
	char *tbuffptr;
	if(setter->getRights()&OPERPRIVS_OPEROVERRIDE) operoverride=true;
	//if(setter->getRights()&OPERPRIVS_GLOBALOWNER)  operoverride=true;
	info = getUserInfo(setter);
	if(info == NULL) info = &tinfo;
	if(info->owner) info->op = true;
	if(info->op) info->halfop = true;
	for(int i=0;i<strlen(modestr);i++) {
		switch(modestr[i]) {
		case '-':
			set = false;
			break;
		case '+':
			set = true;
			break;
		case 'e':
			if(info->halfop || operoverride && !(this->onlyowner == 1 && info->owner == false)) {
				if(this->mode_ops_obey_channel_limit == set) break;
				this->mode_ops_obey_channel_limit = set;
				sendMessage(false,false,setter,"MODE %s %s",getName(),set?"+e":"-e");
			}
			else sendNotEnoughPrivs(ENotEnough_HALFOP,setter,set?"set mode":"remove mode");
			break;
		case 'm':
			if(info->halfop || operoverride && !(this->onlyowner == 1 && info->owner == false)) {
				if(this->moderated == set) break;
				this->moderated = set;
				sendMessage(false,false,setter,"MODE %s %s",getName(),set?"+m":"-m");
			}
			else sendNotEnoughPrivs(ENotEnough_HALFOP,setter,set?"set mode":"remove mode");
			break;
		case 'n':
			if(info->halfop || operoverride && !(this->onlyowner == 1 && info->owner == false)) {
				if(this->nooutsidemsgs == set) break;
				this->nooutsidemsgs = set;
				sendMessage(false,false,setter,"MODE %s %s",getName(),set?"+n":"-n");
			}
			else sendNotEnoughPrivs(ENotEnough_HALFOP,setter,set?"set mode":"remove mode");
			break;
		case 'i':
			if(info->halfop || operoverride && !(this->onlyowner == 1 && info->owner == false)) {
				if(this->inviteonly == set) break;
				this->inviteonly = set;
				sendMessage(false,false,setter,"MODE %s %s",getName(),set?"+i":"-i");
			}
			else sendNotEnoughPrivs(ENotEnough_HALFOP,setter,set?"set mode":"remove mode");
			break;
		case 'l': //set channel limit
			if(info->halfop || operoverride && !(this->onlyowner == 1 && info->owner == false)) {
			int len = 0;
			if(set) {
				if(p == NULL) {
					info->client->send_numeric(461, "%c :Not enough parameters",modestr[i]);
					return;
				}
				find_nth(p,modep++,tbuff,sizeof(tbuff));
				if(strlen(tbuff)<1) return;
				len = atoi(tbuff);
				if(len < 1) return;
			}
			if(set) {
				sendMessage(false,false,setter,"MODE %s +l %d",getName(),len);
			} else {
				sendMessage(false,false,setter,"MODE %s -l",getName());
			}
			this->limit = len;
			} else sendNotEnoughPrivs(ENotEnough_HALFOP,setter,set?"set mode":"remove mode");
			break;
		case 'k': //set channel key
			if(info->halfop || operoverride && !(this->onlyowner == 1 && info->owner == false)) {
			if(set) {
				if(p == NULL) {
					info->client->send_numeric(461, "%c :Not enough parameters",modestr[i]);
					return;
				}
				find_nth(p,modep++,tbuff,sizeof(tbuff));
				if(strlen(tbuff)<1) return;
				sendMessage(false,false,setter,"MODE %s +k %s",getName(),tbuff);
				strcpy(key,tbuff);
			} else {
				sendMessage(false,false,setter,"MODE %s -k",getName());
				memset(key,0,sizeof(key));
			}
			} else sendNotEnoughPrivs(ENotEnough_HALFOP,setter,set?"set mode":"remove mode");
			break;
		case 't':
			if(info->halfop || operoverride && !(this->onlyowner == 1 && info->owner == false)) {
				if(this->topic_protect == set) break;
				this->topic_protect = set;
				sendMessage(false,false,setter,"MODE %s %s",getName(),set?"+t":"-t");
			}
			else sendNotEnoughPrivs(ENotEnough_HALFOP,setter,set?"set mode":"remove mode");
			break;
		case 'p':
			if(info->halfop || operoverride && !(this->onlyowner == 1 && info->owner == false)) {
				if(this->secret && set) {
					this->secret = false;
					sendMessage(false,false,setter,"MODE %s -s",getName());
				}
				if(this->priv == set) break;
				this->priv = set;
				sendMessage(false,false,setter,"MODE %s %s",getName(),set?"+p":"-p");
			}
			else sendNotEnoughPrivs(ENotEnough_HALFOP,setter,set?"set mode":"remove mode");
			break;
		case 's':
			if(info->halfop || operoverride && !(this->onlyowner == 1 && info->owner == false)) {
				if(this->priv && set) {
					this->priv = false;
					sendMessage(false,false,setter,"MODE %s -p",getName());
				}
				if(this->secret == set) break;
				this->secret = set;
				sendMessage(false,false,setter,"MODE %s %s",getName(),set?"+s":"-s");
			}
			else sendNotEnoughPrivs(ENotEnough_HALFOP,setter,set?"set mode":"remove mode");
			break;
		case 'q':
			if(info->halfop || operoverride && !(this->onlyowner == 1 && info->owner == false)) {
				if(set && this->auditorium == 2) {
					sendMessage(false,false,setter,"MODE %s %s",getName(),!set?"+u":"-u");	
				}
				if((set && this->auditorium == 1) || (!set && this->auditorium != 1)) break;
				this->auditorium = (set==true?1:0);
				sendMessage(false,false,setter,"MODE %s %s",getName(),set?"+q":"-q");
				auditoriumUpdate(oldMode);
			}
			else sendNotEnoughPrivs(ENotEnough_HALFOP,setter,set?"set mode":"remove mode");
			break;
		case 'u':
			if(info->halfop || operoverride && !(this->onlyowner == 1 && info->owner == false)) {
				if(set && this->auditorium == 1) {
					sendMessage(false,false,setter,"MODE %s %s",getName(),!set?"+q":"-q");	
				}
				if((set && this->auditorium == 2) || (!set && this->auditorium != 2)) break;
				this->auditorium = (set==true?2:0);
				sendMessage(false,false,setter,"MODE %s %s",getName(),set?"+u":"-u");
				auditoriumUpdate(oldMode);
			}
			else sendNotEnoughPrivs(ENotEnough_HALFOP,setter,set?"set mode":"remove mode");
			break;
		case 'o': //op someone
			if(info->owner || operoverride && !(this->onlyowner == 1 && info->owner == false)) {
			chanClient *tclient;
			Client *opclient;
			if(p == NULL) {
				info->client->send_numeric(461, "%c :Not enough parameters",modestr[i]);
				return;
			}
			find_nth(p,modep++,tbuff,sizeof(tbuff));
			if(strlen(tbuff)<1) return;
			opclient = find_user(tbuff);

			if(opclient != NULL) {
				tclient = this->getUserInfo(opclient);
				if(tclient != NULL) {
					if(tclient->op == set) break;
					sendMessage(false,false,setter,"MODE %s %s %s",getName(),set?"+o":"-o",tbuff);
					if(set == false) tclient->owner = set;
					tclient->op=set;
					tclient->halfop = set;
				} else {
					setter->send_numeric(401,"%s :No such nick/channel",tbuff);
					break;
				}
			} else {
					setter->send_numeric(401,"%s :No such nick/channel",tbuff);
					break;
				}
			} else {
				sendNotEnoughPrivs(ENotEnough_OWNER,setter,"change ops");
			}
			break;
		case 'v': //voice someone
			//checking isn't instant because you could be devoicing yourself
			chanClient *tclient;
			Client *opclient;
			if(p == NULL) {
				info->client->send_numeric(461, "%c :Not enough parameters",modestr[i]);
				return;
			}
			canVoice = info->halfop || info->op || info->owner || operoverride && (this->onlyowner != 1 || info->owner);
			find_nth(p,modep++,tbuff,sizeof(tbuff));
			if(strlen(tbuff)<1) return;
			opclient = find_user(tbuff);
			if(opclient != NULL) {
				tclient = this->getUserInfo(opclient);
				if(tclient != NULL) {
					if(!canVoice && (tclient->client != setter || set == true)) {
						sendNotEnoughPrivs(ENotEnough_HALFOP,setter,"change voice");
						break;
					}
					if(tclient->voice == set) break;
					sendMessage(false,false,setter,"MODE %s %s %s",getName(),set?"+v":"-v",tbuff);
					tclient->voice=set;
				} else {
					setter->send_numeric(401,"%s :No such nick/channel",tbuff);
					break;
				}
			} else {
					setter->send_numeric(401,"%s :No such nick/channel",tbuff);
					break;
			}
			break;
		case 'h': //halfop someone
			if(info->op || operoverride && !(this->onlyowner == 1 && info->owner == false)) {
			chanClient *tclient;
			Client *opclient;
			if(p == NULL) {
				info->client->send_numeric(461, "%c :Not enough parameters",modestr[i]);
				return;
			}
			find_nth(p,modep++,tbuff,sizeof(tbuff));
			if(strlen(tbuff)<1) return;
			opclient = find_user(tbuff);
			if(opclient != NULL) {
				tclient = this->getUserInfo(opclient);
				if(tclient != NULL) {
					if(tclient->halfop == set) break;
					if(tclient->op == true || tclient->owner == true && info->owner == false) break;
						sendMessage(false,false,setter,"MODE %s %s %s",getName(),set?"+o":"-o",tbuff);
						tclient->halfop = set;
				} else {
					setter->send_numeric(401,"%s :No such nick/channel",tbuff);
					break;
				}
			} else {
					setter->send_numeric(401,"%s :No such nick/channel",tbuff);
					break;
				}
			} else {
				sendNotEnoughPrivs(ENotEnough_OP,setter,"set halfop");
			}
			break;
		case 'O': //owner someone
			if(info->owner || operoverride && !(this->onlyowner == 1 && info->owner == false)) {
				chanClient *tclient;
				Client *opclient;
				if(p == NULL) {
					info->client->send_numeric(461, "%c :Not enough parameters",modestr[i]);
					return;
				}
				find_nth(p,modep++,tbuff,sizeof(tbuff));
				if(strlen(tbuff)<1) return;
				opclient = find_user(tbuff);
			if(opclient != NULL) {
				tclient = this->getUserInfo(opclient);
				if(tclient != NULL) {
					if(tclient->owner == set) break;
					sendMessage(false,false,setter,"MODE %s %s %s",getName(),set?"+o":"-o",tbuff);
					tclient->owner = set;
					tclient->op = set;
					tclient->halfop = set;
				} else {
					setter->send_numeric(401,"%s :No such nick/channel",tbuff);
					break;
				}
			} else {
					setter->send_numeric(401,"%s :No such nick/channel",tbuff);
					break;
				}
			} else {
				sendNotEnoughPrivs(ENotEnough_OWNER,setter,"change owner");
			}
			break;
		case 'b': //ban/unban someone
			if((info->halfop || operoverride && !(this->onlyowner == 1 && info->owner == false)) || p == NULL) {
				if(p == NULL) { //list bans
					std::list<userMode *>::iterator iterator=server.usermodes_list.begin();
					userMode *um;
					char *nick;
					info->client->getUserInfo(&nick,NULL,NULL,NULL);
					while(iterator != server.usermodes_list.end()) {
						um=*iterator;
							if(match(um->chanmask,getName()) == 0) {
								if(um->hostmask[0] != 0 && um->modeflags & EModeFlags_Ban)
									info->client->send_numeric(367,"%s *!*@%s %s@%s %d",getName(), um->hostmask, um->setbynick[0] == 0?"SERVER":um->setbynick,um->setbyhost[0] == 0||info->halfop==false?"*":um->setbyhost,um->setondate);
							}
						iterator++;
					}
					info->client->send_numeric(368,"%s :End of channel ban list",getName());
					break;
				}
				find_nth(p,modep++,tbuff,sizeof(tbuff));
				if(strlen(tbuff)<1) return;
				char setstr[128];
				memset(&setstr,0, sizeof(setstr));
				tbuffptr = (char *)&tbuff;
				if(strchr(tbuffptr,'@') != NULL) tbuffptr = strchr(tbuffptr,'@')+1;
				sprintf(setstr,"\\hostmask\\%s\\modeflags\\b\\comment\\Banned by MODE command (Persist)",tbuffptr);
				if(set) {
					addUserMode(info->client,this->getName(),setstr);
				} else {
					userMode *usermode = findRemoveableUsermode(getName(),tbuff,EModeFlags_Ban,setter->getRights()&OPERPRIVS_GLOBALOWNER);
					if(usermode != NULL) {
						removeUsermode(usermode);
					}
				}
				//tbuff = ban name
			} else {
				sendNotEnoughPrivs(ENotEnough_HALFOP,setter,"set mode");
			}
			break;
		case 'I': //invite/uninvite someone
			if((info->halfop || operoverride && !(this->onlyowner == 1 && info->owner == false)) || p == NULL) {
				if(p == NULL) { //list bans
					std::list<userMode *>::iterator iterator=server.usermodes_list.begin();
					userMode *um;
					char *nick;
					info->client->getUserInfo(&nick,NULL,NULL,NULL);
					while(iterator != server.usermodes_list.end()) {
						um=*iterator;
							if(match(um->chanmask,getName())) {
								if(um->hostmask[0] != 0 && um->modeflags & EModeFlags_Invited)
									info->client->send_numeric(367,"%s *!*@%s %s@%s %d",getName(), um->hostmask, um->setbynick[0] == 0?"SERVER":um->setbynick,um->setbyhost[0] == 0||info->halfop==false?"*":um->setbyhost,um->setondate);
							}
						iterator++;
					}
					info->client->send_numeric(368,"%s :End of channel invite list",getName());
					break;
				}
				find_nth(p,modep++,tbuff,sizeof(tbuff));
				if(strlen(tbuff)<1) return;
				char setstr[128];
				memset(&setstr,0, sizeof(setstr));
				tbuffptr = (char *)&tbuff;
				if(strchr(tbuffptr,'@') != NULL) tbuffptr = strchr(tbuffptr,'@')+1;
				sprintf(setstr,"\\hostmask\\%s\\modeflags\\I\\comment\\Invited by MODE command (Persist)",tbuffptr);
				if(set) {
					addUserMode(info->client,this->getName(),setstr);
				} else {
					userMode *usermode = findRemoveableUsermode(getName(),tbuff,EModeFlags_Invited,setter->getRights()&OPERPRIVS_GLOBALOWNER);
					if(usermode != NULL) {
						removeUsermode(usermode);
					}
				}
				//tbuff = ban name
			} else {
				sendNotEnoughPrivs(ENotEnough_HALFOP,setter,"set mode");
			}
			break;
		case 'E': //excempt/unexcempt someone
			if((info->halfop || operoverride && !(this->onlyowner == 1 && info->owner == false)) || p == NULL) {
				if(p == NULL) { //list bans
					std::list<userMode *>::iterator iterator=server.usermodes_list.begin();
					userMode *um;
					char *nick;
					info->client->getUserInfo(&nick,NULL,NULL,NULL);
					while(iterator != server.usermodes_list.end()) {
						um=*iterator;
							if(match(um->chanmask,getName())) {
								if(um->hostmask[0] != 0 && um->modeflags & EModeFlags_BanExcempt)
									info->client->send_numeric(367,"%s *!*@%s %s@%s %d",getName(), um->hostmask, um->setbynick[0] == 0?"SERVER":um->setbynick,um->setbyhost[0] == 0||info->halfop==false?"*":um->setbyhost,um->setondate);
							}
						iterator++;
					}
					info->client->send_numeric(368,"%s :End of channel exempt list",getName());
					break;
				}
				find_nth(p,modep++,tbuff,sizeof(tbuff));
				if(strlen(tbuff)<1) return;
				char setstr[128];
				memset(&setstr,0, sizeof(setstr));
				tbuffptr = (char *)&tbuff;
				if(strchr(tbuffptr,'@') != NULL) tbuffptr = strchr(tbuffptr,'@')+1;
				sprintf(setstr,"\\hostmask\\%s\\modeflags\\E\\comment\\Exempt by MODE command (Persist)",tbuffptr);
				if(set) {
					addUserMode(info->client,this->getName(),setstr);
				} else {
					userMode *usermode = findRemoveableUsermode(getName(),tbuff,EModeFlags_BanExcempt,setter->getRights()&OPERPRIVS_GLOBALOWNER);
					if(usermode != NULL) {
						removeUsermode(usermode);
					}
				}
			} else {
				sendNotEnoughPrivs(ENotEnough_HALFOP,setter,"set mode");
			}
			break;
		default:
			setter->send_numeric(472,"%c :is unknown mode to me for %s",modestr[i],getName());
			break;
		}
	}
	return;
}
예제 #21
0
void MoodBoxServer::getUserInfo(Callback callback, qint32 userId)
{
    getUserInfo(callback, QVariant(), userId);
}
예제 #22
0
//	This method converts a Message from ui layer to a Datagram that can be passed to network layer
void lmcMessaging::prepareMessage(MessageType type, qint64 msgId, bool retry, QString* lpszUserId, XmlMessage* pMessage) {
	if(!isConnected()) {
		lmcTrace::write("Warning: Not connected. Message not sent");
		return;
	}
    if(localUser->id.isNull()) {
        lmcTrace::write("Warning: Local user not initialized. Message not sent");
        return;
    }

	User* receiver = getUser(lpszUserId);

	switch(type) {
	case MT_Status:
		pMessage->addData(XN_STATUS, localUser->status);
		break;
	case MT_UserName:
		pMessage->addData(XN_NAME, localUser->name);
		break;
	case MT_Note:
		pMessage->addData(XN_NOTE, localUser->note);
		break;
	case MT_Ping:
		//	add message to pending list
		if(!retry)
			addPendingMsg(msgId, MT_Ping, lpszUserId, pMessage);
		break;
	case MT_Message:
		if(!receiver) {
			emit messageReceived(MT_Failed, lpszUserId, pMessage);
			break;
		}
		//	add message to pending list
		if(!retry)
			addPendingMsg(msgId, MT_Message, lpszUserId, pMessage);
		break;
	case MT_GroupMessage:
		break;
	case MT_PublicMessage:
		break;
	case MT_Broadcast:
		break;
	case MT_Acknowledge:
		break;
	case MT_Query:
		//	if its a 'get' query add message to pending list
		if(pMessage->data(XN_QUERYOP) == QueryOpNames[QO_Get] && !retry)
			addPendingMsg(msgId, MT_Query, lpszUserId, pMessage);
		else if(pMessage->data(XN_QUERYOP) == QueryOpNames[QO_Result])
			getUserInfo(pMessage);
		break;
	case MT_ChatState:
		break;
	case MT_File:
	case MT_Avatar:
		prepareFile(type, msgId, retry, lpszUserId, pMessage);
		break;
    case MT_Folder:
        prepareFolder(type, msgId, retry, lpszUserId, pMessage);
        break;
    default:
        break;
	}

	if(!receiver) {
		lmcTrace::write("Warning: Recipient " + *lpszUserId + " not found. Message not sent");
		return;
	}

	lmcTrace::write("Sending message type " + QString::number(type) + " to user " + receiver->id
		+ " at " + receiver->address);
	QString szMessage = Message::addHeader(type, msgId, &localUser->id, lpszUserId, pMessage);
	pNetwork->sendMessage(&receiver->id, &receiver->address, &szMessage);
	lmcTrace::write("Message sending done");
}
예제 #23
0
bool Channel::userOn(Client *user) {
	return getUserInfo(user)==NULL?false:true;
}
예제 #24
0
void NetWorker::replyFinished(QNetworkReply *reply)
{
    QString replyContent = reply->readAll();

    if ( 1 == nowRequestType ) //已得到prop信息
    {
        QString value;
        bool getAllProp = true;
        if ( SpiritUtil::getMid(replyContent, value, "ces/bas.", "?wlanuserip") )
        {
            config.getSetting()->setValue( "last_arg1_value", value );
        }
        else
        {
            getAllProp = false;
        }

        if ( SpiritUtil::getMid(replyContent, value, "userip=", "&wlanacname") )
        {
            config.getSetting()->setValue( "last_arg2_value", value );
        }
        else
        {
            getAllProp = false;
        }

        if ( getAllProp )
        {
            config.readConfig();
            postLogin();
        }
        else
        {
            emit postStatus("未能读取特征码,可能已登录");
            emit postStatusCode(32);
        }
    }
    else if ( 2 == nowRequestType ) //已得到登录信息
    {
        QString resultCode;

        if ( ! SpiritUtil::getMid(replyContent, resultCode, "resultCode\":\"", "\",\"") )
        {
            emit postStatus("异常:未能获取resultCode!");
            emit postStatusCode(32);

            return;
        }

        qDebug()<<"resultCode:"<<resultCode;

        if ( 0 == resultCode.compare("0") )
        {
            emit postStatus("当前状态:在线");
            emit postStatusCode(31);

            getUserInfo();  //获取费用信息
        }
        else
        {
            emit postStatus( config.getSetting()->value( "loginerror_"+resultCode ).toString() );
            emit postStatusCode(32);
        }
    }
    else if ( 11 == nowRequestType ) //已得到下线信息
    {
        QString resultCode;

        if ( ! SpiritUtil::getMid(replyContent, resultCode, "resultCode\":\"", "\",\"") )
        {
            emit postStatus("异常:未能获取resultCode!");
            emit postStatusCode(42);

            return;
        }

        qDebug()<<"resultCode:"<<resultCode;

        if ( 0 == resultCode.compare("0") )
        {
            emit postStatus("当前状态:下线");
            emit postStatusCode(41);
        }
        else
        {
            emit postStatus( config.getSetting()->value( "logofferror_"+resultCode ).toString() );
            emit postStatusCode(42);
        }
    }
    else if ( 21 == nowRequestType ) //得到用户费用信息
    {
        QString value;
        if ( SpiritUtil::getMid(replyContent, value, "总流量(公网):", "MB") )
        {
            emit postUserInfo(1, value + "MB" );
        }
        if ( SpiritUtil::getMid(replyContent, value, "剩余流量(公网):", "MB") )
        {
            emit postUserInfo(2, value + "MB" );
        }
        if ( SpiritUtil::getMid(replyContent, value, "已用流量(校园网):", "MB") )
        {
            emit postUserInfo(3, value + "MB" );
        }
        if ( SpiritUtil::getMid(replyContent, value, "剩余金额:", "元") )
        {
            emit postUserInfo(4, value + " 元" );
        }
    }
    else if ( 31 == nowRequestType ) //软件更新信息
    {
        emit postUpdateInfo( replyContent.trimmed() );
    }
}
AGDesktopInfoPalm * AGDesktopInfoPalmNew(void)
{
    AGDesktopInfoPalm * desktopInfo;

    desktopInfo = (AGDesktopInfoPalm *)malloc(sizeof(AGDesktopInfoPalm));
    if (NULL != desktopInfo) {

        char pathName[MAX_PATH];
        HKEY key = NULL;

        pathName[0] = '\0';

        bzero(desktopInfo, sizeof(AGDesktopInfoPalm));

        if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER,
            "Software\\U.S. Robotics\\Pilot Desktop\\Core",
            0,
            KEY_READ,
            &key)) {

            DWORD dwSize = MAX_PATH;
            DWORD type;

            RegQueryValueEx(key,
                "Path",
                0,
                &type,
                pathName,
                &dwSize);

            PathAppend(pathName, "instaide.dll");

            desktopInfo->hModule = LoadLibrary(pathName);

            /* It's possible for people to move around their directories
            legitimately, so we have to look in two places for the instaide
            DLL. */
            if (NULL == desktopInfo->hModule) {

                dwSize = MAX_PATH;

                RegQueryValueEx(key,
                    "HotSyncPath",
                    0,
                    &type,
                    pathName,
                    &dwSize);

                PathRemoveFileSpec(pathName);

                PathAppend(pathName, "instaide.dll");

                desktopInfo->hModule = LoadLibrary(pathName);

            }

            RegCloseKey(key);

        }

        if (NULL != desktopInfo->hModule) {

            desktopInfo->pGetUser = (PLTGETUSER)GetProcAddress(
                desktopInfo->hModule, "PltGetUser");

            desktopInfo->pGetUserCount = (PLTGETUSERCOUNT)GetProcAddress(
                desktopInfo->hModule, "PltGetUserCount");

            desktopInfo->pGetUserDirectory = (PLTGETUSERDIRECTORY)
                GetProcAddress(desktopInfo->hModule, "PltGetUserDirectory");

        }
        else {

            desktopInfo->userArray = getUserInfo();

        }

    }

    return desktopInfo;
}
예제 #26
0
파일: userserv.c 프로젝트: Lerc/userserv
void handleConnection(int socketfd)  {
	static char buffer[BUFFER_SIZE+1];
	static char* headers[HEADER_LIMIT+1];
	int i;
	int headerCount=0;
	//int requestSize = read(socketfd,buffer,BUFFER_SIZE);
	int requestSize = readUntil(socketfd,crlfcrlfCheck,buffer,BUFFER_SIZE);
	if (requestSize ==0 || requestSize == -1) {
		fail("failed to read browser request");		
	}
	logText(buffer);
	int done = 0;
	char mode = 0; /*  */
	for (i=0;i<requestSize;i++) {
		switch(mode) {
			case '\r':  
				if (buffer[i] == '\n') {
					buffer[i-1]=0;
					mode=0;
					done = (*headers[headerCount]==0) || (headerCount++ == HEADER_LIMIT);
				}
				break;
			case 0:
			  headers[headerCount]=&buffer[i]; 
			default:
			  mode=buffer[i];
			  if (mode==0) done=1;  /* catch headers containing zeros */
		}
		if (done) break;
	}
	int bodyStart=i+1;
  int bodyLength=requestSize-bodyStart;
  
	headers[headerCount]=NULL; /*null terminated list*/

  logFormat("%d header lines\n",headerCount);
	logText("we got some headers");
	for (i=0; i<headerCount;i++) {
		logFormat("%d: %s\n",i,headers[i]);
	}
	logText("That was them headers");
	
	/*
	logText("looking for User-Agent:");	
	char* userAgent=findHeader(0,headerCount,headers,"User-Agent:");
	if (userAgent==NULL) {logText("No User-Agent");} else	{logText(userAgent);}
	*/
	
	char* aCookie = findHeader(0,headerCount,headers,"Cookie:");
	int uid=getUserInfo(aCookie);
  logFormat("uid of %d\n",uid);
	
	if (uid <= 0) {
		if (strncmp("POST /login ",headers[0],12) == 0 ) {
			 //for a non-logged-in user POST to /login try and read user credentials.  
			logText("Login request received");
			char userpass[300];
			struct passwd* pwd = NULL;
			strncpy(userpass,&buffer[bodyStart],300);			
			if (userpass[299] == 0) {
				char* user = NULL;
				char* pass = NULL;
				user = strstr(userpass,"user="******"pass="******"I think the userName is '%s'\n",user);
				//logFormat("I think the passWord is '%s'\n",pass);				
				pwd = checkUserPass(user,pass);
				free(pass);				
			}
			char* resultPage;
			if (pwd != NULL) {
				logText("setting cookie");
				char token[33];
				token[32]='\0';
				makeAuthenticationToken(pwd->pw_uid,token,32); 
				
				char* pageHeaders;
				asprintf(&pageHeaders,"Set-Cookie: %s; Secure; HttpOnly\r\nLocation: %s\r\n",token,loginRedirect);
				logText(pageHeaders);
				resultPage=
				"<html><head></head><body"
					"<div>Login Successful</div>"
				"</body></html>";
				sendHTMLPage(socketfd,"303 See Other",pageHeaders,resultPage);
				free(pageHeaders);
			} else {
				resultPage=
				"<html><head></head><body"
					"<div>Login Failed</div>"
				"</body></html>";				
				sendSimpleHTMLPage(socketfd,"401 Unauthorised",resultPage);
			}			
		} else {
			sendLoginPage(socketfd);
		}
	}	else {			
		struct passwd *pw = getpwuid(uid);
		setgid(uid);
		setuid(uid);
		setenv("HOME",pw->pw_dir,1);
		setenv("USER",pw->pw_name,1);
		setenv("SHELL",pw->pw_shell,1);
		//if we get to here, the request sent a token identifying them as a 
		//valid user and we have dropped privileges to be that user.
		//now we can set about serving the user request.
#ifdef NOTANOS 
		//support for a notanos websocket server.  
		char* upgrade = findHeader(0,headerCount,headers,"Upgrade:");
		if (upgrade) {
			 //Try using websockets
			 char* websocket_key = findHeader(0,headerCount,headers,"Sec-WebSocket-Key:");
			 char* websocket_protocol = findHeader(0,headerCount,headers,"Sec-WebSocket-Protocol:");
			 char* websocket_version = findHeader(0,headerCount,headers,"Sec-WebSocket-Version:");
			 char* origin = findHeader(0,headerCount,headers,"Origin:");
			 webSocketUpgrade(socketfd,websocket_key,websocket_protocol,websocket_version,origin);
			 //webSocketUpgrade should never return
		} 
#endif		
		if (strncmp("GET ",headers[0],4) == 0 ) {
			char* nameStart=headers[0]+4;
			int nameLen = strcspn(nameStart," ");
			char* urlName=strndup(nameStart,nameLen);
			char* fileName=url_decode(urlName);
			char* queryStart=strchr(fileName,'?');
			if (queryStart != NULL) *queryStart++='\0';
			
			logFormat("url request '%s'\n",urlName);
			logFormat("filename request '%s'\n",fileName);
			char* newFileName=expandFilename(fileName);
			free(fileName); fileName=newFileName;
			char* contentType=getContentType(fileName);
			struct stat fileInfo;
			int res=stat(fileName,&fileInfo);
			if (res !=0)  {
				if (errno == EACCES) {
					sendSimpleHTMLPage(socketfd,"403 Forbidden","403: Forbidden");
				} else {
					sendSimpleHTMLPage(socketfd,"404 Not Found","404: Not Found");
				}
			}	else {
				if (S_ISREG(fileInfo.st_mode)) {
					int filefd=open(fileName,O_RDONLY);
					if (filefd < 0) {
						sendSimpleHTMLPage(socketfd,"403 Forbidden","403: Forbidden");
					} else {
						sendFileChunked(socketfd,"200 OK",filefd,contentType);
						close(filefd);
					}
				}
				else if (S_ISDIR(fileInfo.st_mode)) {
					char* command;
					char* awkline = "BEGIN {printf(\"{\\\"path\\\":\\\"%s\\\",\\n \\\"contents\\\":[\\n\",path)} END{print\"\\n  ]\\n};\\n\"}  NR > 2 { printf(\",\\n\") } NR >1 { printf(\"    {\\\"filename\\\":\\\"%s\\\", \\\"attributes\\\":\\\"%s\\\", \\\"owner\\\":\\\"%s\\\", \\\"size\\\":%s}\", $9, $1, $3, $5) }";
					//int commandLength = asprintf(&command,"ls -AlQ %s|  awk -v path=%s '%s'",fileName,fileName,awkline);
					int commandLength = asprintf(&command,"./jsondir '%s'",fileName);
					logText(command);
					if (commandLength>0) {
						FILE* commandPipe = popen(command,"r");
						if (commandPipe) { 
							int commandfd=(fileno(commandPipe));
							sendFileChunked(socketfd,"200 OK",commandfd,"application/json");
							pclose(commandPipe);
						} else {
							sendSimpleHTMLPage(socketfd,"500 Internal Server Error","popen failure");
						}
						free(command);
					} else {
						sendSimpleHTMLPage(socketfd,"200 OK","That's a directory");
					}  
				}

			}
			free(fileName);
			free(contentType);
			free(urlName);
		}
	}
	logText("done response, closing connection");
	sleep(1);
	close(socketfd);
	exit(1);
}