MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / l_siplua_getRoute

Function l_siplua_getRoute

modules/lua/sipapi.c:304–370  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

302}
303
304static int l_siplua_getRoute(lua_State *L)
305{
306 struct sipapi_object *o;
307 rr_t *rt;
308 str uri;
309 struct sip_uri puri;
310 int n = 1;
311
312 o = luaL_checkudata(L, 1, "siplua.api");
313 if (parse_headers(o->msg, HDR_ROUTE_F, 0) == -1)
314 return luaL_error(L, "failed to parse headers");
315 if (!o->msg->route)
316 {
317 lua_pushnil(L);
318 return 1;
319 }
320 if (parse_rr(o->msg->route) < 0)
321 return luaL_error(L, "failed to parse route HF");
322 lua_newtable(L);
323 for (rt = (rr_t *)o->msg->route->parsed; rt; rt = rt->next )
324 {
325 uri = rt->nameaddr.uri;
326 lua_pushinteger(L, n++);
327 lua_newtable(L);
328 lua_pushliteral(L, "uri");
329 lua_pushlstring(L, uri.s, uri.len);
330 lua_rawset(L, -3);
331 if (parse_uri(uri.s, uri.len, &puri) < 0)
332 {
333 if (n == 1)
334 return luaL_error(L, "failed to parse the first route URI");
335 continue;
336 }
337 lua_pushliteral(L, "user");
338 lua_pushlstring(L, puri.user.s, puri.user.len);
339 lua_rawset(L, -3);
340 lua_pushliteral(L, "host");
341 lua_pushlstring(L, puri.host.s, puri.host.len);
342 lua_rawset(L, -3);
343 lua_pushliteral(L, "port");
344 lua_pushinteger(L, puri.port_no);
345 lua_rawset(L, -3);
346 lua_pushliteral(L, "params");
347 lua_pushlstring(L, puri.params.s, puri.params.len);
348 lua_rawset(L, -3);
349 lua_pushliteral(L, "lr");
350 lua_pushlstring(L, puri.lr.s, puri.lr.len);
351 lua_rawset(L, -3);
352 lua_pushliteral(L, "lr_val");
353 lua_pushlstring(L, puri.lr_val.s, puri.lr_val.len);
354 lua_rawset(L, -3);
355 lua_pushliteral(L, "r2");
356 lua_pushlstring(L, puri.r2.s, puri.r2.len);
357 lua_rawset(L, -3);
358 lua_pushliteral(L, "r2_val");
359 lua_pushlstring(L, puri.r2_val.s, puri.r2_val.len);
360 lua_rawset(L, -3);
361 lua_pushliteral(L, "is_myself");

Callers

nothing calls this directly

Calls 3

parse_rrFunction · 0.85
parse_uriFunction · 0.85
check_selfFunction · 0.85

Tested by

no test coverage detected