another helper function, it just creates a socket_info struct */
| 116 | |
| 117 | /* another helper function, it just creates a socket_info struct */ |
| 118 | struct socket_info_full* new_sock_info(struct socket_id *sid, str *orig_name) |
| 119 | { |
| 120 | struct socket_info_full *sif; |
| 121 | struct socket_info *si; |
| 122 | |
| 123 | sif=(struct socket_info_full*) pkg_malloc(sizeof(*sif)); |
| 124 | if (sif==NULL) goto error; |
| 125 | memset(sif, 0, sizeof(*sif)); |
| 126 | si = &sif->socket_info; |
| 127 | si->socket=-1; |
| 128 | si->last_real_ports = &sif->last_real_ports; |
| 129 | |
| 130 | if (sid->name) { |
| 131 | si->name.len=strlen(sid->name); |
| 132 | si->name.s=(char*)pkg_malloc(si->name.len+1); /* include \0 */ |
| 133 | if (si->name.s==0) goto error; |
| 134 | memcpy(si->name.s, sid->name, si->name.len+1); |
| 135 | } |
| 136 | |
| 137 | if (orig_name && orig_name->s && orig_name->len) { |
| 138 | si->orig_name.s = pkg_malloc(orig_name->len + 1); |
| 139 | if (si->orig_name.s == 0) { |
| 140 | LM_ERR("pkg memory allocation failure\n"); |
| 141 | goto error; |
| 142 | } |
| 143 | memcpy(si->orig_name.s, orig_name->s, orig_name->len); |
| 144 | si->orig_name.s[orig_name->len] = '\0'; |
| 145 | si->orig_name.len = orig_name->len; |
| 146 | } |
| 147 | |
| 148 | /* set port & proto */ |
| 149 | si->port_no=sid->port; |
| 150 | si->proto=sid->proto; |
| 151 | si->flags=sid->flags; |
| 152 | |
| 153 | /* advertised socket information */ |
| 154 | /* Make sure the adv_sock_string is initialized, because if there is |
| 155 | * no adv_sock_name, no other code will initialize it! |
| 156 | */ |
| 157 | si->adv_sock_str.s=NULL; |
| 158 | si->adv_sock_str.len=0; |
| 159 | si->adv_port = 0; /* Here to help grep_sock_info along. */ |
| 160 | if(sid->adv_name) { |
| 161 | si->adv_name_str.len=strlen(sid->adv_name); |
| 162 | si->adv_name_str.s=(char *)pkg_malloc(si->adv_name_str.len+1); |
| 163 | if (si->adv_name_str.s==0) goto error; |
| 164 | memcpy(si->adv_name_str.s, sid->adv_name, si->adv_name_str.len+1); |
| 165 | if (!sid->adv_port) sid->adv_port=si->port_no ; |
| 166 | si->adv_port_str.s=pkg_malloc(10); |
| 167 | if (si->adv_port_str.s==0) goto error; |
| 168 | si->adv_port_str.len=snprintf(si->adv_port_str.s, 10, "%hu", |
| 169 | (unsigned short)sid->adv_port); |
| 170 | si->adv_port = sid->adv_port; |
| 171 | } |
| 172 | |
| 173 | /* store the tag info too */ |
| 174 | if (sid->tag) { |
| 175 | si->tag.len = strlen(sid->tag); |
no test coverage detected