#include #include "parse_next_hop.h" #include "parse_common.h" #include "log.h" int parse_next_hop(const cstring& next_hop, list& dest_list) { enum { IPL_BEG=0, IPL_HOST, IPL_V6, IPL_HOST_SEP, IPL_PORT, IPL_TRSP }; int st = IPL_BEG; const char* c = next_hop.s; const char* end = c + next_hop.len; const char* beg = NULL; sip_destination dest; for(;c '9'){ DBG("error: unexpected character '%c' in IPL_PORT state.\n",*c); return -1; } dest.port = dest.port*10 + (*c - '0'); break; } break; case IPL_TRSP: switch(*c){ case ',': st = IPL_BEG; dest.trsp.set(beg,c-beg); dest_list.push_back(dest); break; default: if( (*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <= 'Z') ) { continue; } // syntax error DBG("error: unexpected character '%c' in IPL_TRSP state.\n",*c); return -1; } break; } } switch(st){ case IPL_BEG: // no host at all // possibly, the string was empty break; case IPL_HOST: dest.host.set(beg,c-beg); dest_list.push_back(dest); break; case IPL_V6: case IPL_HOST_SEP: case IPL_PORT: dest_list.push_back(dest); break; case IPL_TRSP: dest.trsp.set(beg,c-beg); dest_list.push_back(dest); break; } return 0; }