/* {{{ proto Router Router::setRequest(string method, string uri) Set the request, overriding detection on ::route() */ static PHP_METHOD(Router, setRequest) { const char *request_method = NULL; size_t request_method_length = 0L; const char *request_uri = NULL; size_t request_uri_length = 0L; router_t *router = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &request_method, &request_method_length, &request_uri, &request_uri_length) != SUCCESS) { return; } router = getRouter(); { if (!router->set) { router->set = (route_t*) ecalloc(1, sizeof(route_t)); } else { zval_dtor(&router->set->method); zval_dtor(&router->set->uri); } ZVAL_STRINGL(&router->set->method, request_method, request_method_length, 1); ZVAL_STRINGL(&router->set->uri, request_uri, request_uri_length, 1); } RETURN_CHAIN(); }
void Nlsrc::recordCoordinateLsa(const nlsr::tlv::CoordinateLsa& lsa) { Router& router = getRouter(lsa.getLsaInfo()); std::ostringstream os; os << " Coordinate LSA:" << std::endl; os << getLsaInfoString(lsa.getLsaInfo()) << std::endl; os << " angle=" << lsa.getHyperbolicAngle() << std::endl; os << " radius=" << lsa.getHyperbolicRadius() << std::endl; router.coordinateLsaString = os.str(); }
void Nlsrc::recordNameLsa(const nlsr::tlv::NameLsa& lsa) { Router& router = getRouter(lsa.getLsaInfo()); std::ostringstream os; os << " Name LSA:" << std::endl; os << getLsaInfoString(lsa.getLsaInfo()) << std::endl; for (const auto& name : lsa.getNames()) { os << " name=" << name << std::endl; } router.nameLsaString = os.str(); }
void Nlsrc::recordAdjacencyLsa(const nlsr::tlv::AdjacencyLsa& lsa) { Router& router = getRouter(lsa.getLsaInfo()); std::ostringstream os; os << " AdjacencyLsa:" << std::endl; os << getLsaInfoString(lsa.getLsaInfo()) << std::endl; for (const auto& adjacency : lsa.getAdjacencies()) { os << " adjacency=" << adjacency << std::endl; } router.adjacencyLsaString = os.str(); }
SUMOTime MSDevice_Routing::preInsertionReroute(SUMOTime currentTime) { const MSEdge* source = MSEdge::dictionary(myHolder.getParameter().fromTaz + "-source"); const MSEdge* dest = MSEdge::dictionary(myHolder.getParameter().toTaz + "-sink"); if (source && dest) { const std::pair<const MSEdge*, const MSEdge*> key = std::make_pair(source, dest); if (myCachedRoutes.find(key) == myCachedRoutes.end()) { myHolder.reroute(currentTime, getRouter(), true); myCachedRoutes[key] = &myHolder.getRoute(); myHolder.getRoute().addReference(); } else { myHolder.replaceRoute(myCachedRoutes[key], true); } } return myPreInsertionPeriod; }
/* {{{ proto Router Router::setDefault(Callable handler) Throws RoutingException on failure The default route is invoked for web requests that match no other route */ static PHP_METHOD(Router, setDefault) { zval *callable; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &callable) != SUCCESS) { return; } { char *callable_name = NULL; if (zend_is_callable(callable, 0, &callable_name TSRMLS_CC)) { route_t route = {ROUTER_ROUTE_DEFAULT}; route.callable = callable; Z_ADDREF_P(route.callable); { router_t *router = getRouter(); zend_hash_update( &router->routes, Default_Route, Default_Route_Size, (void**)&route, sizeof(route_t), (void**)&router->fallback); } } else { zend_throw_exception( RoutingException, "handler is not callable", 0 TSRMLS_CC); } if (callable_name) { efree(callable_name); } } RETURN_CHAIN(); } /* }}} */
SUMOTime MSDevice_Routing::wrappedRerouteCommandExecute(SUMOTime currentTime) { myHolder.reroute(currentTime, getRouter()); return myPeriod; }
/* {{{ proto Router Router::addRoute(string method, string uri, Callable handler) proto Router Router::addRoute(Route route) Throws RoutingException on failure */ static PHP_METHOD(Router, addRoute) { const char *request_method = NULL; size_t request_method_length = 0L; const char *request_uri = NULL; size_t request_uri_length = 0L; zval *callable = NULL; zend_class_entry *ce = NULL; router_t *router = getRouter(); switch (ZEND_NUM_ARGS()) { case 3: if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "ssz", &request_method, &request_method_length, &request_uri, &request_uri_length, &callable) != SUCCESS) { return; } break; case 1: if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "O", &callable, ce) != SUCCESS) { return; } break; default: zend_throw_exception( RoutingException, "Router::addRoute expects one or three arguments, please see documentation", 0 TSRMLS_CC); return; } { route_t route = {ROUTER_ROUTE_NORMAL}; route.callable = callable; if (ZEND_NUM_ARGS() == 1) { zval *pmethod = NULL, *puri = NULL; zend_call_method_with_0_params( &callable, ce, NULL, "getMethod", &pmethod); if (Z_TYPE_P(pmethod) != IS_STRING) { zend_throw_exception( RoutingException, "getMethod returned a non-string value", 0 TSRMLS_CC); zval_ptr_dtor(&pmethod); return; } zend_call_method_with_0_params( &callable, ce, NULL, "getURI", &puri); if (Z_TYPE_P(puri) != IS_STRING) { zend_throw_exception( RoutingException, "getURI returned a non-string value", 0 TSRMLS_CC); zval_ptr_dtor(&pmethod); zval_ptr_dtor(&puri); return; } ZVAL_STRINGL(&route.method, Z_STRVAL_P(pmethod), Z_STRLEN_P(pmethod), 1); ZVAL_STRINGL(&route.uri, Z_STRVAL_P(puri), Z_STRLEN_P(puri), 1); Z_ADDREF_P(route.callable); zend_hash_next_index_insert( &router->routes, (void**) &route, sizeof(route_t), NULL); zval_ptr_dtor(&pmethod); zval_ptr_dtor(&puri); } else { char *callable_name = NULL; if (!zend_is_callable(callable, 0, &callable_name TSRMLS_CC)) { zend_throw_exception( RoutingException, "handler is not callable", 0 TSRMLS_CC); if (callable_name) efree(callable_name); return; } ZVAL_STRINGL(&route.method, request_method, request_method_length, 1); ZVAL_STRINGL(&route.uri, request_uri, request_uri_length, 1); Z_ADDREF_P(route.callable); zend_hash_next_index_insert( &router->routes, (void**) &route, sizeof(route_t), NULL); if (callable_name) efree(callable_name); } } RETURN_CHAIN(); } /* }}} */