Exemple #1
0
Scene::Scene(GuiWidgets* _gw) :
gw(*_gw), 
is_visible(true),    // should be set to false when the window is iconified !!!!
is_initialized(false),
is_startCB_launched(false),
net_delay(500),
cycles(0),
hud(NULL)
{
  background = UBackground::black;
  addAttr(background);
  addAttr(usize(g.pref.width3D, g.pref.height3D));

  hudbox.addAttr(upos(1, 1)  // position relatively to the canvas : up left corner
                 + UOrient::vertical + UHalign::left
                 + UFont::small + UColor::yellow   // size & color of the text
                 );
  hudbox.add(hud_line1 + hud_line2 + hud_line3 + hud_line4 + hud_line5);
  add(hudbox);	// add the hudbox to the scene

  message.addAttr(UFont::bold + UFont::xx_large + UColor::orange + uhcenter() + uvcenter());
  message.add("Please wait, VReng is coming up...");
  add(uhflex() + uvflex() + message);
  
  // Paint and Resize functions:
  // - are callback functions (paintCB and resizeCB) if the Scene is a UBox 
  // - are redefinitions of paintGL and resizeGL if the Scene is a UGlcanvas
  addAttr(UOn::paint / ucall(this, &Scene::paintCB)
          + UOn::resize / ucall(this, &Scene::resizeCB));
}
Exemple #2
0
ItemAttributes::Attribute* ItemAttributes::getAttr(const itemAttrTypes& type)
{
	Attribute* curAttr;

	if ((type & m_attributes) == 0)
	{
		//if that type was not present add it
		curAttr = new Attribute(type);
		addAttr(curAttr);
		return curAttr;
	}
	else
	{
		//was present, search and return it
		curAttr = m_firstAttr;

		while (curAttr)
		{
			if (curAttr->type == type)
			{
				return curAttr;
			}

			curAttr = curAttr->next;
		}
	}

	std::cout << "Warning: [ItemAttributes::getAttr] (type & m_attributes) != 0 but attribute not found" << std::endl;
	curAttr = new Attribute(type);
	addAttr(curAttr);
	return curAttr;
}
Exemple #3
0
ItemAttributes::Attribute* ItemAttributes::getAttr(itemAttrTypes type)
{
	Attribute* curAttr;

	if ((type & m_attributes) == 0) {
		curAttr = new Attribute(type);
		addAttr(curAttr);
		return curAttr;
	} else {
		curAttr = m_firstAttr;

		while (curAttr) {
			if (curAttr->type == type) {
				return curAttr;
			}

			curAttr = curAttr->next;
		}
	}

	std::cout << "Warning: [ItemAttributes::getAttr] (type & m_attributes) != 0 but attribute not found" << std::endl;
	curAttr = new Attribute(type);
	addAttr(curAttr);
	return curAttr;
}
Exemple #4
0
Attr::Attr(string key, string value)
{
	attrMap = map<string, string>();
	keyList = vector<string>();
	
	addAttr(key, value);
}
Exemple #5
0
static int callback_convert(void *pArg, int argc, char **argv, char **azColName){
    Link array = (Link) pArg;
    Link record = object_create(record_type);
    int i;
    for (i = 0; i < argc; i++){
        //printf("%s    %s\n", azColName[i], argv[i]);
        addAttr(record, create_string(argv[i]) , create_string(azColName[i]));
    }
    array_push(array, record);
    return 0; /* okay */
}
Exemple #6
0
/*function : send a request pkg to AC auth and wish to get response from that --tangsiqi 2010-1-18*/
int CgiInformAc(char * clientIp, char * serverIp, PKG_TYPE Type, STAuthProcess * pAuthProc,UINT32 pro)
{
	int retErr=0;
	struct in_addr user_ip;
	struct in6_addr user_ipv6;
	pAuthProc->pSendPkg= createPortalPkg(Type);
	/*malloc STPortalPkg ready to rev data*/
	fprintf(stderr,"CgiInformAc createPortalPkg suc Type is %d\n",Type );
	pAuthProc->pRevPkg = (STPortalPkg * )malloc(sizeof(STPortalPkg));
	memset(pAuthProc->pRevPkg, 0, sizeof(STPortalPkg));
    fprintf(stderr,"CgiInformAc serverIp=%s\n",serverIp );

	setAuthType(pAuthProc->pSendPkg, pro);

	memset(&user_ip, 0, sizeof(user_ip));
	memset(&user_ipv6, 0, sizeof(user_ipv6));
	if (1 == inet_pton(AF_INET, clientIp, &user_ip)) {
		fprintf(stderr,"CgiInformAc clientIp4=%s\n",clientIp );
		setPkgUserIP( pAuthProc->pSendPkg, user_ip.s_addr );
	} else if (1 == inet_pton(AF_INET6, clientIp, &user_ipv6)){
		fprintf(stderr,"CgiInformAc clientIp6=%s\n",clientIp );
		pAuthProc->pSendPkg->version = 0x02;
		setPkgUserIP( pAuthProc->pSendPkg, 0 );
		addAttr( &(pAuthProc->pSendPkg), ATTR_USER_IPV6, &user_ipv6, sizeof(user_ipv6) );
	}
	fprintf(stderr,"CgiInformAc version=%u\n",pAuthProc->pSendPkg->version );

	if(sendPortalPkg(pAuthProc->fd, 3, 2000, serverIp, pAuthProc->pSendPkg) < 0 )
	{
		fprintf(stderr,"CgiInformAc sendPortalPkg failed\n" );
		retErr = -1;
	}
	else
	{
		fprintf(stderr,"CgiInformAc sendPortalPkg suc\n" );
	}

	if(getPortalPkg(pAuthProc->fd, 3, &(pAuthProc->pRevPkg))<0)
	{
		fprintf(stderr,"CgiInformAc getPortalPkg failed\n" );
		retErr = -1;
	}
	else
	{
		fprintf(stderr,"CgiInformAc getPortalPkg suc\n" );
		retErr = getErrCode(pAuthProc->pRevPkg);
	}

	fprintf(stderr,"CgiInformAc getErrCode(stAuth.pRevPkg)=%d\n", retErr );

	return retErr;
}
Exemple #7
0
void UTreenode::constructs(const UArgs& _title, const UArgs& children) {
  static UPadding& offset = upadding(0, UIGNORE).setLeft(40);
  psubnodes = &uvbox(children);
  psubnodes->addAttr(offset);
  psubnodes->addAttr(UVspacing::none);
  addAttr(UVspacing::none);
  
  pexpander = new UBox
    (UOn::select   / USymbol::down
     + UOn::deselect / USymbol::right
     + UOn::select   / ushow(*psubnodes, true)
     + UOn::deselect / ushow(*psubnodes, false)
     );
  pexpander->setSelected(false);
  psubnodes->show(false);
  
  plabel = new UItem(*pexpander +  " " + _title);
  UBox::add(*plabel + *psubnodes);
}
Exemple #8
0
void NodeBlock::load(QDataStream &ds, QMap<quint64, NodeAttr*> &attrMap)
{
	QPointF p;
	ds >> p;
	setPos(p);
	int count;
	ds >> count;
	for (int i = 0; i < count; i++)
	{
		QString name;
		bool output;
		int flags;
		quint64 ptr;

		ds >> ptr;
		ds >> name;
		ds >> output;
		ds >> flags;
        attrMap[ptr] = addAttr(name, output, flags, ptr);
	}
}
Exemple #9
0
/* create a backtrace for the critical link  */
static inline void addBacktrace(Link crit, Link codeblock_link, int linenum){
    if (! crit) return;
    if (! is_critical(crit)) return;
    
    Module module = codeblock_link->value.codeblock->parent->value.module;
    
    Link message = NULL;
    
    if (linenum)
        message = create_string_str( string_new_formatted("[module:%s   line:%i]", module->name->data, linenum));
    else
        message = create_string_str( string_new_formatted("[module:%s]", module->name->data) );

    Link backtrace = getAttr(crit, Global->backtrace_key);
        
    if ( ! backtrace ){
        backtrace = array_new(0);
        //fprintf(stderr, "createing backtrace array %p\n", backtrace);
        addAttr(crit,backtrace,Global->backtrace_key);
    }        

    array_push(backtrace, message);
    link_free(backtrace);
}
Exemple #10
0
static void global_init(){
    
    /* locate the installation directory */
    Global->blue_location       = find_blue();
    Global->blue_lib_location   = find_blue_lib();
    
    /* 0 = only main thread; >0 = multi-threaded */
    Global->threads = 0;

    /* initialize basic object functionality */
    object_init();
    native_init();

    Global->backtrace_key       = create_string("__backtrace");
    Global->constructor_key     = create_string("_");
    Global->destructor_key      = create_string("__");

    Link loc     = create_string(Global->blue_location->data);
    Link loc_key = create_string("install_dir");
    
    addAttr(Global->SYS_MODULE, loc , loc_key);
    link_free(loc);
    link_free(loc_key);
}
Exemple #11
0
Node::Node(string name, Node *nodeParent)
{
	
	attrList = new Attr();
	nodeName = name;
	children = map<string, Node *>();
	childNames = vector<string>();
	reqs = vector<Node *>();
	reqParent = vector<string>();
	reqConcept = vector<string>();
	reqPtr = vector<Node *>();
	parent = nodeParent;
	if(parent != NULL)
	{
		parentName = nodeParent->getName();
	}
	else
	{
		parentName = "";
	}
	addAttr("id", nodeName);
	func = (FMap::ExecFunc) NULL;
	//func = functionMap->getFunc(name);
}
void parse_item(bool capture, std::string pinName, AttributeList *attr)
{
    while (tokval != "}" && !eof) {
        std::string paramname = tokval;
        validate_token(isId(tokval[0]), "name");
        if (paramname == "default_intrinsic_fall" || paramname == "default_intrinsic_rise") {
            validate_token(tokval == ":", ":(paramname)");
            if (capture)
                addAttr(attr, pinName, paramname, tokval);
            validate_token(isdigit(tokval[0]), "number");
        }
        else if (paramname == "bus_type") {
            validate_token(tokval == ":", ":(bus_type)");
            if (capture)
                addAttr(attr, pinName, paramname, tokval);
            validate_token(isId(tokval[0]), "name");
        }
        else if (tokval == "(") {
            while (tokval == "(") {
                std::string paramstr = parseparam();
                bool cell = paramname == "cell" && paramstr == options.cell;
                int ind = paramstr.find("[");
                if (capture && (paramname == "pin" || paramname == "bus")) {
                    if (ind > 0 && paramstr[paramstr.length()-1] == ']') {
                        std::string sub = paramstr.substr(ind+1);
                        sub = sub.substr(0, sub.length()-1);
                        paramstr = paramstr.substr(0, ind);
                        capturePins[paramstr].pins[atol(sub.c_str())] = 1;
                    }
                    parse_item(true, paramstr, &capturePins[paramstr].attr);
                }
                else if (paramname == "type") {
                    parse_item(true, "", &busInfo[paramstr].attr);
                }
                else
                    parse_item(capture || cell, pinName, attr);
//if (paramname == "cell")
//printf("[%s:%d] paramname %s paramstr %s \n", __FUNCTION__, __LINE__, paramname.c_str(), paramstr.c_str());
                if (cell) {
                    processCell();
                    return;
                }
                paramname = tokval;
                if (!isId(tokval[0]))
                    break;
                parsenext();
            }
        }
        else {
            validate_token(tokval == ":", ":(other)");
            if (capture && paramname != "timing_type")
                addAttr(attr, pinName, paramname, tokval);
            if (isdigit(tokval[0]) || isId(tokval[0]) || tokval[0] == '"')
                parsenext();
            else
                validate_token(false, "number or name or string");
            if (tokval != "}")
                validate_token(tokval == ";", ";");
        }
    }
    validate_token(tokval == "}", "}");
}
Exemple #13
0
/*main--tangsiqi 2010-1-18*/
int cgiMain()
{

	int retLogin=-1,retLogout=-1,ret_challege=0,fd=0;/*0--suc,100--timeout, 減方---fail*/
	unsigned short reqID = 0;
	char opt[10]="";
	FILE * fpOut = cgiOut;
	unsigned char chap_password[MD5LEN + 2] = {0};
	unsigned char chap_challenge[MD5LEN] = {0};
	MD5_CTX context;
	unsigned char chap_ident=0;
	STPkgAttr *tlvPkgAttr;
	UINT8  tmp[MD5LEN+1];
	char acIp[32] = "";
	char userIp[32] = "";
	char ssid[64] = "";
	
	STUserInfo userInfo;
	memset(&userInfo, 0 ,sizeof(STUserInfo));

	cgiHeaderContentType("text/html");

	/*rev user info from login.html*/
	cgiFormStringNoNewlines("op_auth", opt, 10);
	fprintf(stderr,"opt=%s",opt);
	if( strlen(opt)>0 && (!strcmp(opt,"login")) )
	{
		cgiFormStringNoNewlines("a_name", userInfo.usrName, MAX_EAG_LOGIN_NAME_LEN);
		cgiFormStringNoNewlines("a_pass", userInfo.usrPass, MAX_EAG_LOGIN_PASS_LEN);

		userInfo.usrOperation = 1;
	}
	else
	{
		userInfo.usrOperation = 2;/*logout*/
	}
		
	
	//fprintf(stderr,"cgiQueryString=%s",cgiQueryString);
	//fprintf(stderr,"cgiReferrer=%s",cgiReferrer);
	//fprintf(stderr,"cgiServerName=%s",cgiServerName);
	memset(acIp, 0, sizeof(acIp));
	if( cgiFormNotFound == cgiFormStringNoNewlines("wlanacip", acIp, sizeof(acIp)) ) {
		strncpy(acIp, cgiServerName, sizeof(acIp)-1);
	}
	if( cgiFormNotFound == cgiFormStringNoNewlines("wlanuserip", userIp, sizeof(userIp)) ) {
		strncpy(userIp, cgiRemoteAddr, sizeof(userIp)-1);
	}
	cgiFormStringNoNewlines("ssid", ssid, sizeof(ssid));

	fprintf( fpOut, "<html xmlns=\"http://www.w3.org/1999/xhtml\"> \n" );
	fprintf( fpOut, "<head> \n" );
	fprintf( fpOut, "<meta http-equiv=Content-Type content=text/html; charset=gb2312> \n" );


  	fprintf( fpOut, "<META   HTTP-EQUIV=\"pragma\"   CONTENT=\"no-cache\"> \n");
  	fprintf( fpOut, "<META   HTTP-EQUIV=\"Cache-Control\"   CONTENT=\"no-cache,   must-revalidate\"> \n" );
  	fprintf( fpOut, "<META   HTTP-EQUIV=\"expires\"   CONTENT=\"Wed,   26   Feb   1997   08:21:57   GMT\">	\n");


	fprintf( fpOut, "<title>login_proc</title>\n");
	fprintf( fpOut, "</head> \n" );
	fprintf( fpOut, "<boby>\n");

	
	/*process http req and require a auth request with AC*/
	STAuthProcess stAuth;
	memset(&stAuth, 0, sizeof(STAuthProcess));

	cgi_auth_init(&stAuth, 2000);
	STUserManagePkg * pstReq = NULL;
	STUserManagePkg * pstRsp = NULL;
	char urlPost[4096]={0};
	char *urlNew = NULL;
	char *replace = NULL;
	char urlParam[128] = "";
	char urlValue[256] = "";
	struct in_addr user_ip;
	struct in6_addr user_ipv6;
	
	fprintf(stderr, "a_name=%s, a_pass=%s, op_auth=%s, userIp=%s, acIp=%s, cgiRemoteAddr=%s, cgiServerName=%s\n",
			userInfo.usrName, userInfo.usrPass, opt, userIp, acIp, cgiRemoteAddr, cgiServerName);
	#if 1

	fprintf(stderr,"cgiReferrer=%s\n", cgiReferrer  );
	#endif
	strncpy(urlPost, cgiReferrer, strlen(cgiReferrer));
	#if 0
	fprintf(stderr,"before urlPost=%s\n" ,urlPost );
	replace = strrchr(urlPost, '//');
	fprintf(stderr,"before replace=%s\n" ,replace );
	int partLen = strlen(replace);
	memset(replace, "\0", partLen);
	fprintf(stderr,"inner urlPost=%s\n" ,urlPost );
	memcpy(replace, "/auth_suc.html", strlen("/auth_suc.html")+1);
	
	fprintf(stderr,"last urlPost=%s--partLen=%d\n" ,urlPost, partLen );
	#endif
	
	fprintf(stderr,"userInfo.usrOperation=%d\n" ,userInfo.usrOperation );
	switch(userInfo.usrOperation)
	{
		case 1:/*login*/
			//stAuth.protocal = AUTH_CHAP;

			pstReq =  createRequirePkg(REQ_GET_AUTH_TYPE,NULL,NULL);

			/*connect unix sock to get auth type*/
			//fd = suc_connect_unix_sock();
			//if(fd <= -1)
			//{
			//	fprintf(stderr,"suc_connect_unix_sock: error\n");
			//	break;
			//}

			//fprintf(stderr,"fd=%d",fd);
			stAuth.protocal = AUTH_CHAP;//get_authType_from_eag( pstReq, fd, 5, &(pstRsp));
			//fprintf(stderr,"stAuth.protocal=%d",stAuth.protocal);
			//close( fd );

			if( stAuth.protocal == AUTH_CHAP )				/*chap md5 simulation----------*/
			{
				ret_challege = CgiInformAc(userIp, acIp, REQ_CHALLENGE, &stAuth, stAuth.protocal);
				fprintf(stderr,"ret_challege=%d", ret_challege);
				if( CHALLENGE_SUCCESS == ret_challege || CHALLENGE_CONNECTED == ret_challege )/*if ret is success ,then can get attr from rev pkg*/
				{
					if((tlvPkgAttr = getAttrByAttrType(stAuth.pRevPkg, ATTR_CHALLENGE)) == NULL && CHALLENGE_CONNECTED == ret_challege)
					{
						retLogin = 0;/*容僕suc.html*/
						break;
					}
				}
				else
				{
					retLogin = -1;/*容僕fail.html*/
					break;
				}
				memcpy(chap_challenge, tlvPkgAttr->attr_value, tlvPkgAttr->attr_len);
				fprintf(stderr,"chap_challenge() value %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n", \
						 chap_challenge[0],chap_challenge[1],chap_challenge[2],
						chap_challenge[3],chap_challenge[4],chap_challenge[5],chap_challenge[6],chap_challenge[7],chap_challenge[8],chap_challenge[9],
						chap_challenge[10],chap_challenge[11],chap_challenge[12],chap_challenge[13],chap_challenge[14],chap_challenge[15] );
				reqID = getRequireID(stAuth.pRevPkg);
				fprintf(stderr,"CHAP: reqID=%d\n",reqID);
				unsigned char chap_id = (unsigned char)reqID ;
				fprintf(stderr, "chap_id=%d\n",chap_id);

				/*simulate MD5 encoded at portal server add by tangsiqi 2010-1-5*/

				MD5Init(&context);
				MD5Update(&context, (UINT8 *)&chap_id, 1);
				MD5Update(&context, (UINT8 *)userInfo.usrPass, strlen(userInfo.usrPass));/*now the password is get through by redir url */
				MD5Update(&context, chap_challenge, MD5LEN);
				MD5Final(tmp, &context);
				tmp[MD5LEN] = 0;/*add 0 at end of char[]*/
				fprintf(stderr,"CHAP: tmp=%s",tmp);

				memcpy(chap_password, tmp, MD5LEN );
				chap_password[MD5LEN+1] = 0;
				fprintf(stderr,"...add attr CHAP_PASSWORD() value %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n", \
						 chap_password[0],chap_password[1],chap_password[2],
						chap_password[3],chap_password[4],chap_password[5],chap_password[6],chap_password[7],chap_password[8],chap_password[9],
						chap_password[10],chap_password[11],chap_password[12],chap_password[13],chap_password[14],chap_password[15] );

				destroyPortalPkg(stAuth.pSendPkg);
				destroyPortalPkg(stAuth.pRevPkg);
 			}

			/*after challege exchange*/
			stAuth.pSendPkg = createPortalPkg(REQ_AUTH);
			fprintf(stderr,"login createPortalPkg suc\n" );

			/*malloc STPortalPkg ready to rev data*/
			stAuth.pRevPkg = (STPortalPkg * )malloc(sizeof(STPortalPkg));
			memset(stAuth.pRevPkg, 0, sizeof(STPortalPkg));

			setAuthType(stAuth.pSendPkg, stAuth.protocal);
			setRequireID(stAuth.pSendPkg, reqID );
			memset(&user_ip, 0, sizeof(user_ip));
			memset(&user_ipv6, 0, sizeof(user_ipv6));
			if (1 == inet_pton(AF_INET, userIp, &user_ip)) {
				fprintf(stderr,"userIp4=%s\n",userIp);
				setPkgUserIP( stAuth.pSendPkg, user_ip.s_addr );
			} else if (1 == inet_pton(AF_INET6, userIp, &user_ipv6)){
				fprintf(stderr,"userIp6=%s\n",userIp);
				stAuth.pSendPkg->version = 0x02;
				setPkgUserIP( stAuth.pSendPkg, 0 );
				addAttr( &stAuth.pSendPkg, ATTR_USER_IPV6, &user_ipv6, sizeof(user_ipv6) );
			}
			fprintf(stderr,"version=%u\n", stAuth.pSendPkg->version);

			addAttr( &stAuth.pSendPkg, ATTR_USERNAME, userInfo.usrName, strlen(userInfo.usrName) );

			if( stAuth.protocal == AUTH_CHAP )
			{
				/*challenge exchange*/
				addAttr( &stAuth.pSendPkg, ATTR_CHAPPASSWORD, chap_password, MD5LEN );
			}
			else/*PAP authentication*/
			{
				fprintf(stderr,"userInfo.usrPass=%s",userInfo.usrPass);
				addAttr( &stAuth.pSendPkg, ATTR_PASSWORD, userInfo.usrPass, strlen(userInfo.usrPass) );
			}

			if(sendPortalPkg(stAuth.fd, 6, 2000, acIp, stAuth.pSendPkg) < 0 )
			{
				fprintf(stderr,"login sendPortalPkg failed\n" );
				retLogin = -1;
			}
			else
			{
				fprintf(stderr,"login sendPortalPkg suc\n" );
			}

			if(getPortalPkg(stAuth.fd, 12, &(stAuth.pRevPkg))<0)
			{
				fprintf(stderr,"login getPortalPkg failed\n" );
				retLogin = -1;
			}
			else
			{
				fprintf(stderr,"login getPortalPkg suc\n" );
			}
			retLogin = getErrCode(stAuth.pRevPkg);
			fprintf(stderr,"login getErrCode(stAuth.pRevPkg)=%d\n", retLogin );


			destroyPortalPkg(stAuth.pSendPkg);
			destroyPortalPkg(stAuth.pRevPkg);
			break;
		case 2:/*logout*/
			retLogout = CgiInformAc(userIp, acIp, REQ_LOGOUT, &stAuth, stAuth.protocal);
			destroyPortalPkg(stAuth.pSendPkg);
			destroyPortalPkg(stAuth.pRevPkg);
			break;
		default:
			break;
	}
	
	
	fprintf(stderr,"retLogin=%d---retLogout=%d\n" ,retLogin,retLogout );
	closePkgSock(&stAuth);
	if( retLogin==100 ||  retLogout==100 )/*time out will retry,reserve*/
	{
		fprintf( fpOut, "<table border=0 cellspacing=0 cellpadding=0><tr><td colspan=2>time out!please retry or return</td></tr>\n");
		fprintf( fpOut, "<tr><td><input type='submit' name='retry' value='retry'></td><td><input type='submit' name='return' value='return'></td></tr>\n");
		fprintf( fpOut, "</table>\n");
		goto html_end;
	}

	snprintf(urlParam, sizeof(urlParam)-1, "wlanacip=%s&wlanuserip=%s&ssid=%s", acIp, userIp, ssid);
	if( userInfo.usrOperation == 1 )/*login*/
	{
		switch(retLogin)
		{
			case PORTAL_AUTH_SUCCESS:
			case PORTAL_AUTH_CONNECTED: /* urlNew = replaceStrPart(urlPost, "/auth_suc.html"); locate(fpOut, urlNew);break; */
				snprintf(urlValue, sizeof(urlValue)-1, "/auth_suc.html?%s", urlParam);
				urlNew = replaceStrPart(urlPost, urlValue);
				locate(fpOut, urlNew);
				break;
			case PORTAL_AUTH_REJECT: 	/* urlNew = replaceStrPart(urlPost, "/auth_fail.html"); locate(fpOut, urlNew);break; */
			case PORTAL_AUTH_ONAUTH: 	/* urlNew = replaceStrPart(urlPost, "/auth_fail.html"); locate(fpOut, urlNew);break; */
			case PORTAL_AUTH_FAILED: 	/* urlNew = replaceStrPart(urlPost, "/auth_fail.html"); locate(fpOut, urlNew);break; */
				snprintf(urlValue, sizeof(urlValue)-1, "/auth_fail.html?%s", urlParam);
				urlNew = replaceStrPart(urlPost, urlValue);
				locate(fpOut, urlNew);
				break;
			case -1:					/* urlNew = replaceStrPart(urlPost, "/login.html"); locate(fpOut, urlNew);break; */
				snprintf(urlValue, sizeof(urlValue)-1, "/login.html?%s", urlParam);
				urlNew = replaceStrPart(urlPost, urlValue);
				locate(fpOut, urlNew);
				break;
			default:
				break;
		}
	}
	else if( userInfo.usrOperation == 2 )/*logout*/
	{
		switch(retLogout)
		{
			case EC_ACK_LOGOUT_SUCCESS: /* urlNew = replaceStrPart(urlPost, "/login.html"); locate(fpOut, urlNew);break; */
				snprintf(urlValue, sizeof(urlValue)-1, "/login.html?%s", urlParam);
				urlNew = replaceStrPart(urlPost, urlValue);
				locate(fpOut, urlNew);
				break;
			case -1:
			case EC_ACK_LOGOUT_REJECT: 	/* urlNew = replaceStrPart(urlPost, "/auth_suc.html"); locate(fpOut, urlNew);break; */
			case EC_ACK_LOGOUT_FAILED: 	/* urlNew = replaceStrPart(urlPost, "/auth_suc.html"); locate(fpOut, urlNew);break; */
				snprintf(urlValue, sizeof(urlValue)-1, "/auth_suc.html?%s", urlParam);
				urlNew = replaceStrPart(urlPost, urlValue);
				locate(fpOut, urlNew);
				break;
			default:
				break;
		}
	}
html_end:

	fprintf( fpOut, "</body>\n" );
	fprintf( fpOut, "</html>\n" );

		
}
Exemple #14
0
Link interpret(Link codeblock_link ,  Link This, Link Arg){
    
    CallEnv env = callenv_new_root( codeblock_link, This, Arg);
    LinkStack stack = env->stack;
    
    
    Link b          = NULL;
    Link link       = NULL;
    Link parent     = NULL;
    Link child_key  = NULL;
    
    Link pusher     = NULL; // Anything in this variable gets pushed onto the stack
    Link trapped    = NULL; // This is the last critical caught by the trap operator
    
    int    delta = 0; // jump delta

    /* Main interpreter loop */
    while(1){

        switch( *(env->current++) ){

            case INTRO:
                env->current+=4;
                break;

            case ALLOC_MODULE:
                delta = read_offset(env);
                env->module->global_vars = linkarray_new(delta);
                break;
            
            case ALLOC_LOCAL:
                delta = read_offset(env);
                env->local = linkarray_new(delta);
                break;
                                
            case NO_OP:
                break;
            
            case RETURN: // if there is something on the env->stack stack pop it off and return it, if not return null link
                if (   stack_length(stack) - env->stack_offset ){
                    pusher = stack_pop(stack);
                }else{
                    pusher = object_create(Global->null_type);
                }
                goto done;

            case RAISE: // if there is something on the stack stack pop it off and return it, if not return null link
            
                if (  stack_length(stack) - env->stack_offset ){
                    pusher = create_critical(stack_pop(stack));
                }else{
                    pusher = create_critical(object_create(Global->null_type));
                }
                goto done;

            case PUSH_LEX:
                delta = read_offset(env);
                //fprintf(stderr , "push lex [%i]    %p\n", delta,env->function->value.codeblock->lexicals);
                pusher = link_dup(env->function->value.codeblock->lexicals->vars[delta]);
                break;
                
            case STORE_LEX:
                delta = read_offset(env);
                //fprintf(stderr , "storing lex [%i]    %p\n", delta,env->function->value.codeblock->lexicals);
                b = env->function->value.codeblock->lexicals->vars[delta];
            
                if (b){
                    if  ( (b->type == Global->function_type) && 
                          (b->value.codeblock->lexicals == env->function->value.codeblock->lexicals)
                        )  b->value.codeblock->lexical_cycles--;
                    link_free(b);
                }
                
                b = link_dup(stack_peek(stack));
                if  ( (b->type == Global->function_type) && 
                      (b->value.codeblock->lexicals == env->function->value.codeblock->lexicals)
                    )  b->value.codeblock->lexical_cycles++;
                
                env->function->value.codeblock->lexicals->vars[delta] = b;
                
                break;
            
            case DEF:
                if (env->Def) link_free(env->Def);
                env->Def = stack_pop(env->stack);
                pusher = link_dup(env->Def);
                break;
            
            case PUSH_DEF:
                if ( ! env->Def){
                    pusher = exception("NoDefObject",NULL, NULL);
                }
                pusher = link_dup(env->Def);
                break;
                
                
                
            case ALLOC_LEXICAL:
                delta = read_offset(env);
                lexicals_alloc( env->function, delta);
                //env->lexical_root = 1;
                break;
                
            case STORE_ARG:
                delta = read_offset(env);
                
                if (env->Arg->value.array->length  > delta){
                    retry_store_arg:
                    env->Arg->value.array->links[delta] =  link_dup( stack_peek(stack) );
                }else{
                    array_push(env->Arg, NULL);
                    goto retry_store_arg;
                } 
                break;
                
            case PUSH_ARG:
                delta = read_offset(env);
                if (env->Arg->value.array->length  > delta){
                    pusher = link_dup(  env->Arg->value.array->links[delta]);
                }else{
                    pusher = exception("ArgsIndexOutOfBounds", NULL, NULL);
                }
            
                break;
                
            case STORE_GVAR:
                delta = read_offset(env);
                if (env->module->global_vars->links[delta]){
                    link_free(env->module->global_vars->links[delta]);
                }
                env->module->global_vars->links[delta] = link_dup( stack_peek(stack) );
                break;

            case STORE_VAR:
                delta = read_offset(env);

                if (env->local->links[delta]){
                    link_free(env->local->links[delta]);
                }
            
                env->local->links[delta] = link_dup( stack_peek(stack) );
                break;

            case STORE_CHILD:
                link        = stack_pop(stack); // value
                child_key   = stack_pop(stack); // key to find the child
                parent      = stack_pop(stack); // parent to look in
                pusher = object_addChild(parent, link, child_key);
                goto STORE_COMMON;

            case STORE_ATTR:
                link           = stack_pop(stack); // value
                child_key      = stack_pop(stack); // key to find the child
                parent         = stack_pop(stack); // parent to look in
                pusher = addAttr(parent, link,child_key);
                goto STORE_COMMON;
                
            STORE_COMMON:
                if (! pusher){
                    pusher = exception("AssignError", NULL, NULL);
                    link_free(link);
                }
            
                link_free(child_key);
                link_free(parent);
                break;

            case LT:
                delta = compare(env);
                pusher = create_numberi( (delta < 0)  ? 1 : 0 );
                break;

            case GT:
                delta = compare(env);
                pusher = create_numberi( (delta > 0)  ? 1 : 0 );
                break;

            case EQ:
                delta = compare(env);
                pusher = create_numberi( (delta == 0)  ? 1 : 0 );
                break;

            case NE:
                delta = compare(env);
                pusher = create_numberi( (delta == 0)  ? 0 : 1 );
                break;

            case LE:
                delta = compare(env);
                pusher = create_numberi( (delta <= 0)  ? 1 : 0 );
                break;

            case GE:
                delta = compare(env);
                pusher = create_numberi( (delta >= 0)  ? 1 : 0 );
                break;
        
            case CMP:
                delta = compare(env);
                pusher = create_numberi( delta );
                break;
            
            case OR:
            case AND:
                break;

            case SUB:
                b = stack_pop(env->stack);
                link = stack_pop(env->stack);
            
                if ( (link->type == Global->number_type) && (link->type == b->type)){
                    pusher = create_number(link->value.number - b->value.number);
                    link_free(link);
                    link_free(b);
                    break;
                }            
            
                pusher = object_op_minus(link,b);
                link_free(link);
                link_free(b);
            
                break;
            
            case ADD:
                b = stack_pop(env->stack);
                link = stack_pop(env->stack);
            
                if ( (link->type == Global->number_type) && (link->type == b->type)){
                    pusher = create_number(link->value.number + b->value.number);
                    link_free(link);
                    link_free(b);
                    break;
                }            
            
                pusher = object_op_plus(link,b);
                link_free(link);
                link_free(b);
                
                break;
                        
            case DIV:
                binary_op(env , object_op_divide);
                break;
            
            case MULT:
                binary_op(env , object_op_multiply);
                break;
            
            case MOD:
                binary_op(env , object_op_modulus);
                break;
            
            case POW:
                binary_op(env , object_op_power);
                break;
            
            case NEG:
                unary_op(env, object_op_neg);
                break;
            
            case NOT:
                link = stack_pop(stack);
                pusher = create_numberi(  (object_is_true(link))  ?  0 : 1 );
                link_free(link);
                break;

            case TEST:
            case ELSE:
                break;

            case DO:
                delta = read_offset(env);
                link  = codeblock_literal2( env->function->value.codeblock->parent, delta  );
                if (env->function->value.codeblock->lexicals) {
                    lexicals_attach( env->function->value.codeblock->lexicals, link);
                }
                env = callenv_new_doblock(env,link);
                break;
            
            case PUSH_ARRAY:
                delta = read_offset(env);
                pusher =  array_new_subarray( stack , delta);
                break;
                
            case CALL:
                link   = stack_pop(stack);     // the arguments in an array
                b      = stack_pop(stack);     // the function that gets called
                parent = link_dup(env->This);  // caller
                goto CALL_COMMON;

            
            case CALL_ATTR:            
                link       = stack_pop(stack);    // arguments
                child_key  = stack_pop(stack);    // name of the function
                parent     = stack_pop(stack);    // caller
                b = getAttr(parent,child_key); // the function that gets called           
                link_free(child_key); // no longer need the attributes key
            
                if (! b) {
                    pusher = exception("AttrNotFound", NULL, NULL);
                    break;
                }
                goto CALL_COMMON;
                
            case CALL_CHILD:
                link       = stack_pop(stack);     // ARG
                child_key  = stack_pop(stack);
                parent     = stack_pop(stack);     // THIS
                b = object_getChild(parent,child_key);
                link_free(child_key);
                goto CALL_COMMON;

            CALL_COMMON:
                /* function type so we can call it inline */
                if (b->type == Global->function_type){
                    env = callenv_new_function(env, b, parent, link); // ce , func,this, arg

                /* Not a CodeBlock so we have to use its virtual call function */
                }else{
                    pusher = object_call(b,  parent, link);// function, caller, args
                    link_free(link);
                    if (parent) link_free(parent);
                    link_free(b);
                    if (! pusher) pusher = object_create(Global->null_type);
                }
                break;

            case DEL_CHILD:
                child_key      = stack_pop(stack); // key to find the child
                parent         = stack_pop(stack); // parent to look in

                /* delete child from container */
                pusher = object_delChild(parent,child_key);
                if (! pusher) pusher = exception("ChildNotFound", object_getString(child_key), NULL);
                        
                link_free(child_key);
                link_free(parent);
                break;                
                
            case DEL_ATTR:
                child_key      = stack_pop(stack); // key to find the child
                parent         = stack_pop(stack); // parent to look in

                /* delete attr from container */
                pusher = delAttr(parent,child_key);
                if (! pusher) pusher = exception("AttrNotFound", object_getString(child_key), NULL);

                link_free(child_key);
                link_free(parent);
                break;                
                
            case GET_CHILD:
                child_key      = stack_pop(stack); // key to find the child
                parent         = stack_pop(stack); // parent to look in

                pusher = object_getChild(parent, child_key);            
                if (! pusher) pusher = exception("ChildNotFound", object_getString(child_key), NULL);

                link_free(parent);
                link_free(child_key);
                break;

            case GET_ATTR:
                child_key      = stack_pop(stack); // key to find the child
                parent         = stack_pop(stack); // parent to look in

                pusher = getAttr(parent, child_key);
                if (! pusher) pusher = exception("AttrNotFound", object_getString(child_key), NULL);

                link_free(parent);
                link_free(child_key);
                break;

            case TRAP:
                break;

            case CLEAR:
                for ( delta = stack_length( stack ) ; delta > env->stack_offset ; delta--){
                    link_free( stack_pop(stack) );    
                }    
                break;
            
            case STOP:
                break;

            done:
            case END:
                for ( delta = stack_length( stack ) ; delta > env->stack_offset ; delta--){
                    link_free( stack_pop(stack) );    
                }    
                addBacktrace(pusher, env->function, env->linenum);
                env = callenv_free(env);

                if (! env) goto end;
                
                if (! pusher) pusher = object_create(Global->null_type);
                break;

            /* JUMPS */
            case JIT:  /* Jump if true */
                delta = read_offset(env);
                link = stack_peek(stack);
                if ( link->type->is_true(link) )  env->current = env->start+delta;
                break;

            case JIF:  /* Jump if false */
                delta = read_offset(env);
                link = stack_peek(stack);
                if ( ! link->type->is_true(link) )  env->current = env->start+delta;
                break;
                

            case JIF_POP:  /* Pop value then jump if value is false,  */
                delta = read_offset(env);
                link = stack_pop(stack);
                if ( ! link->type->is_true(link) )  env->current = env->start+delta;
                link_free(link);
                break;
                
            case JUMP:  /* Absolute jump */
                delta = read_offset(env);
                env->current = env->start + delta;
                break;

            case JINC: /* Jump If Not Critical */
                delta = read_offset(env);
                env->current = env->start+delta;
                break;
                
              jinc_critical:
                delta = read_offset(env);
            
                if (trapped) link_free(trapped);
                trapped = pusher->value.link;
                pusher->value.link = NULL;
                link_free(pusher);
                pusher = NULL;
                break;

            case PUSH_NULL:
                pusher = create_null();
                break;

            case PUSH_NUM:
                pusher = create_number( *((number_t *)env->current) );
                env->current+= sizeof(number_t);
                break;
            
            case PUSH_STR:
                delta = read_offset(env);
                pusher = create_string_literal( env->start + delta  );
                break;

            case PUSH_GVAR:
                delta = read_offset(env);
                pusher = link_dup(env->module->global_vars->links[delta]);
            
                if (! pusher){
                    pusher = exception("GlobalVariableUsedBeforeSet",NULL,NULL);
                }
                break;
            
            case PUSH_VAR:
                delta = read_offset(env);
             
                pusher = link_dup(env->local->links[delta]);
                
                if (! pusher){
                    pusher = exception("VariableUsedBeforeSet",NULL,NULL);;
                }
                break;
            
            case PUSH_BLOCK:
                delta = read_offset(env);
                pusher  = codeblock_literal2( env->function->value.codeblock->parent, delta  );
                if (env->function->value.codeblock->lexicals) {
                    lexicals_attach( env->function->value.codeblock->lexicals, pusher);
                }
                break;

            case PUSH_SYS:
                pusher = link_dup(Global->SYS_MODULE);
                break;
            
            case PUSH_MODULE:
                pusher = link_dup( env->function->value.codeblock->parent);
                break;
            
            case TYPEOF:
                link = stack_pop(stack);
                pusher = link_dup( link->type->type_link);
                link_free(link);
                break;
            
            case PUSH_THIS:
                pusher = link_dup(env->This);
                break;

            case PUSH_SELF:
                pusher = link_dup(env->Self);
                break;
            
            case PUSH_ARGS:
                pusher = link_dup(env->Arg);
                break;

            case PUSH_TRAPPED:
                pusher = trapped ? link_dup(trapped) : object_create(Global->null_type);
                break;
            
            case POP:
                link_free( stack_pop(stack) );
                break;

            case LINE:
                env->linenum = read_offset(env);
                break;

            default:
                fprintf(stderr," UNRECOGNIZED OPCODE ERROR %i\n", *(env->current));
                fprintf(stderr,"     near line %i\n", (int)(env->linenum));
                exit(1);
                break;
        }
                
        if (pusher) {
            
            if ( is_critical( pusher ) ){
                if ( *(env->current) == JINC)  goto jinc_critical;
                goto done;
            }
            
            stack_push(stack , pusher);
            pusher = NULL;
        }
        
    }

    end:

    if (trapped) link_free(trapped);
    return pusher;
}
int cgiMain()
{
	int retLogin=0,ResponseCode= 0;
	unsigned short reqID = 0;
	FILE * fpOut = cgiOut;
	char  WISPrVersion[MAX_EAG_WISPR_VERSION_LEN+1] = {0};
	STUserInfo userInfo;
	STAuthProcess stAuth;
	UINT32 userip = 0;
	char userip_str[32]="";
	int ret;
	UINT32 timeout = DEFAULT_PORTAL_REQ_TIMEOUT;
	char timeout_str[32];
	char *ReplyMessage = NULL;
	char *RedirectionURL = NULL;
	UINT32 MaxSessionTime = 0;
	
	memset(&stAuth, 0, sizeof(STAuthProcess));

	cgi_auth_init(&stAuth, 2000);
	memset(&userInfo, 0 ,sizeof(STUserInfo));
	
	ret = cgiFormStringNoNewlines("WISPrVersion", WISPrVersion, MAX_EAG_WISPR_VERSION_LEN);
	if (cgiFormNotFound == ret) {
		strcpy(WISPrVersion,"1");
	}
	cgiFormStringNoNewlines("UserName", userInfo.usrName, MAX_EAG_LOGIN_NAME_LEN);
	cgiFormStringNoNewlines("Password", userInfo.usrPass, MAX_EAG_LOGIN_PASS_LEN);

	memset (userip_str, 0, sizeof(userip_str) );
	ret = cgiFormStringNoNewlines("UserIP", userip_str, sizeof(userip_str));
	if( cgiFormNotFound == ret ){
		fprintf(stderr,"UserIP not find! use cgiRemoteAddr=%s\n",cgiRemoteAddr);
		strncpy (userip_str, cgiRemoteAddr, sizeof(userip_str)-1);		
	}
	userip = htonl(inet_addr(userip_str));

	if (0 == userip) {
		fprintf(stderr, "user ip is 0!!\n" );
	}
	
	ret = cgiFormStringNoNewlines("TimeOut", timeout_str, sizeof(timeout_str)-1);
	if (cgiFormSuccess == ret) {
		timeout = atoi(timeout_str);
		if (timeout<MIN_PORTAL_REQ_TIMEOUT || timeout>MAX_PORTAL_REQ_TIMEOUT) {
			timeout = DEFAULT_PORTAL_REQ_TIMEOUT;
		}
	}
	fprintf(stderr,"login WISPrVersion:%s,UserName:%s,Password=%s.\n",WISPrVersion,userInfo.usrName,userInfo.usrPass);
		
	/*after challege exchange*/
	stAuth.pSendPkg = createPortalPkg(REQ_AUTH);
	fprintf(stderr,"login createPortalPkg suc\n" );
	
	/*malloc STPortalPkg ready to rev data*/
	stAuth.pRevPkg = (STPortalPkg * )malloc(sizeof(STPortalPkg));
	memset(stAuth.pRevPkg, 0, sizeof(STPortalPkg));

	stAuth.protocal = AUTH_PAP;
	setAuthType(stAuth.pSendPkg, stAuth.protocal);
	setRequireID(stAuth.pSendPkg, reqID );
	setPkgUserIP( stAuth.pSendPkg, userip );
	
	addAttr( &stAuth.pSendPkg, ATTR_USERNAME, userInfo.usrName, strlen(userInfo.usrName) );
	
	fprintf(stderr,"userInfo.usrPass=%s",userInfo.usrPass);
	addAttr( &stAuth.pSendPkg, ATTR_PASSWORD, userInfo.usrPass, strlen(userInfo.usrPass) );
	
	if(sendPortalPkg(stAuth.fd, (timeout+1)/2, 2000, cgiServerName, stAuth.pSendPkg) < 0 )
	{
		fprintf(stderr,"login sendPortalPkg failed\n" );
		retLogin = -1;
	}
	else
	{
		fprintf(stderr,"login sendPortalPkg suc\n" );
	}
	
	if(getPortalPkg(stAuth.fd, timeout/2, &(stAuth.pRevPkg))<0)
	{
		fprintf(stderr,"login getPortalPkg failed\n" );
		retLogin = -1;
	}
	else
	{
		fprintf(stderr,"login getPortalPkg suc\n" );
		retLogin = getErrCode(stAuth.pRevPkg);
	}
	
	fprintf(stderr,"login getErrCode(stAuth.pRevPkg)=%d\n", retLogin );

//		WISPr response
//		<MessageType>120</MessageType>	//Required
//		<ResponseCode>{Response Code}</ResponseCode>	//Required
//		<ReplyMessage>{Reply Message Text}</ReplyMessage>	//Conditional Required
//		<LogoffURL>http[s]:/*{site specific logoffURL}*/</LogoffURL>	//Conditional Required
//		<RedirectionURL>http[s]:/*{redirection URL}*/</RedirectionURL>	//Optional
//		<StatusURL>http[s]:/*{status URL}*/</StatusURL>	//Conditional Required
//		<MaxSessionTime>{Maximum Session Time}</MaxSessionTime>
	switch(retLogin){
		case 0:
			ResponseCode=50;	//Login succeeded (Access ACCEPT)
			break;
		case 1:
			ResponseCode=100;	//Login failed (Access REJECT)
			break;
#if 0				
		case:
			ResponseCode=102;	//Authentication server error/timeout
			break;
		case:
			ResponseCode=105;	//Network Administrator Error: No authentication server enabled
			break;
		case:
			ResponseCode=252;	//Invalid state for WISPr request
			break;
		case:
			ResponseCode=253;	//MTU of AAA message is too big
			break;
		case:
			ResponseCode=254;	//Protocol error
			break;
		case:
			ResponseCode=255;	//Access gateway internal error
			break;
#endif				
		default:
			ResponseCode=100;
			fprintf(stderr,"login err retcode(%d) not found!",retLogin);
			break;
	}
/*html pre*/
	cgiHeaderContentType("text/html");
	fprintf( fpOut, "<html xmlns=\"http://www.w3.org/1999/xhtml\"> \n" );
	fprintf( fpOut, "<head> \n" );
#if 0	
	fprintf( fpOut, "<meta http-equiv=\"Content-Type\" content=\"text/html;\" charset=\"gb2312\"> \n" );


  	fprintf( fpOut, "<META   HTTP-EQUIV=\"pragma\"   CONTENT=\"no-cache\"> \n");
  	fprintf( fpOut, "<META   HTTP-EQUIV=\"Cache-Control\"   CONTENT=\"no-cache\"> \n" );
  	fprintf( fpOut, "<META   HTTP-EQUIV=\"expires\"   CONTENT=\"0\">\n");
#endif

	fprintf( fpOut, "<title>login_proc</title> \n");
	fprintf( fpOut, "</head> \n" );
	fprintf( fpOut, "<body> \n");
/*xml */	
	fprintf( fpOut, "<!-- \n" );
	fprintf( fpOut, "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n" );
	fprintf( fpOut, "<WISPAccessGatewayParam  \n"
					"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n"
					"xsi:noNamespaceSchemaLocation=\"http://www.acmewisp.com/WISPAccessGatewayParam.xsd\"> \n" );
	fprintf( fpOut, "  <AuthenticationReply> \n");
	fprintf( fpOut, "    <MessageType>120</MessageType> \n    <ResponseCode>%d</ResponseCode> \n",ResponseCode);
	if (ReplyMessage && strlen(ReplyMessage)>0){
		fprintf( fpOut, "    <ReplyMessage>%s</ReplyMessage> \n",ReplyMessage);
	}else if (0 != retLogin) {
		fprintf( fpOut, "    <ReplyMessage>Login Failed.Please check your username and password!</ReplyMessage> \n" );
	}
	fprintf( fpOut, "    <LogoffURL>%s://%s:%s/wispr/logout?UserIP=%s</LogoffURL> \n",
						urlprefix,cgiServerName, cgiServerPort, userip_str );
	if (RedirectionURL && strlen(RedirectionURL)>0){
		fprintf( fpOut,	"    <RedirectionURL>%s</RedirectionURL> \n",RedirectionURL);
	}
#if 0	
	fprintf( fpOut, "    <StatusURL>%s://%s:%s/wispr/status?UserIP=%s</StatusURL> \n",
						urlprefix,cgiServerName, cgiServerPort, userip_str );
#endif
	if (MaxSessionTime) {
		fprintf( fpOut,	"    <MaxSessionTime>%u</MaxSessionTime> \n",MaxSessionTime);
	}
	fprintf( fpOut, "  </AuthenticationReply>\n</WISPAccessGatewayParam> \n" );
	
	destroyPortalPkg(stAuth.pSendPkg);
	destroyPortalPkg(stAuth.pRevPkg);
	fprintf( fpOut, "--> \n" );	
/*xml  end*/
#if 0
	if ( 0 == retLogin ){
		fprintf( fpOut, "login successful!\n" );
	}
	if (ReplyMessage && strlen(ReplyMessage)>0){
		fprintf( fpOut, "ReplyMessage=%s\n",ReplyMessage );
	}

#endif	           
/**/
	  
	fprintf( fpOut, "</body>\n" );
	fprintf( fpOut, "</html>\n" );

	/* adding aff_ack_auth package	*/
	// err_code=0 means ack-auth normal succeed
	if (0 == retLogin ) { 
		/*after auth exchange*/
		stAuth.pSendPkg = createPortalPkg(AFF_ACK_AUTH);
		
		/*malloc STPortalPkg ready to rev data*/
		stAuth.pRevPkg = (STPortalPkg * )malloc(sizeof(STPortalPkg));
		memset(stAuth.pRevPkg, 0, sizeof(STPortalPkg));
		
		setAuthType(stAuth.pSendPkg, stAuth.protocal);
		setRequireID(stAuth.pSendPkg, reqID );
		setPkgUserIP( stAuth.pSendPkg, htonl(inet_addr(cgiRemoteAddr)) );
	
		if(sendPortalPkg(stAuth.fd, 3, 2000, cgiServerName, stAuth.pSendPkg) < 0 )
		{
			fprintf(stderr,"auth sendPortalPkg failed\n" );
			retLogin = -1;
		}
		else
		{
			fprintf(stderr,"auth sendPortalPkg suc\n" );
		}
	
		destroyPortalPkg(stAuth.pSendPkg);
		destroyPortalPkg(stAuth.pRevPkg);
	}


	return 0;
}
Exemple #16
0
 ATTR& obtainAttr()  
 {ATTR* a; _attributes.findClass(a); if (!a) addAttr(a = new ATTR); return *a;}
