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

Function trans_load

net/trans.c:83–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81}
82
83int trans_load(void)
84{
85 int id;
86 struct sr_module *mod;
87 const cmd_export_t *cmd;
88 int found_all = 0;
89 int found_proto;
90 api_proto_init abind;
91 struct proto_info pi;
92
93 /* go through all protocol modules loaded and load only the ones
94 * that are prefixed with the PROTO_PREFIX token */
95 for (mod = modules; mod; mod = mod->next) {
96 if (strncmp(PROTO_PREFIX, mod->exports->name, PROTO_PREFIX_LEN) != 0)
97 continue;
98 found_proto = 0;
99 /* we have a transport module here - check for protocols */
100 for (cmd = mod->exports->cmds; cmd && cmd->name; cmd++) {
101 if (strcmp("proto_init", cmd->name)!=0)
102 continue;
103 abind = (api_proto_init)cmd->function;
104 memset(&pi, 0, sizeof(pi));
105 if (abind(&pi) < 0) {
106 LM_ERR("cannot load protocol's functions for %s\n",
107 cmd->name);
108 return -1;
109 }
110 /* double check if it is a known/valid proto */
111 if (pi.id < PROTO_FIRST || pi.id >= PROTO_OTHER) {
112 LM_ERR("Unknown protocol id %d; check sip_protos structure!\n", pi.id);
113 return -1;
114 }
115 /* double check the name of the proto */
116 if (parse_proto((unsigned char *)pi.name, strlen(pi.name), &id) < 0) {
117 LM_ERR("Cannot parse protocol %s\n", pi.name);
118 return -1;
119 }
120 if (id != pi.id) {
121 LM_ERR("Protocol ID mismatch %d != %d\n", id, pi.id);
122 return -1;
123 }
124 /* check if there is any listener for this protocol */
125 if (!proto_has_listeners(pi.id)) {
126 LM_DBG("No listener defined for proto %s\n", pi.name);
127 continue;
128 }
129
130 if (check_proxy_listener_support(pi.id, pi.net.flags) < 0)
131 return -1;
132
133 /* check if already added */
134 if (protos[id].id != PROTO_NONE) {
135 LM_ERR("Protocol already loaded %s\n", pi.name);
136 return -1;
137 }
138 found_proto = 1;
139 /* all good now */
140 found_all++;

Callers 1

mainFunction · 0.85

Calls 2

parse_protoFunction · 0.85

Tested by

no test coverage detected