Ejemplo n.º 1
0
 __INLINE ElementRef
 ElementRef::getLastChild ()
 {
     AssertBug(getElementPtr(), "Invalid ptr !\n");
     ElementSegment* me = getMe<Read>();
     if (!__doesElementRefHasAttributesAndChildren(me->flags))
     {
         return ElementRef(getDocument());
     }
     __checkElementFlag_HasAttributesAndChildren(me->flags);
     return ElementRef(getDocument(), me->attributesAndChildren.lastChildPtr);
 }
Ejemplo n.º 2
0
ElementRef Box::getEdge(ElementRef p1, ElementRef p2) const {
  Coord coord(p1,p2);
  if (coords2edges.find(coord) == coords2edges.end()) {
    return ElementRef();
  }
  return coords2edges.at(coord);
}
Ejemplo n.º 3
0
    __INLINE ElementRef
    ElementRef::getFather ()
    {
        if (getElementPtr() == getDocument().rootElementPtr)
        {
            return ElementRef(getDocument());
        }
        ElementRef father( document, getMe<Read>()->fatherPtr);
#ifdef __XEM_DOM_NODEREF_CHROOT_USING_XEMINT_ROOT
        if ( 0 && father && father.getKeyId() == getKeyCache().getBuiltinKeys().xemint.root())
        {
            return ElementRef(getDocument(), 0);
        }
#endif // __XEM_DOM_NODEREF_CHROOT_USING_XEMINT_ROOT
        return father;
    }