Exemple #17
0
UTreebox::UTreebox(const UArgs& a) : UListbox(a) {
  choice().setSelectionRule(is_selectable_by_tree);
  addAttr(UBorder::none);
}
Exemple #18
0
int
main(int argc, char *argv[])
{
	type_code attrType = B_STRING_TYPE;
	char *attrValue = NULL;
	size_t valueFileLength = 0;
	bool resolveLinks = true;

	int c;
	while ((c = getopt_long(argc, argv, "hf:t:P", kLongOptions, NULL)) != -1) {
		switch (c) {
			case 0:
				break;
			case 'f':
			{
				// retrieve attribute value from file
				BFile file;
				off_t size;
				status_t status = file.SetTo(optarg, B_READ_ONLY);
				if (status < B_OK) {
					ERR("can't read attribute value from file %s: %s\n",
						optarg, strerror(status));
					return 1;
				}
		
				status = file.GetSize(&size);
				if (status == B_OK) {
					if (size == 0) {
						ERR_0("attribute value is empty: 0 bytes\n");
						return 1;
					}
					if (size > 4 * 1024 * 1024) {
						ERR("attribute value is too large: %" B_PRIdOFF
							" bytes\n", size);
						return 1;
					}
					attrValue = (char *)malloc(size);
					if (attrValue != NULL)
						status = file.Read(attrValue, size);
					else
						status = B_NO_MEMORY;
				}
		
				if (status < B_OK) {
					ERR("can't read attribute value: %s\n", strerror(status));
					return 1;
				}
		
				valueFileLength = (size_t)size;
				break;
			}
			case 't':
				// Get the attribute type
				if (typeForString(optarg, &attrType) != B_OK)
					invalidAttrType(optarg);
				break;
			case 'P':
				resolveLinks = false;
				break;
			case 'h':
				usage(0);
				break;
			default:
				usage(1);
				break;
		}
	}
	
	if (argc - optind < 1)
		usage(1);
	const char *attrName = argv[optind++];

	if (argc - optind < 1)
		usage(1);
	if (!valueFileLength)
		attrValue = argv[optind++];

	if (argc - optind < 1)
		usage(1);

	// Now that we gathered all the information proceed
	// to add the attribute to the file(s)

	int result = 0;

	for (; optind < argc; optind++) {
		status_t status = addAttr(argv[optind], attrType, attrName, attrValue,
			valueFileLength, resolveLinks);

		// special case for bool types
		if (status == B_BAD_VALUE && attrType == B_BOOL_TYPE)
			invalidBoolValue(attrValue);

		if (status != B_OK) {
			ERR("can't add attribute to file %s: %s\n", argv[optind],
				strerror(status));

			// proceed files, but return an error at the end
			result = 1;
		}
	}

	if (valueFileLength)
		free(attrValue);

	return result;
}
Exemple #19
0
void *JabberAdd::processEvent(Event *e)
{
    if (e->type() == EventDiscoItem){
        DiscoItem *item = (DiscoItem*)(e->param());
        if (m_id_browse == item->id){
            if (item->jid.empty()){
                if (!item->node.empty()){
                    QString url;
                    if (m_client->getUseVHost())
                        url = QString::fromUtf8(m_client->getVHost());
                    if (url.isEmpty())
                        url = QString::fromUtf8(m_client->getServer());
                    m_id_disco  = m_client->discoItems(url.utf8(), "");
                }
                m_id_browse = "";
                checkDone();
                return e->param();
            }
            addSearch(item->jid.c_str(), "", item->features.c_str(), item->type.c_str());
            return e->param();
        }
        if (m_id_disco == item->id){
            if (item->jid.empty()){
                m_id_disco = "";
                checkDone();
                return e->param();
            }
            ItemInfo info;
            info.jid  = item->jid;
            info.node = item->node;
            info.id   = m_client->discoInfo(info.jid.c_str(), info.node.c_str());
            m_disco_items.push_back(info);
            return e->param();
        }
        list<ItemInfo>::iterator it;
        for (it = m_disco_items.begin(); it != m_disco_items.end(); ++it){
            if ((*it).id == item->id){
                addSearch((*it).jid.c_str(), (*it).node.c_str(), item->features.c_str(), item->type.c_str());
                m_disco_items.erase(it);
                checkDone();
                break;
            }
        }
    }
    if (e->type() == EventAgentInfo){
        JabberAgentInfo *data = (JabberAgentInfo*)(e->param());
        list<AgentSearch>::iterator it;
        for (it = m_agents.begin(); it != m_agents.end(); ++it)
            if ((*it).id_info == data->ReqID.ptr)
                break;
        if (it == m_agents.end())
            return NULL;
        if (data->Type.ptr == NULL){
            (*it).id_info = "";
            if (m_first.isEmpty())
                (*it).fill |= FILL_FIRST;
            if (m_last.isEmpty())
                (*it).fill |= FILL_LAST;
            if (m_nick.isEmpty())
                (*it).fill |= FILL_NICK;
            if (m_mail.isEmpty())
                (*it).fill |= FILL_MAIL;
            if ((*it).fill != FILL_ALL){
                m_agents.erase(it);
                checkDone();
                return e->param();;
            }
            (*it).id_search = m_client->search((*it).jid.c_str(), (*it).node.c_str(), (*it).condition.utf8());
            if ((*it).condition.left(6) != "x:data"){
                addAttr("", i18n("JID"));
                addAttr("first", i18n("First name"));
                addAttr("last", i18n("Last name"));
                addAttr("nick", i18n("Nick"));
                addAttr("email", i18n("E-Mail"));
                addAttrs();
            }
            return e->param();
        }
        if (!strcmp(data->Type.ptr, "x")){
            (*it).condition = "x:data";
            (*it).fill = 0;
            return e->param();
        }
        QString value;
        QString field;
        if (data->Field.ptr &&
                (!strcmp(data->Type.ptr, "text-single") ||
                 !strcmp(data->Type.ptr, "text-private") ||
                 !strcmp(data->Type.ptr, "text-multi"))){
            field = data->Field.ptr;
            if (!strcmp(data->Field.ptr, "first") && !m_first.isEmpty()){
                value = m_first;
                (*it).fill |= FILL_FIRST;
            }
            if (!strcmp(data->Field.ptr, "last") && !m_last.isEmpty()){
                value = m_last;
                (*it).fill |= FILL_LAST;
            }
            if ((!strcmp(data->Field.ptr, "nickname") || !strcmp(data->Field.ptr, "nick")) && !m_nick.isEmpty()){
                value = m_nick;
                (*it).fill |= FILL_NICK;
            }
            if (!strcmp(data->Field.ptr, "email") && !m_mail.isEmpty()){
                value = m_mail;
                (*it).fill |= FILL_MAIL;
            }
        }
        if (!strcmp(data->Type.ptr, "first") && !m_first.isEmpty()){
            field = data->Type.ptr;
            value = m_first;
            (*it).fill |= FILL_FIRST;
        }
        if (!strcmp(data->Type.ptr, "last") && !m_last.isEmpty()){
            field = data->Type.ptr;
            value = m_last;
            (*it).fill |= FILL_LAST;
        }
        if ((!strcmp(data->Type.ptr, "nickname") || !strcmp(data->Type.ptr, "nick")) && !m_nick.isEmpty()){
            field = data->Type.ptr;
            value = m_nick;
            (*it).fill |= FILL_NICK;
        }
        if (!strcmp(data->Type.ptr, "email") && !m_mail.isEmpty()){
            field = data->Type.ptr;
            value = m_mail;
            (*it).fill |= FILL_MAIL;
        }
        if (!value.isEmpty()){
            if (!(*it).condition.isEmpty())
                (*it).condition += ";";
            (*it).condition += field;
            (*it).condition += "=";
            (*it).condition += quoteChars(value, ";");
        }
        return e->param();
    }
    if (e->type() == EventSearch){
        JabberSearchData *data = (JabberSearchData*)(e->param());
        list<AgentSearch>::iterator it;
        for (it = m_agents.begin(); it != m_agents.end(); ++it)
            if ((*it).id_search == data->ID.ptr)
                break;
        if (it == m_agents.end())
            return NULL;
        if (data->JID.ptr == NULL){
            addAttr("", i18n("JID"));
            for (unsigned i = 0; i < data->nFields.value; i++){
                addAttr(get_str(data->Fields, i * 2), get_str(data->Fields, i * 2 + 1));
                (*it).fields.push_back(get_str(data->Fields, i * 2));
            }
            addAttrs();
            return e->param();
        }
        QString icon = "Jabber";
        if ((*it).type == "icq"){
            icon = "ICQ";
        }else if ((*it).type == "aim"){
            icon = "AIM";
        }else if ((*it).type == "msn"){
            icon = "MSN";
        }else if ((*it).type == "yahoo"){
            icon = "Yahoo!";
        }
        if (data->Status.ptr){
            if (!strcmp(data->Status.ptr, "online")){
                icon += "_online";
            }else{
                icon += "_offline";
            }
        }
        QStringList l;
        l.append(icon);
        l.append(QString::fromUtf8(data->JID.ptr));
        for (unsigned i = 0; i < m_fields.size(); i++){
            QString v;
            if (m_fields[i] == ""){
                v = QString::fromUtf8(data->JID.ptr);
            }else if ((m_fields[i] == "first") && data->First.ptr){
                v = QString::fromUtf8(data->First.ptr);
            }else if ((m_fields[i] == "last") && data->Last.ptr){
                v = QString::fromUtf8(data->Last.ptr);
            }else if ((m_fields[i] == "nick") && data->Nick.ptr){
                v = QString::fromUtf8(data->Nick.ptr);
            }else if ((m_fields[i] == "email") && data->EMail.ptr){
                v = QString::fromUtf8(data->EMail.ptr);
            }else{
                for (unsigned n = 0; n < (*it).fields.size(); n++){
                    if ((*it).fields[n] == m_fields[i]){
                        v = QString::fromUtf8(get_str(data->Fields, n));
                        break;
                    }
                }
            }
            l.append(v);
        }
        emit addItem(l, this);
    }
    if (e->type() == EventSearchDone){
        const char *id = (const char*)(e->param());
        list<AgentSearch>::iterator it;
        for (it = m_agents.begin(); it != m_agents.end(); ++it)
            if ((*it).id_search == id)
                break;
        if (it == m_agents.end())
            return NULL;
        m_agents.erase(it);
        checkDone();
        return e->param();
    }
    return NULL;
}