Ejemplo n.º 4
0
// class NeighborIndex
NeighborIndex::NeighborIndex(const Set &edgeSet) {
  VertexToEdgeIndex VToE(edgeSet);

  //number of vertices per edge
  unsigned cardinality = edgeSet.getCardinality();

  const Set* vSet = edgeSet.getEndpointSet(0);
  startIndex = (int*)malloc(sizeof(int) * (vSet->getSize()+1));
  startIndex[0] = 0;
  for(auto v : *vSet){
    std::set<int> edgeNeighbors = VToE.getWhichEdgesForElement(v, *vSet);

    std::vector<int> nbr;
    for(int eIdx : edgeNeighbors) {
      for(unsigned jj = 0; jj<cardinality; jj++){
        int nbrIdx = edgeSet.getEndpoint(ElementRef(eIdx), jj).ident;
        addNoCollision(nbrIdx, nbr);
      }
    }
    neighbors.insert(neighbors.end(), nbr.begin(), nbr.end());
    startIndex[v.ident+1] = neighbors.size();
  }

  for (int i=0; i < vSet->getSize(); ++i) {
    std::sort(neighbors.begin()+startIndex[i], neighbors.begin()+startIndex[i+1]);
  }
}
Ejemplo n.º 5
0
//-----------------------------------------------------------------------------
//! This function checks if all elements are of the type specified in the argument
bool FECoreMesh::IsType(int ntype)
{
	int NE = Elements();
	for (int i=0; i<NE; ++i)
	{
		FEElement_& el = ElementRef(i);
		if (el.GetType() != ntype) return false;
	}
	return true;
}
Ejemplo n.º 6
0
VOID CXElement::_SendXMsg( IXMsg& pMsg )
{
	if (pMsg.msgPolicy==MsgDispatchPolicy::Processor && pMsg.msgHandled)
	{
		return;
	}

	switch (pMsg.msgDirection)
	{
	case MsgDirection::UpToRoot:
	case MsgDirection::UpToRootThenDown:
		if (m_father)
		{
			ElementRef(XNodeRef(m_father))->ProcessXMessage(pMsg);
		}
		else
		{
			if (pMsg.msgDirection == MsgDirection::UpToRootThenDown)
			{
				pMsg.msgDirection = MsgDirection::Down;
				_SendXMsg(pMsg);
			}
		}
		break;
		break;
	case MsgDirection::Down:
		for (auto i=m_children.begin(); i!=m_children.end(); ++i)
		{
			if (pMsg.msgPolicy==MsgDispatchPolicy::Processor && pMsg.msgHandled)
			{
				return;
			}
			XSmartPtr<CXElement> pElement = *i;
			pElement->ProcessXMessage( pMsg );
		}
		break;
	default:
		WTF;
		break;
	}
}
Ejemplo n.º 7
0
  void QueryDocument::parseQuery ( XProcessor& xproc, bool isQuery )
  {
    ElementRef cookiesList = queryElement.getDocument().createElement ( queryElement, xem_web.cookies() );
    queryElement.appendLastChild ( cookiesList );

    ElementRef headersList = queryElement.getDocument().createElement ( queryElement, xem_web.headers() );
    queryElement.appendLastChild ( headersList );

    QParseState state = QParseState_HeadLine;
    String accu = "";
    String method;
    ElementRef headerElement(*this);
    ElementRef responseElement(*this);
    ElementRef urlElement(*this);
    ElementRef urlParams(*this);
    ElementRef urlParam(*this);
    ElementRef cookieElement(*this);

    __ui64 contentLength = 0;
    bool transferEncodingChunked = false;

#define Invalid() throwException(Exception, "Invalid character %d at state %d\n", r, state );

    while ( state != QParseState_FinishedHTTPHeader && !reader.isFinished())
      {
        int r = reader.getNextChar();
        if ( r >= 0x80 )
          {
            throwException ( Exception, "Invalid char %d\n", r );
          }
        // Log_QParse ( "state=%d, r=%x (%d, %c)\n", state, r, r, r );
        switch ( state )
        {
        case QParseState_HeadLine:
          if ( r == ' ' )
            {
              Log_QParse ( "Method : '%s'\n", accu.c_str() );
              if ( isQuery )
                {
                  if ( accu == "GET" || accu == "POST" )
                    {
                      ElementRef methodElement = addTextualElement ( queryElement, xem_web.method(), accu );
                      method = methodElement.getText();
                      state = QParseState_URLStart;
                      accu = "";
                      continue;
                    }
                  else
                    Invalid();
                }
              else
                {
                  if ( accu == "HTTP/1.1" )
                    {
                      Log_QParse ( "Got a Response, protocol=%s\n", accu.c_str() );
                      addTextualElement ( queryElement, xem_web.protocol(), accu );
                      accu = "";
                      state = QParseState_ResponseCode;
                      responseElement = createElement ( headersList, xem_web.response() );
                      headersList.appendLastChild ( responseElement );
                    }
                  else
                    {
                      Invalid();
                    }
                }
            }
          else if ( r == '\r' || r == '\n' )
            {
              Invalid();
            }
          accu.appendUtf8(r);
          break;
        case QParseState_URLStart:
          if ( r == '/' )
            {
              state = QParseState_URL;
              continue;
            }
          Invalid();
          break;
        case QParseState_URL:
          if ( r == ' ' || r == '?' )
            {
              Log_QParse ( "Url : '%s'\n", accu.c_str() );
              urlElement = createElement ( queryElement, xem_web.url() );
              queryElement.appendLastChild ( urlElement );
              addTextualElement ( urlElement, xem_web.base(), accu );

              accu = "";
              if ( r == ' ' )
                {
                  state = QParseState_Protocol;
                }
              else
                {
                  state = QParseState_URLParam;
                }
              continue;
            }
          else if ( r == '?' )
            {
              Invalid();
            }
          else if ( r == '\r' || r == '\n' )
            {
              Invalid();
            }
          else if ( r == '%' )
            {
              Invalid ();
            }
          accu.appendUtf8(r);
          break;
        case QParseState_URLParam:
          if ( r == '\n' || r == '%' || r == '\r' )
            {
              Invalid();
            }
          else if ( r == '=' || r == ' ' || r == '&' )
            {
              if ( ! urlParams )
                {
                  urlParams = createElement ( urlElement, xem_web.parameters() );
                  urlElement.appendLastChild ( urlParams );
                }
              Log_QParse ( "Param : '%s'\n", accu.c_str() );
              urlParam = createElement ( urlParams, xem_web.param() );
              urlParams.appendLastChild ( urlParam );
              urlParam.addAttr ( xem_web.name(), accu );
              accu = "";
              if ( r == '=' )
                state = QParseState_URLParamValue;
              else if ( r == '&' )
                state = QParseState_URLParam;
              else if ( r == ' ' )
                state = QParseState_Protocol;
              else
                { Invalid(); }
              continue;
            }
          accu.appendUtf8(r);
          break;
        case QParseState_URLParamValue:
          if ( r == '&' || r == ' ')
            {
              Log_QParse ( "Param Value : '%s'\n", accu.c_str() );
              ElementRef valueNode = createTextNode ( urlParam, accu );
              urlParam.appendLastChild ( valueNode );
              urlParam = ElementRef(*this);
              accu = "";
              if ( r == '&' )
                state = QParseState_URLParam;
              else
                state = QParseState_Protocol;
              continue;
            }
          accu.appendUtf8(r);
          break;
        case QParseState_Protocol:
          if ( r == ' ' )
            {
              Invalid();
            }
          else if ( r == '\r' )
            {
              continue;
            }
          else if ( r == '\n' )
            {
              Log_QParse ( "Protocol = '%s'\n", accu.c_str() );
              addTextualElement ( queryElement, xem_web.protocol(), accu );
              accu = "";
              state = QParseState_BeginLine;
              continue;
            }
          accu.appendUtf8(r);
          break;
        case QParseState_ResponseCode:
          if ( r == ' ' )
            {
              Log_QParse ( "ResponseCode : %s\n", accu.c_str() );
              responseElement.addAttr ( xem_web.response_code(), accu );
              accu = "";
              state = QParseState_ResponseString;
              continue;
            }
          if ( '0' <= r && r <= '9' )
            {
              accu.appendUtf8(r);
              continue;
            }
          Invalid();
          break;
        case QParseState_ResponseString:
          if ( r == '\r' )
            continue;
          else if ( r == '\n' )
            {
              Log_QParse ( "ResponseString : %s\n", accu.c_str() );
              responseElement.addAttr ( xem_web.response_string(), accu );
              accu = "";
              state = QParseState_BeginLine;
              continue;
            }
          accu.appendUtf8(r);
          break;
        case QParseState_BeginLine:
          if ( r == '\r' )
            continue;
          else if ( r == '\n' )
            {
              state = QParseState_FinishedHTTPHeader;
              break;
            }
          else if ( r == ' ' )
            {
              Invalid();
            }
          accu.appendUtf8(r);
          state = QParseState_FieldName;
          continue;
        case QParseState_FieldName:
          if ( r == ':' )
            {
              Log_QParse ( "Field : '%s'\n", accu.c_str() );
              if ( accu == "Cookie" )
                {
                  accu = "";
                  state = QParseState_CookieStart;
                  continue;
                }
              headerElement = createElement ( headersList, xem_web.param() );
              headersList.appendLastChild ( headerElement );
              headerElement.addAttr ( xem_web.name(), accu );
              accu = "";
              state = QParseState_PostFieldName;
              continue;
            }
          else if ( r == ' ' || r == '\n' || r == '\r' )
            {
               Invalid();
            }
          accu.appendUtf8(r);
          break;
        case QParseState_PostFieldName:
          if ( r == ' ' )
            {
              state = QParseState_Value;
              continue;
            }
          Invalid();
        case QParseState_Value:
          if ( r == '\r')
            continue;
          else if ( r == '\n' )
            {
              Log_QParse ( "Field value : '%s'\n", accu.c_str() );
              ElementRef valueNode = createTextNode ( headerElement, accu );
              headerElement.appendLastChild ( valueNode );
              String fieldName = headerElement.getAttr(xem_web.name());
#ifdef __XEM_WEBSERVER_QUERYDOCUMENT_HAS_HEADERFIELDSMAP
              headerFieldsMap[fieldName] = valueNode.getText();
#endif
              if ( fieldName == "Content-Length" )
                {
                  contentLength = accu.toUI64();
                  Log_QParse ( "ContentLength : %llu\n", contentLength );
                }
              else if ( fieldName == "Transfer-Encoding" && accu == "chunked" )
                {
                  Log_QParse ( "TransferEncoding chuncked !\n" );
                  transferEncodingChunked = true;
                }
              headerElement = ElementRef(*this);
              accu = "";
              state = QParseState_BeginLine;
              continue;
            }
          accu.appendUtf8(r);
          break;
        case QParseState_CookieStart:
          if ( r == ' ' )
            continue;
          accu.appendUtf8(r);
          state = QParseState_CookieName;
          break;
        case QParseState_CookieName:
          if ( r == '=' )
            {
              Log_QParse ( "Cookie name : '%s'\n", accu.c_str() );
              cookieElement = createElement ( cookiesList, xem_web.cookie() );
              cookieElement.addAttr ( xem_web.name(), accu );
              cookiesList.appendLastChild ( cookieElement );

              accu = "";
              state = QParseState_CookieValue;
              continue;
            }
          accu.appendUtf8(r);
          break;
        case QParseState_CookieValue:
          if ( r == '\r' )
            continue;
          if ( r == ';' || r == '\n' )
            {
              Log_QParse ( "Cookie value : '%s'\n", accu.c_str() );
              ElementRef cookieValueNode = createTextNode ( cookieElement, accu );
              cookieElement.appendLastChild ( cookieValueNode );

              accu = "";
              if ( r == ';' )
                state = QParseState_CookieStart;
              else
                state = QParseState_BeginLine;
              continue;
            }
          accu.appendUtf8(r);
          break;
        default:
          Bug ( "Case %d Not implemented !\n", state );
        }
      }
    if ( state != QParseState_FinishedHTTPHeader )
      {
        throwException ( Exception, "HTTP reader not finished ! state=%d\n", state );
      }
    if ( contentLength || transferEncodingChunked )
      {
        if ( !isQuery || method == "POST" )
          {
            ElementRef content = createElement ( queryElement, xem_web.content() );
            queryElement.appendLastChild ( content );
            BlobRef blob = content.addBlob(xem_web.blob_contents());
            if ( contentLength )
              parseToBlob(blob, contentLength);
            else
              parseChunkedToBlob(blob);
          }
        else
          {
            throwException ( Exception, "Invalid content-length with method = %s\n", method.c_str() );
          }
      }
  }