commit 02272ef7d215c4352f4080cb6ce1bb98ceae577e parent 76a3351007f1a174c6a8914e7a52e2d506293cc2 Author: Cristian Tuns <ctuns@mozilla.com> Date: Tue, 18 Nov 2025 14:22:03 -0500 Revert "Bug 2000353 - remove disabled code from ice_parser.c r=bwc,ng" for causing build bustages with "FATAL ERROR PROCESSING MOZBUILD FILE" DONTBUILD This reverts commit 178e217c0321b8466d0169a1fe1fe7e4d3534b98. Revert "Bug 2000353 - remove disabled code from stun_hint.c r=bwc,ng" This reverts commit a03a54e914d50532dbb5165182720f739d8914bc. Revert "Bug 2000353 - remove disabled code from stun_server_ctx.c r=bwc,ng" This reverts commit 8cf9ef32f2e30c7568f69b9fb46ffc34c5d6c2fb. Revert "Bug 2000353 - remove disabled code from registry_int.h r=bwc,ng" This reverts commit 3c484193dc747f4fdc2a88914f9d616ac3408343. Revert "Bug 2000353 - remove unused file async_wait_int.h r=bwc,ng" This reverts commit 3df6fc7ef1ed6c83580613f0018dbec5b2092f16. Revert "Bug 2000353 - remove unused files cb_args.{c|h} r=bwc,ng" This reverts commit 8f6ffe83ac08b123a618b43f8b14be0afcd5782e. Revert "Bug 2000353 - remove unused files nr_socket_wrapper.{c|h} r=bwc,ng" This reverts commit 1379eb90e3d29669a05dcd25c0e9137c1df2f9db. Revert "Bug 2000353 - remove unused functions r=bwc,ng" This reverts commit 352465171adece70a35f4e2ae39668244cdcdeaa. Revert "Bug 2000353 - USE_OWN_INET_NTOP in util.c is never defined for Mozilla builds r=bwc,ng" This reverts commit fbd30bf87867b86c257a5a8ae4e5b9d0255c6a3f. Revert "Bug 2000353 - remove unused files r_replace.c r=bwc,ng" This reverts commit 832790b9d5fd7222b3243e430393cfcae6c33655. Revert "Bug 2000353 - remove unused file r_thread.h r=bwc,ng" This reverts commit 222e8350614473f238371ae2cf7680eda2a3c021. Revert "Bug 2000353 - remove unused files nr_plugin.h and nrstats.h r=bwc,ng" This reverts commit 0923e875b774d3d4ec2f43a565c75fa0d873986c. Revert "Bug 2000353 - virtually everything in nr_common.h was unused r=bwc,ng" This reverts commit 852419e5ff759a256730cfb4a23104086c9babe9. Revert "Bug 2000353 - remove unused file nr_reg_keys.h r=bwc,ng" This reverts commit 375dfa56f9d4ef80c920149eac36a32ff9e2ed19. Revert "Bug 2000353 - remove unused functions from registry.{c|h} and util.{c|h} r=bwc,ng" This reverts commit 7953bc3a2c1856a5bad438f81dbb3a57348c0144. Revert "Bug 2000353 - remove unused files c2ru.{c|h} r=bwc,ng" This reverts commit 7e723379f047c8ea131d33c23ceb56e5c24cf3be. Revert "Bug 2000353 - remove unused functions from registry.{c|h} r=bwc,ng" This reverts commit ed08981c47ba6cf97494b872275003c89441b239. Revert "Bug 2000353 - remove unused files transport_addr_reg.{c|h} r=bwc,ng" This reverts commit d9883c7a14da067f2c7dd167d23be386c471da00. Revert "Bug 2000353 - use nr_stun_get_addrs rather than nr_stun_find_local_addresses. r=bwc,ng" This reverts commit 629c789c60e5a1400da0f7f41ec3af6b49b056ef. Revert "Bug 2000353 - remove commented out lines from nicer.gyp and nrappkit.gyp r=bwc,ng" This reverts commit 5130c32c7daa85792a6a07702b4960969665813c. Diffstat:
65 files changed, 3460 insertions(+), 18 deletions(-)
diff --git a/dom/media/webrtc/transport/common.build b/dom/media/webrtc/transport/common.build @@ -46,9 +46,11 @@ LOCAL_INCLUDES += [ "/dom/media/webrtc/transport/third_party/nICEr/src/util", "/dom/media/webrtc/transport/third_party/nrappkit/src/event", "/dom/media/webrtc/transport/third_party/nrappkit/src/log", + "/dom/media/webrtc/transport/third_party/nrappkit/src/plugin", "/dom/media/webrtc/transport/third_party/nrappkit/src/port/generic/include", "/dom/media/webrtc/transport/third_party/nrappkit/src/registry", "/dom/media/webrtc/transport/third_party/nrappkit/src/share", + "/dom/media/webrtc/transport/third_party/nrappkit/src/stats", "/dom/media/webrtc/transport/third_party/nrappkit/src/util/libekr", "/third_party/libsrtp/src/crypto/include", "/third_party/libsrtp/src/include", diff --git a/dom/media/webrtc/transport/nricectx.cpp b/dom/media/webrtc/transport/nricectx.cpp @@ -61,7 +61,6 @@ extern "C" { // clang-format off #include "nr_api.h" #include "registry.h" -#include "addrs.h" #include "async_timer.h" #include "r_crc32.h" #include "r_memory.h" @@ -71,6 +70,7 @@ extern "C" { #include "nr_socket.h" #include "nr_socket_local.h" #include "stun_reg.h" +#include "stun_util.h" #include "ice_codeword.h" #include "ice_ctx.h" #include "ice_candidate.h" @@ -618,7 +618,7 @@ nsTArray<NrIceStunAddr> NrIceCtx::GetStunAddrs() { } MOZ_MTLOG(ML_INFO, "NrIceCtx static call to find local stun addresses"); - if (nr_stun_get_addrs(local_addrs, MAXADDRS, &addr_ct)) { + if (nr_stun_find_local_addresses(local_addrs, MAXADDRS, &addr_ct)) { MOZ_MTLOG(ML_INFO, "Error finding local stun addresses"); } else { for (int i = 0; i < addr_ct; ++i) { diff --git a/dom/media/webrtc/transport/test/moz.build b/dom/media/webrtc/transport/test/moz.build @@ -92,9 +92,11 @@ LOCAL_INCLUDES += [ "/dom/media/webrtc/transport/third_party/nICEr/src/util", "/dom/media/webrtc/transport/third_party/nrappkit/src/event", "/dom/media/webrtc/transport/third_party/nrappkit/src/log", + "/dom/media/webrtc/transport/third_party/nrappkit/src/plugin", "/dom/media/webrtc/transport/third_party/nrappkit/src/port/generic/include", "/dom/media/webrtc/transport/third_party/nrappkit/src/registry", "/dom/media/webrtc/transport/third_party/nrappkit/src/share", + "/dom/media/webrtc/transport/third_party/nrappkit/src/stats", "/dom/media/webrtc/transport/third_party/nrappkit/src/util/", "/dom/media/webrtc/transport/third_party/nrappkit/src/util/libekr", "/netwerk/sctp/src/", diff --git a/dom/media/webrtc/transport/test/stunserver.cpp b/dom/media/webrtc/transport/test/stunserver.cpp @@ -266,7 +266,7 @@ int TestStunServer::Initialize(int address_family) { int r; int i; - r = nr_stun_get_addrs(addrs, max_addrs, &addr_ct); + r = nr_stun_find_local_addresses(addrs, max_addrs, &addr_ct); if (r) { MOZ_MTLOG(ML_ERROR, "Couldn't retrieve addresses"); return R_INTERNAL; diff --git a/dom/media/webrtc/transport/third_party/nICEr/nicer.gyp b/dom/media/webrtc/transport/third_party/nICEr/nicer.gyp @@ -19,8 +19,10 @@ # nrappkit '../nrappkit/src/event', '../nrappkit/src/log', + '../nrappkit/src/plugin', '../nrappkit/src/registry', '../nrappkit/src/share', + '../nrappkit/src/stats', '../nrappkit/src/util', '../nrappkit/src/util/libekr', '../nrappkit/src/port/generic/include', @@ -37,6 +39,8 @@ # Crypto "./src/crypto/nr_crypto.c", "./src/crypto/nr_crypto.h", + #"./src/crypto/nr_crypto_openssl.c", + #"./src/crypto/nr_crypto_openssl.h", # ICE "./src/ice/ice_candidate.c", @@ -61,13 +65,18 @@ # Net "./src/net/nr_resolver.c", "./src/net/nr_resolver.h", + "./src/net/nr_socket_wrapper.c", + "./src/net/nr_socket_wrapper.h", "./src/net/nr_socket.c", "./src/net/nr_socket.h", + #"./src/net/nr_socket_local.c", "./src/net/nr_socket_local.h", "./src/net/nr_socket_multi_tcp.c", "./src/net/nr_socket_multi_tcp.h", "./src/net/transport_addr.c", "./src/net/transport_addr.h", + "./src/net/transport_addr_reg.c", + "./src/net/transport_addr_reg.h", "./src/net/local_addr.c", "./src/net/local_addr.h", "./src/net/nr_interface_prioritizer.c", @@ -108,6 +117,8 @@ "./src/stun/turn_client_ctx.h", # Util + "./src/util/cb_args.c", + "./src/util/cb_args.h", "./src/util/ice_util.c", "./src/util/ice_util.h", diff --git a/dom/media/webrtc/transport/third_party/nICEr/src/ice/ice_candidate_pair.c b/dom/media/webrtc/transport/third_party/nICEr/src/ice/ice_candidate_pair.c @@ -554,6 +554,37 @@ void nr_ice_candidate_pair_cancel(nr_ice_peer_ctx *pctx,nr_ice_cand_pair *pair, } } +int nr_ice_candidate_pair_select(nr_ice_cand_pair *pair) + { + int r,_status; + + if(!pair){ + r_log(LOG_ICE,LOG_ERR,"ICE-PAIR: No pair chosen"); + ABORT(R_BAD_ARGS); + } + + if(pair->state!=NR_ICE_PAIR_STATE_SUCCEEDED){ + r_log(LOG_ICE,LOG_ERR,"ICE-PEER(%s)/CAND-PAIR(%s): tried to install non-succeeded pair, ignoring: %s",pair->pctx->label,pair->codeword,pair->as_string); + } + else{ + /* Ok, they chose one */ + /* 1. Send a new request with nominated. Do it as a scheduled + event to avoid reentrancy issues. Only do this if it hasn't + happened already (though this shouldn't happen.) + */ + if(!pair->restart_nominated_cb_timer) + NR_ASYNC_TIMER_SET(0,nr_ice_candidate_pair_restart_stun_nominated_cb,pair,&pair->restart_nominated_cb_timer); + + /* 2. Tell ourselves this pair is ready */ + if(r=nr_ice_component_nominated_pair(pair->remote->component, pair)) + ABORT(r); + } + + _status=0; + abort: + return(_status); + } + void nr_ice_candidate_pair_set_state(nr_ice_peer_ctx *pctx, nr_ice_cand_pair *pair, int state) { r_log(LOG_ICE,LOG_INFO,"ICE-PEER(%s)/CAND-PAIR(%s): setting pair to state %s: %s", diff --git a/dom/media/webrtc/transport/third_party/nICEr/src/ice/ice_candidate_pair.h b/dom/media/webrtc/transport/third_party/nICEr/src/ice/ice_candidate_pair.h @@ -89,6 +89,7 @@ int nr_ice_candidate_pair_start(nr_ice_peer_ctx *pctx, nr_ice_cand_pair *pair); void nr_ice_candidate_pair_set_state(nr_ice_peer_ctx *pctx, nr_ice_cand_pair *pair, int state); void nr_ice_candidate_pair_dump_state(nr_ice_cand_pair *pair, int log_level); void nr_ice_candidate_pair_cancel(nr_ice_peer_ctx *pctx,nr_ice_cand_pair *pair, int move_to_wait_state); +int nr_ice_candidate_pair_select(nr_ice_cand_pair *pair); int nr_ice_candidate_pair_do_triggered_check(nr_ice_peer_ctx *pctx, nr_ice_cand_pair *pair, int force); void nr_ice_candidate_pair_insert(nr_ice_cand_pair_head *head,nr_ice_cand_pair *pair); int nr_ice_candidate_pair_trigger_check_append(nr_ice_cand_pair_head *head,nr_ice_cand_pair *pair); diff --git a/dom/media/webrtc/transport/third_party/nICEr/src/ice/ice_component.c b/dom/media/webrtc/transport/third_party/nICEr/src/ice/ice_component.c @@ -40,6 +40,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "stun.h" #include "nr_socket_local.h" #include "nr_socket_turn.h" +#include "nr_socket_wrapper.h" #include "nr_socket_buffered_stun.h" #include "nr_socket_multi_tcp.h" #include "ice_reg.h" diff --git a/dom/media/webrtc/transport/third_party/nICEr/src/ice/ice_ctx.c b/dom/media/webrtc/transport/third_party/nICEr/src/ice/ice_ctx.c @@ -58,6 +58,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. int LOG_ICE = 0; +static int nr_ice_random_string(char *str, int len); static int nr_ice_fetch_stun_servers(int ct, nr_ice_stun_server **out); #ifdef USE_TURN static int nr_ice_fetch_turn_servers(int ct, nr_ice_turn_server **out); @@ -167,6 +168,31 @@ int nr_ice_ctx_set_turn_servers(nr_ice_ctx *ctx,nr_ice_turn_server *servers,int return(_status); } +int nr_ice_ctx_copy_turn_servers(nr_ice_ctx *ctx, nr_ice_turn_server *servers, int ct) + { + int _status, i, r; + + if (r = nr_ice_ctx_set_turn_servers(ctx, servers, ct)) { + ABORT(r); + } + + // make copies of the username and password so they aren't freed twice + for (i = 0; i < ct; ++i) { + if (!(ctx->turn_servers_cfg[i].username = r_strdup(servers[i].username))) { + ABORT(R_NO_MEMORY); + } + if (r = r_data_create(&ctx->turn_servers_cfg[i].password, + servers[i].password->data, + servers[i].password->len)) { + ABORT(r); + } + } + + _status=0; + abort: + return(_status); + } + static int nr_ice_ctx_set_local_addrs(nr_ice_ctx *ctx,nr_local_addr *addrs,int ct) { int _status,i,r; @@ -845,7 +871,7 @@ int nr_ice_set_target_for_default_local_address_lookup(nr_ice_ctx *ctx, const ch int stun_addr_ct; if (!ctx->local_addrs) { - if((r=nr_stun_get_addrs(stun_addrs,MAXADDRS,&stun_addr_ct))) { + if((r=nr_stun_find_local_addresses(stun_addrs,MAXADDRS,&stun_addr_ct))) { ABORT(r); } if((r=nr_ice_set_local_addresses(ctx,stun_addrs,stun_addr_ct))) { @@ -930,6 +956,28 @@ int nr_ice_get_global_attributes(nr_ice_ctx *ctx,char ***attrsp, int *attrctp) return(0); } +static int nr_ice_random_string(char *str, int len) + { + unsigned char bytes[100]; + size_t needed; + int r,_status; + + if(len%2) ABORT(R_BAD_ARGS); + needed=len/2; + + if(needed>sizeof(bytes)) ABORT(R_BAD_ARGS); + + if(r=nr_crypto_random_bytes(bytes,needed)) + ABORT(r); + + if(r=nr_bin2hex(bytes,needed,(unsigned char *)str)) + ABORT(r); + + _status=0; + abort: + return(_status); + } + /* This is incredibly annoying: we now have a datagram but we don't know which peer it's from, and we need to be able to tell the API user. So, offer it to each peer and if one bites, assume @@ -993,6 +1041,38 @@ int nr_ice_ctx_remember_id(nr_ice_ctx *ctx, nr_stun_message *msg) } +/* Clean up some of the resources (mostly file descriptors) used + by candidates we didn't choose. Note that this still leaves + a fair amount of non-system stuff floating around. This gets + cleaned up when you destroy the ICE ctx */ +int nr_ice_ctx_finalize(nr_ice_ctx *ctx, nr_ice_peer_ctx *pctx) + { + nr_ice_media_stream *lstr,*rstr; + + r_log(LOG_ICE,LOG_DEBUG,"Finalizing ICE ctx %s, peer=%s",ctx->label,pctx->label); + /* + First find the peer stream, if any + */ + lstr=STAILQ_FIRST(&ctx->streams); + while(lstr){ + rstr=STAILQ_FIRST(&pctx->peer_streams); + + while(rstr){ + if(rstr->local_stream==lstr) + break; + + rstr=STAILQ_NEXT(rstr,entry); + } + + nr_ice_media_stream_finalize(lstr,rstr); + + lstr=STAILQ_NEXT(lstr,entry); + } + + return(0); + } + + int nr_ice_ctx_set_trickle_cb(nr_ice_ctx *ctx, nr_ice_trickle_candidate_cb cb, void *cb_arg) { ctx->trickle_cb = cb; @@ -1019,3 +1099,40 @@ int nr_ice_ctx_hide_candidate(nr_ice_ctx *ctx, nr_ice_candidate *cand) return 0; } +int nr_ice_get_new_ice_ufrag(char** ufrag) + { + int r,_status; + char buf[ICE_UFRAG_LEN+1]; + + if(r=nr_ice_random_string(buf,ICE_UFRAG_LEN)) + ABORT(r); + if(!(*ufrag=r_strdup(buf))) + ABORT(r); + + _status=0; + abort: + if(_status) { + RFREE(*ufrag); + *ufrag = 0; + } + return(_status); + } + +int nr_ice_get_new_ice_pwd(char** pwd) + { + int r,_status; + char buf[ICE_PWD_LEN+1]; + + if(r=nr_ice_random_string(buf,ICE_PWD_LEN)) + ABORT(r); + if(!(*pwd=r_strdup(buf))) + ABORT(r); + + _status=0; + abort: + if(_status) { + RFREE(*pwd); + *pwd = 0; + } + return(_status); + } diff --git a/dom/media/webrtc/transport/third_party/nICEr/src/ice/ice_ctx.h b/dom/media/webrtc/transport/third_party/nICEr/src/ice/ice_ctx.h @@ -44,6 +44,7 @@ extern "C" { #include "nr_socket.h" #include "nr_resolver.h" #include "nr_interface_prioritizer.h" +#include "nr_socket_wrapper.h" #include "stun_client_ctx.h" #include "stun_server_ctx.h" #include "turn_client_ctx.h" @@ -181,13 +182,17 @@ int nr_ice_get_global_attributes(nr_ice_ctx *ctx,char ***attrsp, int *attrctp); int nr_ice_ctx_deliver_packet(nr_ice_ctx *ctx, nr_ice_component *comp, nr_transport_addr *source_addr, UCHAR *data, int len); int nr_ice_ctx_is_known_id(nr_ice_ctx *ctx, UCHAR id[12]); int nr_ice_ctx_remember_id(nr_ice_ctx *ctx, nr_stun_message *msg); +int nr_ice_ctx_finalize(nr_ice_ctx *ctx, nr_ice_peer_ctx *pctx); int nr_ice_ctx_set_stun_servers(nr_ice_ctx *ctx,nr_ice_stun_server *servers, int ct); int nr_ice_ctx_set_turn_servers(nr_ice_ctx *ctx,nr_ice_turn_server *servers, int ct); +int nr_ice_ctx_copy_turn_servers(nr_ice_ctx *ctx, nr_ice_turn_server *servers, int ct); int nr_ice_ctx_set_resolver(nr_ice_ctx *ctx, nr_resolver *resolver); int nr_ice_ctx_set_interface_prioritizer(nr_ice_ctx *ctx, nr_interface_prioritizer *prioritizer); void nr_ice_ctx_set_socket_factory(nr_ice_ctx *ctx, nr_socket_factory *factory); int nr_ice_ctx_set_trickle_cb(nr_ice_ctx *ctx, nr_ice_trickle_candidate_cb cb, void *cb_arg); int nr_ice_ctx_hide_candidate(nr_ice_ctx *ctx, nr_ice_candidate *cand); +int nr_ice_get_new_ice_ufrag(char** ufrag); +int nr_ice_get_new_ice_pwd(char** pwd); #define NR_ICE_MAX_ATTRIBUTE_SIZE 256 diff --git a/dom/media/webrtc/transport/third_party/nICEr/src/ice/ice_media_stream.c b/dom/media/webrtc/transport/third_party/nICEr/src/ice/ice_media_stream.c @@ -855,6 +855,36 @@ void nr_ice_media_stream_component_failed(nr_ice_media_stream *stream,nr_ice_com nr_ice_peer_ctx_check_if_connected(stream->pctx); } +int nr_ice_media_stream_get_best_candidate(nr_ice_media_stream *str, int component, nr_ice_candidate **candp) + { + nr_ice_candidate *cand; + nr_ice_candidate *best_cand=0; + nr_ice_component *comp; + int r,_status; + + if(r=nr_ice_media_stream_find_component(str,component,&comp)) + ABORT(r); + + cand=TAILQ_FIRST(&comp->candidates); + while(cand){ + if(cand->state==NR_ICE_CAND_STATE_INITIALIZED){ + if(!best_cand || (cand->priority>best_cand->priority)) + best_cand=cand; + + } + cand=TAILQ_NEXT(cand,entry_comp); + } + + if(!best_cand) + ABORT(R_NOT_FOUND); + + *candp=best_cand; + + _status=0; + abort: + return(_status); + } + /* OK, we have the stream the user created, but that reflects the base ICE ctx, not the peer_ctx. So, find the related stream in the pctx, @@ -944,6 +974,34 @@ int nr_ice_media_stream_get_active(nr_ice_peer_ctx *pctx, nr_ice_media_stream *s return(_status); } +int nr_ice_media_stream_addrs(nr_ice_peer_ctx *pctx, nr_ice_media_stream *str, int component, nr_transport_addr *local, nr_transport_addr *remote) + { + int r,_status; + nr_ice_component *comp; + + /* First find the peer component */ + if(r=nr_ice_peer_ctx_find_component(pctx, str, component, &comp)) + ABORT(r); + + /* Do we have an active pair yet? We should... */ + if(!comp->active) + ABORT(R_BAD_ARGS); + + /* Use the socket on our local side */ + if(r=nr_socket_getaddr(comp->active->local->osock,local)) + ABORT(r); + + /* Use the address on the remote side */ + if(r=nr_transport_addr_copy(remote,&comp->active->remote->addr)) + ABORT(r); + + _status=0; + abort: + return(_status); + } + + + int nr_ice_media_stream_finalize(nr_ice_media_stream *lstr,nr_ice_media_stream *rstr) { nr_ice_component *lcomp,*rcomp; diff --git a/dom/media/webrtc/transport/third_party/nICEr/src/ice/ice_media_stream.h b/dom/media/webrtc/transport/third_party/nICEr/src/ice/ice_media_stream.h @@ -127,10 +127,12 @@ int nr_ice_media_stream_set_state(nr_ice_media_stream *str, int state); void nr_ice_media_stream_stop_checking(nr_ice_media_stream *str); void nr_ice_media_stream_set_obsolete(nr_ice_media_stream *str); int nr_ice_media_stream_is_done_gathering(nr_ice_media_stream *str); +int nr_ice_media_stream_get_best_candidate(nr_ice_media_stream *str, int component, nr_ice_candidate **candp); int nr_ice_media_stream_send(nr_ice_peer_ctx *pctx, nr_ice_media_stream *str, int component, UCHAR *data, int len); int nr_ice_media_stream_get_active(nr_ice_peer_ctx *pctx, nr_ice_media_stream *str, int component, nr_ice_candidate **local, nr_ice_candidate **remote); int nr_ice_media_stream_find_component(nr_ice_media_stream *str, int comp_id, nr_ice_component **compp); int nr_ice_media_stream_find_pair(nr_ice_media_stream *str, nr_ice_candidate *local, nr_ice_candidate *remote, nr_ice_cand_pair **pair); +int nr_ice_media_stream_addrs(nr_ice_peer_ctx *pctx, nr_ice_media_stream *str, int component, nr_transport_addr *local, nr_transport_addr *remote); int nr_ice_peer_ctx_parse_media_stream_attribute(nr_ice_peer_ctx *pctx, nr_ice_media_stream *stream, char *attr); int nr_ice_media_stream_get_consent_status(nr_ice_media_stream *stream, int component_id, int *can_send, struct timeval *ts); diff --git a/dom/media/webrtc/transport/third_party/nICEr/src/ice/ice_parser.c b/dom/media/webrtc/transport/third_party/nICEr/src/ice/ice_parser.c @@ -337,6 +337,13 @@ nr_ice_peer_candidate_from_attribute(nr_ice_ctx *ctx,char *orig,nr_ice_media_str ABORT(R_BAD_DATA); } /* Ignore extensions per RFC 5245 S 15.1 */ +#if 0 + /* This used to be an assert, but we don't want to exit on invalid + remote data */ + if (strlen(str) != 0) { + ABORT(R_BAD_DATA); + } +#endif nr_ice_candidate_compute_codeword(cand); @@ -469,6 +476,15 @@ nr_ice_peer_ctx_parse_global_attributes(nr_ice_peer_ctx *pctx, char **attrs, int skip_to_past_space(&str); +#if 0 + /* TODO: !nn! just drop on the floor for now, later put somewhere */ + /* Assume v4 for now */ + if(r=nr_ip4_port_to_transport_addr(ntohl(addr),port,IPPROTO_UDP,&candidate->base)) + ABORT(r); + + TAILQ_INSERT_TAIL(head, elm, field); +#endif + component_id = 0; /* prevent free */ RFREE(connection_address); connection_address = 0; /* prevent free */ diff --git a/dom/media/webrtc/transport/third_party/nICEr/src/ice/ice_peer_ctx.c b/dom/media/webrtc/transport/third_party/nICEr/src/ice/ice_peer_ctx.c @@ -462,6 +462,30 @@ int nr_ice_peer_ctx_pair_new_trickle_candidate(nr_ice_ctx *ctx, nr_ice_peer_ctx return _status; } +int nr_ice_peer_ctx_disable_component(nr_ice_peer_ctx *pctx, nr_ice_media_stream *lstream, int component_id) + { + int r, _status; + nr_ice_media_stream *pstream; + nr_ice_component *component; + + if ((r=nr_ice_peer_ctx_find_pstream(pctx, lstream, &pstream))) + ABORT(r); + + /* We shouldn't be calling this after we have started pairing */ + if (pstream->ice_state != NR_ICE_MEDIA_STREAM_UNPAIRED) + ABORT(R_FAILED); + + if ((r=nr_ice_media_stream_find_component(pstream, component_id, + &component))) + ABORT(r); + + component->state = NR_ICE_COMPONENT_DISABLED; + + _status=0; + abort: + return(_status); + } + void nr_ice_peer_ctx_destroy(nr_ice_peer_ctx** pctxp) { if (!pctxp || !*pctxp) return; diff --git a/dom/media/webrtc/transport/third_party/nICEr/src/ice/ice_peer_ctx.h b/dom/media/webrtc/transport/third_party/nICEr/src/ice/ice_peer_ctx.h @@ -90,6 +90,7 @@ int nr_ice_peer_ctx_log_state(nr_ice_peer_ctx *pctx); void nr_ice_peer_ctx_check_if_connected(nr_ice_peer_ctx *pctx); int nr_ice_peer_ctx_find_component(nr_ice_peer_ctx *pctx, nr_ice_media_stream *str, int component_id, nr_ice_component **compp); int nr_ice_peer_ctx_deliver_packet_maybe(nr_ice_peer_ctx *pctx, nr_ice_component *comp, nr_transport_addr *source_addr, UCHAR *data, int len); +int nr_ice_peer_ctx_disable_component(nr_ice_peer_ctx *pctx, nr_ice_media_stream *lstream, int component_id); int nr_ice_peer_ctx_pair_new_trickle_candidate(nr_ice_ctx *ctx, nr_ice_peer_ctx *pctx, nr_ice_candidate *cand); void nr_ice_peer_ctx_switch_controlling_role(nr_ice_peer_ctx *pctx); diff --git a/dom/media/webrtc/transport/third_party/nICEr/src/net/nr_socket_wrapper.c b/dom/media/webrtc/transport/third_party/nICEr/src/net/nr_socket_wrapper.c @@ -0,0 +1,84 @@ +/* +Copyright (c) 2007, Adobe Systems, Incorporated +Copyright (c) 2013, Mozilla + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +* Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +* Neither the name of Adobe Systems, Network Resonance, Mozilla nor + the names of its contributors may be used to endorse or promote + products derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include <nr_api.h> +#include "nr_socket_wrapper.h" + +#include <assert.h> + +int nr_socket_wrapper_factory_create_int(void *obj, nr_socket_wrapper_factory_vtbl *vtbl, + nr_socket_wrapper_factory **wrapperp) +{ + int _status; + nr_socket_wrapper_factory *wrapper=0; + + if (!(wrapper=RCALLOC(sizeof(nr_socket_wrapper_factory)))) + ABORT(R_NO_MEMORY); + + wrapper->obj=obj; + wrapper->vtbl=vtbl; + + *wrapperp=wrapper; + _status=0; +abort: + return(_status); +} + +int nr_socket_wrapper_factory_wrap(nr_socket_wrapper_factory *wrapper, + nr_socket *inner, + nr_socket **socketp) +{ + return wrapper->vtbl->wrap(wrapper->obj, inner, socketp); +} + +int nr_socket_wrapper_factory_destroy(nr_socket_wrapper_factory **wrapperp) +{ + nr_socket_wrapper_factory *wrapper; + + if (!wrapperp || !*wrapperp) + return 0; + + wrapper = *wrapperp; + *wrapperp = 0; + + assert(wrapper->vtbl); + if (wrapper->vtbl) + wrapper->vtbl->destroy(&wrapper->obj); + + RFREE(wrapper); + + return 0; +} + diff --git a/dom/media/webrtc/transport/third_party/nICEr/src/net/nr_socket_wrapper.h b/dom/media/webrtc/transport/third_party/nICEr/src/net/nr_socket_wrapper.h @@ -0,0 +1,63 @@ +/* +Copyright (c) 2007, Adobe Systems, Incorporated +Copyright (c) 2013, Mozilla + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +* Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +* Neither the name of Adobe Systems, Network Resonance, Mozilla nor + the names of its contributors may be used to endorse or promote + products derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef _nr_socket_wrapper_h +#define _nr_socket_wrapper_h + +#include "nr_socket.h" + +typedef struct nr_socket_wrapper_factory_vtbl_ { + int (*wrap)(void *obj, + nr_socket *socket, + nr_socket **socketp); + int (*destroy)(void **obj); +} nr_socket_wrapper_factory_vtbl; + +typedef struct nr_socket_wrapper_factory_ { + void *obj; + nr_socket_wrapper_factory_vtbl *vtbl; +} nr_socket_wrapper_factory; + + +int nr_socket_wrapper_factory_create_int(void *obj, nr_socket_wrapper_factory_vtbl *vtbl, + nr_socket_wrapper_factory **wrapperp); + + +int nr_socket_wrapper_factory_wrap(nr_socket_wrapper_factory *wrapper, nr_socket *inner, + nr_socket **socketp); + +int nr_socket_wrapper_factory_destroy(nr_socket_wrapper_factory **wrapperp); + +#endif diff --git a/dom/media/webrtc/transport/third_party/nICEr/src/net/transport_addr_reg.c b/dom/media/webrtc/transport/third_party/nICEr/src/net/transport_addr_reg.c @@ -0,0 +1,230 @@ +/* +Copyright (c) 2007, Adobe Systems, Incorporated +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +* Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +* Neither the name of Adobe Systems, Network Resonance nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include <csi_platform.h> +#include <stdio.h> +#include <string.h> +#include <memory.h> +#include <sys/types.h> +#ifdef WIN32 +#include <winsock2.h> +#else +#include <strings.h> +#include <unistd.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#endif +#include <assert.h> +#include "nr_api.h" +#include "util.h" +#include "transport_addr.h" +#include "transport_addr_reg.h" + +#ifndef INET6_ADDRSTRLEN +#define INET6_ADDRSTRLEN 46 /* Value used by linux/BSD */ +#endif + +int +nr_reg_get_transport_addr(NR_registry prefix, int keep, nr_transport_addr *addr) +{ + int r,_status; + unsigned int count; + char *address = 0; + UINT2 port = 0; + char *ifname = 0; + char *protocol = 0; + int p; + + if ((r=NR_reg_get_child_count(prefix, &count))) + ABORT(r); + + if (count == 0) + ABORT(R_NOT_FOUND); + + if ((r=NR_reg_alloc2_string(prefix, "address", &address))) { + if (r != R_NOT_FOUND) + ABORT(r); + address = 0; + } + + if ((r=NR_reg_alloc2_string(prefix, "ifname", &ifname))) { + if (r != R_NOT_FOUND) + ABORT(r); + ifname = 0; + } + + if ((r=NR_reg_get2_uint2(prefix, "port", &port))) { + if (r != R_NOT_FOUND) + ABORT(r); + port = 0; + } + + if ((r=NR_reg_alloc2_string(prefix, "protocol", &protocol))) { + if (r != R_NOT_FOUND) + ABORT(r); + p = IPPROTO_UDP; + + protocol = 0; + } + else { + if (!strcasecmp("tcp", protocol)) + p = IPPROTO_TCP; + else if (!strcasecmp("udp", protocol)) + p = IPPROTO_UDP; + else + ABORT(R_BAD_DATA); + } + + if (!keep) memset(addr, 0, sizeof(*addr)); + + if ((r=nr_str_port_to_transport_addr(address?address:"0.0.0.0", port, p, addr))) + ABORT(r); + + if (ifname) { + (void)strlcpy(addr->ifname, ifname, sizeof(addr->ifname)); + } + + _status=0; + abort: + RFREE(protocol); + RFREE(ifname); + RFREE(address); + return(_status); +} + +int +nr_reg_set_transport_addr(NR_registry prefix, int keep, nr_transport_addr *addr) +{ + int r,_status; + + if (! keep) { + if ((r=NR_reg_del(prefix))) + ABORT(r); + } + + switch (addr->ip_version) { + case NR_IPV4: + if (!nr_transport_addr_is_wildcard(addr)) { + if ((r=NR_reg_set2_string(prefix, "address", inet_ntoa(addr->u.addr4.sin_addr)))) + ABORT(r); + } + + if (addr->u.addr4.sin_port != 0) { + if ((r=NR_reg_set2_uint2(prefix, "port", ntohs(addr->u.addr4.sin_port)))) + ABORT(r); + } + break; + + case NR_IPV6: + if (!nr_transport_addr_is_wildcard(addr)) { + char address[INET6_ADDRSTRLEN]; + if(!inet_ntop(AF_INET6, &addr->u.addr6.sin6_addr,address,sizeof(address))) { + ABORT(R_BAD_DATA); + } + + if ((r=NR_reg_set2_string(prefix, "address", address))) { + ABORT(r); + } + } + + if (addr->u.addr6.sin6_port != 0) { + if ((r=NR_reg_set2_uint2(prefix, "port", ntohs(addr->u.addr6.sin6_port)))) + ABORT(r); + } + break; + default: + ABORT(R_INTERNAL); + break; + } + + /* We abort if neither NR_IPV4 or NR_IPV6 above */ + switch (addr->protocol) { + case IPPROTO_TCP: + if ((r=NR_reg_set2_string(prefix, "protocol", "tcp"))) + ABORT(r); + break; + case IPPROTO_UDP: + if ((r=NR_reg_set2_string(prefix, "protocol", "udp"))) + ABORT(r); + break; + default: + NR_UNIMPLEMENTED; + break; + } + + if (strlen(addr->ifname) > 0) { + if ((r=NR_reg_set2_string(prefix, "ifname", addr->ifname))) + ABORT(r); + } + + _status=0; + abort: + if (_status) + NR_reg_del(prefix); + return _status; +} + +int +nr_reg_get_transport_addr2(NR_registry prefix, char *name, int keep, nr_transport_addr *addr) +{ + int r, _status; + NR_registry registry; + + if ((r=NR_reg_make_registry(prefix, name, registry))) + ABORT(r); + + if ((r=nr_reg_get_transport_addr(registry, keep, addr))) + ABORT(r); + + _status = 0; +abort: + return _status; +} + +int +nr_reg_set_transport_addr2(NR_registry prefix, char *name, int keep, nr_transport_addr *addr) +{ + int r, _status; + NR_registry registry; + + if ((r=NR_reg_make_registry(prefix, name, registry))) + ABORT(r); + + if ((r=nr_reg_set_transport_addr(registry, keep, addr))) + ABORT(r); + + _status = 0; +abort: + return _status; +} + diff --git a/dom/media/webrtc/transport/third_party/nICEr/src/net/transport_addr_reg.h b/dom/media/webrtc/transport/third_party/nICEr/src/net/transport_addr_reg.h @@ -0,0 +1,46 @@ +/* +Copyright (c) 2007, Adobe Systems, Incorporated +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +* Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +* Neither the name of Adobe Systems, Network Resonance nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + + +#ifndef _transport_addr_reg_h +#define _transport_addr_reg_h + +#include "registry.h" + +int nr_reg_get_transport_addr(NR_registry prefix, int keep, nr_transport_addr *addr); +int nr_reg_set_transport_addr(NR_registry prefix, int keep, nr_transport_addr *addr); +int nr_reg_get_transport_addr2(NR_registry prefix, char *name, int keep, nr_transport_addr *addr); +int nr_reg_set_transport_addr2(NR_registry prefix, char *name, int keep, nr_transport_addr *addr); + +#endif + diff --git a/dom/media/webrtc/transport/third_party/nICEr/src/stun/stun_client_ctx.c b/dom/media/webrtc/transport/third_party/nICEr/src/stun/stun_client_ctx.c @@ -157,6 +157,30 @@ int nr_stun_client_start(nr_stun_client_ctx *ctx, int mode, NR_async_cb finished return(_status); } + int nr_stun_client_restart(nr_stun_client_ctx* ctx, + const nr_transport_addr* peer_addr) { + int r,_status; + int mode; + NR_async_cb finished_cb; + void *cb_arg; + if (ctx->state != NR_STUN_CLIENT_STATE_RUNNING) + ABORT(R_NOT_PERMITTED); + + mode = ctx->mode; + finished_cb = ctx->finished_cb; + cb_arg = ctx->cb_arg; + + nr_stun_client_reset(ctx); + nr_transport_addr_copy(&ctx->peer_addr, peer_addr); + + if (r=nr_stun_client_start(ctx, mode, finished_cb, cb_arg)) + ABORT(r); + + _status=0; + abort: + return(_status); + } + int nr_stun_client_reset(nr_stun_client_ctx *ctx) { diff --git a/dom/media/webrtc/transport/third_party/nICEr/src/stun/stun_client_ctx.h b/dom/media/webrtc/transport/third_party/nICEr/src/stun/stun_client_ctx.h @@ -194,6 +194,8 @@ int nr_stun_client_ctx_create(char* label, nr_socket* sock, nr_transport_addr* peer, UINT4 RTO, int flags, nr_stun_client_ctx** ctxp); int nr_stun_client_start(nr_stun_client_ctx *ctx, int mode, NR_async_cb finished_cb, void *cb_arg); +int nr_stun_client_restart(nr_stun_client_ctx* ctx, + const nr_transport_addr* peer_addr); int nr_stun_client_force_retransmit(nr_stun_client_ctx *ctx); int nr_stun_client_reset(nr_stun_client_ctx *ctx); int nr_stun_client_ctx_destroy(nr_stun_client_ctx **ctxp); diff --git a/dom/media/webrtc/transport/third_party/nICEr/src/stun/stun_hint.c b/dom/media/webrtc/transport/third_party/nICEr/src/stun/stun_hint.c @@ -55,6 +55,9 @@ nr_is_stun_message(UCHAR *buf, size_t len) { const UINT4 cookie = htonl(NR_STUN_MAGIC_COOKIE); const UINT4 cookie2 = htonl(NR_STUN_MAGIC_COOKIE2); +#if 0 + nr_stun_message msg; +#endif UINT2 type; nr_stun_encoded_attribute* attr; unsigned int attrLen; @@ -133,6 +136,25 @@ nr_is_stun_message(UCHAR *buf, size_t len) /* the fingerprint is in the right place and looks sane, so we can be quite * sure we've got a STUN message */ +#if 0 +/* nevermind this check ... there's a reasonable chance that a NAT has modified + * the message (and thus the fingerprint check will fail), but it's still an + * otherwise-perfectly-good STUN message, so skip the check since we're going + * to return "true" whether the check succeeds or fails */ + + if (nr_stun_parse_attr_UINT4(buf + (len - 4), attrLen, &msg.fingerprint)) + return 2; + + + if (nr_stun_compute_fingerprint(buf, len - 8, &computedFingerprint)) + return 2; + + if (msg.fingerprint.number != computedFingerprint) + return 2; + + /* and the fingerprint is good, so it's gotta be a STUN message */ +#endif + return 3; } @@ -189,6 +211,22 @@ nr_is_stun_response_message(UCHAR *buf, size_t len) } int +nr_has_stun_cookie(UCHAR *buf, size_t len) +{ + static UINT4 cookie; + + cookie = htonl(NR_STUN_MAGIC_COOKIE); + + if (sizeof(nr_stun_message_header) > len) + return 0; + + if (memcmp(&cookie, &buf[4], sizeof(UINT4))) + return 0; + + return 1; +} + +int nr_stun_message_length(UCHAR *buf, int buf_len, int *msg_len) { nr_stun_message_header *hdr; diff --git a/dom/media/webrtc/transport/third_party/nICEr/src/stun/stun_hint.h b/dom/media/webrtc/transport/third_party/nICEr/src/stun/stun_hint.h @@ -38,6 +38,7 @@ int nr_is_stun_message(UCHAR *buf, size_t len); int nr_is_stun_request_message(UCHAR *buf, size_t len); int nr_is_stun_response_message(UCHAR *buf, size_t len); int nr_is_stun_indication_message(UCHAR *buf, size_t len); +int nr_has_stun_cookie(UCHAR *buf, size_t len); int nr_stun_message_length(UCHAR *buf, int len, int *length); #endif diff --git a/dom/media/webrtc/transport/third_party/nICEr/src/stun/stun_server_ctx.c b/dom/media/webrtc/transport/third_party/nICEr/src/stun/stun_server_ctx.c @@ -354,6 +354,21 @@ int nr_stun_server_process_request(nr_stun_server_ctx *ctx, nr_socket *sock, cha _status = R_FAILED; } +#if 0 + /* EKR: suppressed these checks because if you have an error when + you are sending an error, things go wonky */ +#ifdef SANITY_CHECKS + if (_status == R_ALREADY) { + assert(NR_STUN_GET_TYPE_CLASS(res->header.type) == NR_CLASS_ERROR_RESPONSE); + assert(nr_stun_message_has_attribute(res, NR_STUN_ATTR_ERROR_CODE, 0)); + } + else { + assert(NR_STUN_GET_TYPE_CLASS(res->header.type) == NR_CLASS_RESPONSE); + assert(!nr_stun_message_has_attribute(res, NR_STUN_ATTR_ERROR_CODE, 0)); + } +#endif /* SANITY_CHECKS */ +#endif + if (0) { skip_response: _status = 0; diff --git a/dom/media/webrtc/transport/third_party/nICEr/src/stun/stun_util.c b/dom/media/webrtc/transport/third_party/nICEr/src/stun/stun_util.c @@ -47,6 +47,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "stun_reg.h" #include "registry.h" #include "addrs.h" +#include "transport_addr_reg.h" #include "nr_crypto.h" #include "hex.h" @@ -112,6 +113,63 @@ nr_stun_xor_mapped_address(UINT4 magicCookie, UINT12 transactionId, nr_transport } int +nr_stun_find_local_addresses(nr_local_addr addrs[], int maxaddrs, int *count) +{ + int r,_status; + //NR_registry *children = 0; + + *count = 0; + +#if 0 + // this really goes with the code commented out below. (mjf) + if ((r=NR_reg_get_child_count(NR_STUN_REG_PREF_ADDRESS_PRFX, (unsigned int*)count))) + if (r != R_NOT_FOUND) + ABORT(r); +#endif + + if (*count == 0) { + if ((r=nr_stun_get_addrs(addrs, maxaddrs, count))) + ABORT(r); + + goto done; + } + + if (*count >= maxaddrs) { + r_log(NR_LOG_STUN, LOG_INFO, "Address list truncated from %d to %d", *count, maxaddrs); + *count = maxaddrs; + } + +#if 0 + if (*count > 0) { + /* TODO(ekr@rtfm.com): Commented out 2012-07-26. + + This code is currently not used in Firefox and needs to be + ported to 64-bit */ + children = RCALLOC((*count + 10) * sizeof(*children)); + if (!children) + ABORT(R_NO_MEMORY); + + assert(sizeof(size_t) == sizeof(*count)); + + if ((r=NR_reg_get_children(NR_STUN_REG_PREF_ADDRESS_PRFX, children, (size_t)(*count + 10), (size_t*)count))) + ABORT(r); + + for (i = 0; i < *count; ++i) { + if ((r=nr_reg_get_transport_addr(children[i], 0, &addrs[i].addr))) + ABORT(r); + } + } +#endif + + done: + + _status=0; + abort: + //RFREE(children); + return _status; +} + +int nr_stun_different_transaction(UCHAR *msg, size_t len, nr_stun_message *req) { int _status; diff --git a/dom/media/webrtc/transport/third_party/nICEr/src/stun/stun_util.h b/dom/media/webrtc/transport/third_party/nICEr/src/stun/stun_util.h @@ -44,6 +44,8 @@ int nr_stun_startup(void); int nr_stun_xor_mapped_address(UINT4 magicCookie, UINT12 transactionId, nr_transport_addr *from, nr_transport_addr *to); +int nr_stun_find_local_addresses(nr_local_addr addrs[], int maxaddrs, int *count); + int nr_stun_different_transaction(UCHAR *msg, size_t len, nr_stun_message *req); char* nr_stun_msg_type(int type); diff --git a/dom/media/webrtc/transport/third_party/nICEr/src/util/cb_args.c b/dom/media/webrtc/transport/third_party/nICEr/src/util/cb_args.c @@ -0,0 +1,57 @@ +/* +Copyright (c) 2007, Adobe Systems, Incorporated +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +* Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +* Neither the name of Adobe Systems, Network Resonance nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include <stdarg.h> +#include "nr_api.h" +#include "cb_args.h" + +void **nr_pack_cb_args(int ct,...) + { + void **vlist; + va_list ap; + int i; + + va_start(ap,ct); + if(!(vlist=RCALLOC(sizeof(void *)*ct+1))) + abort(); + + for(i=0;i<ct;i++){ + vlist[i]=va_arg(ap, void *); + } + + va_end(ap); + + return(vlist); + } + + + diff --git a/dom/media/webrtc/transport/third_party/nICEr/src/util/cb_args.h b/dom/media/webrtc/transport/third_party/nICEr/src/util/cb_args.h @@ -0,0 +1,41 @@ +/* +Copyright (c) 2007, Adobe Systems, Incorporated +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +* Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +* Neither the name of Adobe Systems, Network Resonance nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + + +#ifndef _cb_args_h +#define _cb_args_h + +void **nr_pack_cb_args(int ct,...); + +#endif + diff --git a/dom/media/webrtc/transport/third_party/nrappkit/nrappkit.gyp b/dom/media/webrtc/transport/third_party/nrappkit/nrappkit.gyp @@ -26,12 +26,22 @@ 'sources' : [ # Shared +# './src/share/nr_api.h', + './src/share/nr_common.h', +# './src/share/nr_dynlib.h', + './src/share/nr_reg_keys.h', +# './src/share/nr_startup.c', +# './src/share/nr_startup.h', +# './src/share/nrappkit_static_plugins.c', './src/port/generic/include' # libekr './src/util/libekr/assoc.h', +# './src/util/libekr/debug.c', +# './src/util/libekr/debug.h', './src/util/libekr/r_assoc.c', './src/util/libekr/r_assoc.h', +# './src/util/libekr/r_assoc_test.c', './src/util/libekr/r_common.h', './src/util/libekr/r_crc32.c', './src/util/libekr/r_crc32.h', @@ -41,9 +51,13 @@ './src/util/libekr/r_errors.c', './src/util/libekr/r_errors.h', './src/util/libekr/r_includes.h', +# './src/util/libekr/r_list.c', +# './src/util/libekr/r_list.h', './src/util/libekr/r_macros.h', './src/util/libekr/r_memory.c', './src/util/libekr/r_memory.h', + './src/util/libekr/r_replace.c', + './src/util/libekr/r_thread.h', './src/util/libekr/r_time.c', './src/util/libekr/r_time.h', './src/util/libekr/r_types.h', @@ -51,28 +65,67 @@ # Utilities './src/util/byteorder.c', './src/util/byteorder.h', + #'./src/util/escape.c', + #'./src/util/escape.h', + #'./src/util/filename.c', + #'./src/util/getopt.c', + #'./src/util/getopt.h', './src/util/hex.c', './src/util/hex.h', + #'./src/util/mem_util.c', + #'./src/util/mem_util.h', + #'./src/util/mutex.c', + #'./src/util/mutex.h', './src/util/p_buf.c', './src/util/p_buf.h', + #'./src/util/ssl_util.c', + #'./src/util/ssl_util.h', './src/util/util.c', './src/util/util.h', + #'./src/util/util_db.c', + #'./src/util/util_db.h', # Events +# './src/event/async_timer.c', './src/event/async_timer.h', +# './src/event/async_wait.c', './src/event/async_wait.h', + './src/event/async_wait_int.h', # Logging './src/log/r_log.c', './src/log/r_log.h', + #'./src/log/r_log_plugin.c', # Registry + './src/registry/c2ru.c', + './src/registry/c2ru.h', + #'./src/registry/mod_registry/mod_registry.c', + #'./src/registry/nrregctl.c', + #'./src/registry/nrregistryctl.c', './src/registry/registry.c', './src/registry/registry.h', './src/registry/registry_int.h', './src/registry/registry_local.c', + #'./src/registry/registry_plugin.c', './src/registry/registry_vtbl.h', './src/registry/registrycb.c', + #'./src/registry/registryd.c', + #'./src/registry/regrpc.h', + #'./src/registry/regrpc_client.c', + #'./src/registry/regrpc_client.h', + #'./src/registry/regrpc_client_cb.c', + #'./src/registry/regrpc_clnt.c', + #'./src/registry/regrpc_server.c', + #'./src/registry/regrpc_svc.c', + #'./src/registry/regrpc_xdr.c', + + # Statistics + #'./src/stats/nrstats.c', + #'./src/stats/nrstats.h', + #'./src/stats/nrstats_app.c', + #'./src/stats/nrstats_int.h', + #'./src/stats/nrstats_memory.c', ], 'defines' : [ diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/event/async_timer.h b/dom/media/webrtc/transport/third_party/nrappkit/src/event/async_timer.h @@ -40,9 +40,13 @@ #ifndef _async_timer_h #define _async_timer_h -// These are defined in dom/media/webrtc/transport/nr_timer.cpp + +int NR_async_timer_init(void); int NR_async_timer_set(int delay_ms,NR_async_cb cb,void *cb_arg,char *function,int line,void **handle); int NR_async_timer_cancel(void *handle); +int NR_async_timer_update_time(struct timeval *tv); +int NR_async_timer_next_timeout(int *delay_ms); +int NR_async_timer_sanity_check_for_cb_deleted(NR_async_cb cb,void *cb_arg); #define NR_ASYNC_TIMER_SET(d,c,a,hp) NR_async_timer_set(d,c,a,(char *)__FUNCTION__,__LINE__,hp) diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/event/async_wait.h b/dom/media/webrtc/transport/third_party/nrappkit/src/event/async_wait.h @@ -51,12 +51,13 @@ typedef void (*NR_async_cb)(NR_SOCKET resource,int how,void *arg); #define NR_ASYNC_WAIT_WRITE 1 -// These are defined in dom/media/webrtc/transport/nr_socket_prsock.cpp +int NR_async_wait_init(void); int NR_async_wait(NR_SOCKET sock, int how, NR_async_cb cb,void *cb_arg, char *function,int line); int NR_async_cancel(NR_SOCKET sock,int how); -// defined in dom/media/webrtc/transport/nr_timer.cpp int NR_async_schedule(NR_async_cb cb,void *arg,char *function,int line); +int NR_async_event_wait(int *eventsp); +int NR_async_event_wait2(int *eventsp,struct timeval *tv); #ifdef NR_DEBUG_ASYNC diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/event/async_wait_int.h b/dom/media/webrtc/transport/third_party/nrappkit/src/event/async_wait_int.h @@ -0,0 +1,62 @@ +/** + async_wait_int.h + + + Copyright (C) 2004, Network Resonance, Inc. + Copyright (C) 2006, Network Resonance, Inc. + All Rights Reserved + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of Network Resonance, Inc. nor the name of any + contributors to this software may be used to endorse or promote + products derived from this software without specific prior written + permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + + + ekr@rtfm.com Sun Feb 22 19:16:01 2004 + */ + + +#ifndef _async_wait_int_h +#define _async_wait_int_h + + +typedef struct callback_ { + NR_async_cb cb; + void *arg; + int how; + int resource; + void *backptr; + + char *func; + int free_func; + int line; + TAILQ_ENTRY(callback_) entry; +} callback; + +int nr_async_create_cb(NR_async_cb cb,void *arg,int how, + int resource,char *func,int line,callback **cbp); +int nr_async_destroy_cb(callback **cbp); + +#endif + diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/log/r_log.c b/dom/media/webrtc/transport/third_party/nrappkit/src/log/r_log.c @@ -53,7 +53,9 @@ #include <registry.h> #include <time.h> -#include <csi_platform.h> + +#include "nr_common.h" +#include "nr_reg_keys.h" #define LOGGING_DEFAULT_LEVEL 5 @@ -225,6 +227,15 @@ int r_log_register(char *facility_name,int *log_facility) return(_status); } +int r_log_facility(int facility,char **typename) + { + if(facility >= 0 && facility < log_type_ct){ + *typename=log_types[facility].facility_name; + return(0); + } + return(R_NOT_FOUND); + } + static int r_log_get_reg_level(NR_registry name, int *out) { char level[32]; @@ -382,6 +393,72 @@ int noop_vlog(int facility,int level,const char *format,va_list ap) return(0); } +int r_log_e(int facility,int level,const char *format,...) + { + va_list ap; + + va_start(ap,format); + r_vlog_e(facility,level,format,ap); + va_end(ap); + + return(0); + } + +int r_vlog_e(int facility,int level,const char *format,va_list ap) + { + char log_fmt_buf[MAX_ERROR_STRING_SIZE]; + if(r_logging(facility,level)) { + int formatlen = strlen(format); + + if(formatlen+2 > MAX_ERROR_STRING_SIZE) + return(1); + + strncpy(log_fmt_buf, format, formatlen); + strcpy(&log_fmt_buf[formatlen], ": "); + snprintf(&log_fmt_buf[formatlen+2], MAX_ERROR_STRING_SIZE - formatlen - 2, "%s", +#ifdef WIN32 + strerror(WSAGetLastError())); +#else + strerror(errno)); +#endif + log_fmt_buf[MAX_ERROR_STRING_SIZE-1]=0; + + r_vlog(facility,level,log_fmt_buf,ap); + } + return(0); + } + +int r_log_nr(int facility,int level,int r,const char *format,...) + { + va_list ap; + + va_start(ap,format); + r_vlog_nr(facility,level,r,format,ap); + va_end(ap); + + return(0); + } + +int r_vlog_nr(int facility,int level,int r,const char *format,va_list ap) + { + char log_fmt_buf[MAX_ERROR_STRING_SIZE]; + if(r_logging(facility,level)) { + int formatlen = strlen(format); + + if(formatlen+2 > MAX_ERROR_STRING_SIZE) + return(1); + strncpy(log_fmt_buf, format, formatlen); + strcpy(&log_fmt_buf[formatlen], ": "); + snprintf(&log_fmt_buf[formatlen+2], MAX_ERROR_STRING_SIZE - formatlen - 2, "%s", + nr_strerror(r)); + + log_fmt_buf[MAX_ERROR_STRING_SIZE-1]=0; + + r_vlog(facility,level,log_fmt_buf,ap); + } + return(0); + } + static int r_logging_dest(int dest_index, int facility, int level) { int thresh; diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/log/r_log.h b/dom/media/webrtc/transport/third_party/nrappkit/src/log/r_log.h @@ -55,7 +55,23 @@ int r_log(int facility,int level,const char *fmt,...) int r_vlog(int facility,int level,const char *fmt,va_list ap); int r_dump(int facility,int level,char *name,char *data,int len); +int r_log_e(int facility,int level,const char *fmt,...) +#ifdef __GNUC__ + __attribute__ ((format (printf, 3, 4))) +#endif +; + +int r_vlog_e(int facility,int level,const char *fmt,va_list ap); +int r_log_nr(int facility,int level,int r,const char *fmt,...) +#ifdef __GNUC__ + __attribute__ ((format (printf, 4, 5))) +#endif +; + +int r_vlog_nr(int facility,int level,int r,const char *fmt,va_list ap); + int r_log_register(char *tipename,int *facility); +int r_log_facility(int facility,char **tipename); int r_logging(int facility, int level); int r_log_init(void); diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/plugin/nr_plugin.h b/dom/media/webrtc/transport/third_party/nrappkit/src/plugin/nr_plugin.h @@ -0,0 +1,57 @@ +/** + nr_plugin.h + + + Copyright (C) 2006, Network Resonance, Inc. + All Rights Reserved + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of Network Resonance, Inc. nor the name of any + contributors to this software may be used to endorse or promote + products derived from this software without specific prior written + permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + + + ekr@networkresonance.com Mon Jun 19 18:18:54 2006 + */ + + +#ifndef _nr_plugin_h +#define _nr_plugin_h + +typedef int (NR_plugin_hook)(void); + +typedef struct NR_plugin_hook_def_ { + char *type; + NR_plugin_hook *func; +} NR_plugin_hook_def; + +typedef struct NR_plugin_def_ { + int api_version; // Should be 1 + char *name; + char *version; + NR_plugin_hook_def *hooks; +} NR_plugin_def; + +#endif + diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/registry/c2ru.c b/dom/media/webrtc/transport/third_party/nrappkit/src/registry/c2ru.c @@ -0,0 +1,320 @@ +/* + * + * c2ru.c + * + * $Source: /Users/ekr/tmp/nrappkit-dump/nrappkit/src/registry/c2ru.c,v $ + * $Revision: 1.3 $ + * $Date: 2007/06/26 22:37:50 $ + * + * c2r utility methods + * + * + * Copyright (C) 2005, Network Resonance, Inc. + * Copyright (C) 2006, Network Resonance, Inc. + * All Rights Reserved + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Network Resonance, Inc. nor the name of any + * contributors to this software may be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + */ + +#include <sys/queue.h> +#include <string.h> +#include <registry.h> +#include "nr_common.h" +#include <r_errors.h> +#include <r_macros.h> +#include <ctype.h> +#include "c2ru.h" + + +#define NRGET(func, type, get) \ +int \ +func(NR_registry parent, char *child, type **out) \ +{ \ + int r, _status; \ + NR_registry registry; \ + type tmp; \ + \ + if ((r = nr_c2ru_make_registry(parent, child, registry))) \ + ABORT(r); \ + \ + if ((r = get(registry, &tmp))) { \ + if (r != R_NOT_FOUND) \ + ABORT(r); \ + *out = 0; \ + } \ + else { \ + *out = RCALLOC(sizeof(tmp)); \ + if (*out == 0) \ + ABORT(R_NO_MEMORY); \ + **out = tmp; \ + } \ + \ + _status = 0; \ +abort: \ + return (_status); \ +} + +int +nr_c2ru_get_char(NR_registry parent, char *child, char **out) +{ + int r, _status; + NR_registry registry; + char tmp; + + if ((r = nr_c2ru_make_registry(parent, child, registry))) + ABORT(r); + + if ((r = NR_reg_get_char(registry, &tmp))) { + if (r != R_NOT_FOUND) + ABORT(r); + *out = 0; + } + else { + *out = RCALLOC(sizeof(tmp)); + if (*out == 0) + ABORT(R_NO_MEMORY); + **out = tmp; + } + + _status = 0; +abort: + return (_status); +} +NRGET(nr_c2ru_get_uchar, UCHAR, NR_reg_get_uchar) +NRGET(nr_c2ru_get_int2, INT2, NR_reg_get_int2) +NRGET(nr_c2ru_get_uint2, UINT2, NR_reg_get_uint2) +NRGET(nr_c2ru_get_int4, INT4, NR_reg_get_int4) +NRGET(nr_c2ru_get_uint4, UINT4, NR_reg_get_uint4) +NRGET(nr_c2ru_get_int8, INT8, NR_reg_get_int8) +NRGET(nr_c2ru_get_uint8, UINT8, NR_reg_get_uint8) +NRGET(nr_c2ru_get_double, double, NR_reg_get_double) +NRGET(nr_c2ru_get_string, char*, NR_reg_alloc_string) +NRGET(nr_c2ru_get_data, Data, NR_reg_alloc_data) + + +#define NRSET(func, type, set) \ +int \ +func(NR_registry parent, char *child, type *in) \ +{ \ + int r, _status; \ + NR_registry registry; \ + \ + if (in == 0) \ + return 0; \ + \ + if ((r = nr_c2ru_make_registry(parent, child, registry))) \ + ABORT(r); \ + \ + if ((r = set(registry, *in))) \ + ABORT(r); \ + \ + _status = 0; \ +abort: \ + return (_status); \ +} + +NRSET(nr_c2ru_set_char, char, NR_reg_set_char) +NRSET(nr_c2ru_set_uchar, UCHAR, NR_reg_set_uchar) +NRSET(nr_c2ru_set_int2, INT2, NR_reg_set_int2) +NRSET(nr_c2ru_set_uint2, UINT2, NR_reg_set_uint2) +NRSET(nr_c2ru_set_int4, INT4, NR_reg_set_int4) +NRSET(nr_c2ru_set_uint4, UINT4, NR_reg_set_uint4) +NRSET(nr_c2ru_set_int8, INT8, NR_reg_set_int8) +NRSET(nr_c2ru_set_uint8, UINT8, NR_reg_set_uint8) +NRSET(nr_c2ru_set_double, double, NR_reg_set_double) +NRSET(nr_c2ru_set_string, char*, NR_reg_set_string) + +int +nr_c2ru_set_data(NR_registry parent, char *child, Data *in) +{ + int r, _status; + NR_registry registry; + + if (in == 0) + return 0; + + if ((r = nr_c2ru_make_registry(parent, child, registry))) + ABORT(r); + + if ((r = NR_reg_set_bytes(registry, in->data, in->len))) + ABORT(r); + + _status = 0; +abort: + return (_status); +} + +#define NRFREE(func, type) \ +int \ +func(type *in) \ +{ \ + if (in) \ + RFREE(in); \ + return 0; \ +} + +NRFREE(nr_c2ru_free_char, char) +NRFREE(nr_c2ru_free_uchar, UCHAR) +NRFREE(nr_c2ru_free_int2, INT2) +NRFREE(nr_c2ru_free_uint2, UINT2) +NRFREE(nr_c2ru_free_int4, INT4) +NRFREE(nr_c2ru_free_uint4, UINT4) +NRFREE(nr_c2ru_free_int8, INT8) +NRFREE(nr_c2ru_free_uint8, UINT8) +NRFREE(nr_c2ru_free_double, double) + + +int +nr_c2ru_free_string(char **in) +{ + if (*in) + RFREE(*in); + if (in) + RFREE(in); + return 0; +} + +int +nr_c2ru_free_data(Data *in) +{ + int r, _status; + + if (in) { + if ((r=r_data_destroy(&in))) + ABORT(r); + } + + _status = 0; +abort: + return (_status); +} + +int +nr_c2ru_get_children(NR_registry parent, char *child, void *ptr, size_t size, int (*get)(NR_registry, void*)) +{ + int r, _status; + NR_registry registry; + unsigned int count; + unsigned int i; + NR_registry name; + struct entry { TAILQ_ENTRY(entry) entries; } *entry; + TAILQ_HEAD(, entry) *tailq = (void*)ptr; + + TAILQ_INIT(tailq); + + if ((r=nr_c2ru_make_registry(parent, child, registry))) + ABORT(r); + + if ((r=NR_reg_get_child_count(registry, &count))) { + if (r != R_NOT_FOUND) + ABORT(r); + } + else { + for (i = 0; i < count; ++i) { + if ((r=NR_reg_get_child_registry(registry, i, name))) { + /* ignore R_NOT_FOUND errors */ + if (r == R_NOT_FOUND) + continue; + else + ABORT(r); + } + + if ((r=get(name, &entry))) { + /* ignore R_NOT_FOUND errors */ + if (r == R_NOT_FOUND) + continue; + else + ABORT(r); + } + + TAILQ_INSERT_TAIL(tailq, entry, entries); + } + } + + _status = 0; +abort: + return (_status); +} + +int +nr_c2ru_set_children(NR_registry parent, char *child, void *ptr, int (*set)(NR_registry, void*), int (*label)(NR_registry, void*, char[NR_REG_MAX_NR_REGISTRY_LEN])) +{ + int r, _status; + NR_registry registry; + int i; + NR_registry name; + char buffer[NR_REG_MAX_NR_REGISTRY_LEN]; + struct entry { TAILQ_ENTRY(entry) entries; } *entry; + TAILQ_HEAD(, entry) *tailq = (void*)ptr; + + if ((r=nr_c2ru_make_registry(parent, child, registry))) + ABORT(r); + + (void)NR_reg_del(registry); + + i = 0; + TAILQ_FOREACH(entry, tailq, entries) { + if (label == 0 || (r=label(registry, entry, buffer))) { + snprintf(buffer, sizeof(buffer), "%d", i); + } + if ((r=nr_c2ru_make_registry(registry, buffer, name))) + ABORT(r); + + if ((r=set(name, entry))) + ABORT(r); + + ++i; + } + + _status = 0; +abort: + return (_status); +} + +int +nr_c2ru_free_children(void *ptr, int (*free)(void*)) +{ + struct entry { TAILQ_ENTRY(entry) entries; } *entry; + TAILQ_HEAD(, entry) *tailq = (void*)ptr; + + while (! TAILQ_EMPTY(tailq)) { + entry = TAILQ_FIRST(tailq); + TAILQ_REMOVE(tailq, entry, entries); + (void)free(entry); + } + + return 0; +} + +/* requires parent already in legal form */ +int +nr_c2ru_make_registry(NR_registry parent, char *child, NR_registry out) +{ + return NR_reg_make_registry(parent, child, out); +} diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/registry/c2ru.h b/dom/media/webrtc/transport/third_party/nrappkit/src/registry/c2ru.h @@ -0,0 +1,96 @@ +/* + * + * c2ru.h + * + * $Source: /Users/ekr/tmp/nrappkit-dump/nrappkit/src/registry/c2ru.h,v $ + * $Revision: 1.2 $ + * $Date: 2006/08/16 19:39:13 $ + * + * c2r utility methods + * + * + * Copyright (C) 2005, Network Resonance, Inc. + * Copyright (C) 2006, Network Resonance, Inc. + * All Rights Reserved + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Network Resonance, Inc. nor the name of any + * contributors to this software may be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + */ + +#ifndef __C2RU_H__ +#define __C2RU_H__ + +#include <sys/types.h> +#include <r_types.h> +#include <r_data.h> +#include "registry_int.h" + +int nr_c2ru_get_char(NR_registry parent, char *child, char **out); +int nr_c2ru_get_uchar(NR_registry parent, char *child, UCHAR **out); +int nr_c2ru_get_int2(NR_registry parent, char *child, INT2 **out); +int nr_c2ru_get_uint2(NR_registry parent, char *child, UINT2 **out); +int nr_c2ru_get_int4(NR_registry parent, char *child, INT4 **out); +int nr_c2ru_get_uint4(NR_registry parent, char *child, UINT4 **out); +int nr_c2ru_get_int8(NR_registry parent, char *child, INT8 **out); +int nr_c2ru_get_uint8(NR_registry parent, char *child, UINT8 **out); +int nr_c2ru_get_double(NR_registry parent, char *child, double **out); +int nr_c2ru_get_data(NR_registry parent, char *child, Data **out); +int nr_c2ru_get_string(NR_registry parent, char *child, char ***out); + +int nr_c2ru_set_char(NR_registry parent, char *child, char *data); +int nr_c2ru_set_uchar(NR_registry parent, char *child, UCHAR *data); +int nr_c2ru_set_int2(NR_registry parent, char *child, INT2 *data); +int nr_c2ru_set_uint2(NR_registry parent, char *child, UINT2 *data); +int nr_c2ru_set_int4(NR_registry parent, char *child, INT4 *data); +int nr_c2ru_set_uint4(NR_registry parent, char *child, UINT4 *data); +int nr_c2ru_set_int8(NR_registry parent, char *child, INT8 *data); +int nr_c2ru_set_uint8(NR_registry parent, char *child, UINT8 *data); +int nr_c2ru_set_double(NR_registry parent, char *child, double *data); +int nr_c2ru_set_registry(NR_registry parent, char *child); +int nr_c2ru_set_data(NR_registry parent, char *child, Data *data); +int nr_c2ru_set_string(NR_registry parent, char *child, char **data); + +int nr_c2ru_free_char(char *data); +int nr_c2ru_free_uchar(UCHAR *data); +int nr_c2ru_free_int2(INT2 *data); +int nr_c2ru_free_uint2(UINT2 *data); +int nr_c2ru_free_int4(INT4 *data); +int nr_c2ru_free_uint4(UINT4 *data); +int nr_c2ru_free_int8(INT8 *data); +int nr_c2ru_free_uint8(UINT8 *data); +int nr_c2ru_free_double(double *data); +int nr_c2ru_free_data(Data *data); +int nr_c2ru_free_string(char **data); + +int nr_c2ru_get_children(NR_registry parent, char *child, void *ptr, size_t size, int (*get)(NR_registry, void*)); +int nr_c2ru_set_children(NR_registry parent, char *child, void *ptr, int (*set)(NR_registry, void*), int (*label)(NR_registry, void*, char[NR_REG_MAX_NR_REGISTRY_LEN])); +int nr_c2ru_free_children(void *ptr, int (*free)(void*)); + +int nr_c2ru_make_registry(NR_registry parent, char *child, NR_registry out); + +#endif diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/registry/registry.c b/dom/media/webrtc/transport/third_party/nrappkit/src/registry/registry.c @@ -53,14 +53,15 @@ #include <openssl/ssl.h> #endif #include <ctype.h> -#include <csi_platform.h> #include "registry.h" #include "registry_int.h" #include "registry_vtbl.h" #include "r_assoc.h" +#include "nr_common.h" #include "r_log.h" #include "r_errors.h" #include "r_macros.h" +#include "c2ru.h" /* vtbl used to switch hit between local and remote invocations */ static nr_registry_module *reg_vtbl = 0; @@ -127,9 +128,11 @@ func(NR_registry name, type *out) \ NRREGGET(NR_reg_get_char, get_char, char) NRREGGET(NR_reg_get_uchar, get_uchar, UCHAR) +NRREGGET(NR_reg_get_int2, get_int2, INT2) NRREGGET(NR_reg_get_uint2, get_uint2, UINT2) NRREGGET(NR_reg_get_int4, get_int4, INT4) NRREGGET(NR_reg_get_uint4, get_uint4, UINT4) +NRREGGET(NR_reg_get_int8, get_int8, INT8) NRREGGET(NR_reg_get_uint8, get_uint8, UINT8) NRREGGET(NR_reg_get_double, get_double, double) @@ -157,6 +160,12 @@ NR_reg_get_length(NR_registry name, size_t *length) return reg_vtbl->vtbl->get_length(name, length); } +int +NR_reg_get_type(NR_registry name, NR_registry_type type) +{ + return reg_vtbl->vtbl->get_type(name, type); +} + #define NRREGSET(func, method, type) \ int \ func(NR_registry name, type data) \ @@ -166,8 +175,13 @@ func(NR_registry name, type data) \ NRREGSET(NR_reg_set_char, set_char, char) NRREGSET(NR_reg_set_uchar, set_uchar, UCHAR) +NRREGSET(NR_reg_set_int2, set_int2, INT2) +NRREGSET(NR_reg_set_uint2, set_uint2, UINT2) NRREGSET(NR_reg_set_int4, set_int4, INT4) NRREGSET(NR_reg_set_uint4, set_uint4, UINT4) +NRREGSET(NR_reg_set_int8, set_int8, INT8) +NRREGSET(NR_reg_set_uint8, set_uint8, UINT8) +NRREGSET(NR_reg_set_double, set_double, double) NRREGSET(NR_reg_set_string, set_string, char*) int @@ -190,6 +204,12 @@ NR_reg_del(NR_registry name) } int +NR_reg_fin(NR_registry name) +{ + return reg_vtbl->vtbl->fin(name); +} + +int NR_reg_get_child_count(NR_registry parent, unsigned int *count) { assert(sizeof(count) == sizeof(size_t)); @@ -229,6 +249,25 @@ NR_reg_get_child_registry(NR_registry parent, unsigned int i, NR_registry child) return(_status); } +int +NR_reg_get_children(NR_registry parent, NR_registry *children, size_t size, size_t *length) +{ + return reg_vtbl->vtbl->get_children(parent, children, size, length); +} + +int +NR_reg_dump() +{ + int r, _status; + + if ((r=reg_vtbl->vtbl->dump(0))) + ABORT(r); + + _status=0; + abort: + return(_status); +} + // convenience methods, call RFREE on the returned data int NR_reg_alloc_data(NR_registry name, Data *data) @@ -356,10 +395,50 @@ abort: \ NRGET2(NR_reg_get2_char, char, NR_reg_get_char) NRGET2(NR_reg_get2_uchar, UCHAR, NR_reg_get_uchar) +NRGET2(NR_reg_get2_int2, INT2, NR_reg_get_int2) NRGET2(NR_reg_get2_uint2, UINT2, NR_reg_get_uint2) +NRGET2(NR_reg_get2_int4, INT4, NR_reg_get_int4) +NRGET2(NR_reg_get2_uint4, UINT4, NR_reg_get_uint4) +NRGET2(NR_reg_get2_int8, INT8, NR_reg_get_int8) +NRGET2(NR_reg_get2_uint8, UINT8, NR_reg_get_uint8) +NRGET2(NR_reg_get2_double, double, NR_reg_get_double) NRGET2(NR_reg_alloc2_string, char*, NR_reg_alloc_string) NRGET2(NR_reg_alloc2_data, Data, NR_reg_alloc_data) +int +NR_reg_get2_bytes(NR_registry parent, char *child, UCHAR *out, size_t size, size_t *length) +{ + int r, _status; + NR_registry registry; + + if ((r=NR_reg_make_registry(parent, child, registry))) + ABORT(r); + + if ((r=NR_reg_get_bytes(registry, out, size, length))) + ABORT(r); + + _status = 0; +abort: + return (_status); +} + +int +NR_reg_get2_string(NR_registry parent, char *child, char *out, size_t size) +{ + int r, _status; + NR_registry registry; + + if ((r=NR_reg_make_registry(parent, child, registry))) + ABORT(r); + + if ((r=NR_reg_get_string(registry, out, size))) + ABORT(r); + + _status = 0; +abort: + return (_status); +} + /* More convenience functions: the same as their parents but they take a prefix and a suffix */ #define NRSET2(func, type, set) \ @@ -381,9 +460,102 @@ abort: \ return (_status); \ } +NRSET2(NR_reg_set2_char, char, NR_reg_set_char) NRSET2(NR_reg_set2_uchar, UCHAR, NR_reg_set_uchar) +NRSET2(NR_reg_set2_int2, INT2, NR_reg_set_int2) +NRSET2(NR_reg_set2_uint2, UINT2, NR_reg_set_uint2) +NRSET2(NR_reg_set2_int4, INT4, NR_reg_set_int4) +NRSET2(NR_reg_set2_uint4, UINT4, NR_reg_set_uint4) +NRSET2(NR_reg_set2_int8, INT8, NR_reg_set_int8) +NRSET2(NR_reg_set2_uint8, UINT8, NR_reg_set_uint8) +NRSET2(NR_reg_set2_double, double, NR_reg_set_double) NRSET2(NR_reg_set2_string, char*, NR_reg_set_string) +int +NR_reg_set2_bytes(NR_registry prefix, char *name, UCHAR *data, size_t length) +{ + int r, _status; + NR_registry registry; + + if ((r = NR_reg_make_registry(prefix, name, registry))) + ABORT(r); + + if ((r = NR_reg_set_bytes(registry, data, length))) + ABORT(r); + + _status = 0; +abort: + return (_status); +} + + +int +NR_reg_make_child_registry(NR_registry parent, NR_registry descendant, unsigned int generation, NR_registry child) +{ + int _status; + size_t length; + + length = strlen(parent); + + if (strncasecmp(parent, descendant, length)) + ABORT(R_BAD_ARGS); + + while (descendant[length] != '\0') { + if (descendant[length] == '.') { + if (generation == 0) + break; + + --generation; + } + + ++length; + if (length >= sizeof(NR_registry)) + ABORT(R_BAD_ARGS); + } + + strncpy(child, descendant, length); + child[length] = '\0'; + + _status=0; + abort: + return(_status); +} + +int +NR_reg_get2_child_count(NR_registry base, NR_registry name, unsigned int *count) + { + int r, _status; + NR_registry registry; + + if ((r=nr_c2ru_make_registry(base, name, registry))) + ABORT(r); + + if (r=NR_reg_get_child_count(registry,count)) + ABORT(r); + + _status=0; + abort: + return(_status); + } + +int +NR_reg_get2_child_registry(NR_registry base, NR_registry name, unsigned int i, NR_registry child) + { + int r, _status; + NR_registry registry; + + if ((r=nr_c2ru_make_registry(base, name, registry))) + ABORT(r); + + if (r=NR_reg_get_child_registry(registry, i, child)) + ABORT(r); + + _status=0; + abort: + return(_status); + } + + /* requires parent already in legal form */ int NR_reg_make_registry(NR_registry parent, char *child, NR_registry out) diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/registry/registry.h b/dom/media/webrtc/transport/third_party/nrappkit/src/registry/registry.h @@ -67,9 +67,11 @@ int NR_reg_initted(void); int NR_reg_get_char(NR_registry name, char *out); int NR_reg_get_uchar(NR_registry name, UCHAR *out); +int NR_reg_get_int2(NR_registry name, INT2 *out); int NR_reg_get_uint2(NR_registry name, UINT2 *out); int NR_reg_get_int4(NR_registry name, INT4 *out); int NR_reg_get_uint4(NR_registry name, UINT4 *out); +int NR_reg_get_int8(NR_registry name, INT8 *out); int NR_reg_get_uint8(NR_registry name, UINT8 *out); int NR_reg_get_double(NR_registry name, double *out); int NR_reg_get_registry(NR_registry name, NR_registry out); @@ -77,33 +79,63 @@ int NR_reg_get_registry(NR_registry name, NR_registry out); int NR_reg_get_bytes(NR_registry name, UCHAR *out, size_t size, size_t *length); int NR_reg_get_string(NR_registry name, char *out, size_t size); int NR_reg_get_length(NR_registry name, size_t *length); +int NR_reg_get_type(NR_registry name, NR_registry_type type); int NR_reg_get2_char(NR_registry prefix, char *name, char *); int NR_reg_get2_uchar(NR_registry prefix, char *name, UCHAR *); +int NR_reg_get2_int2(NR_registry prefix, char *name, INT2 *); int NR_reg_get2_uint2(NR_registry prefix, char *name, UINT2 *); +int NR_reg_get2_int4(NR_registry prefix, char *name, INT4 *); +int NR_reg_get2_uint4(NR_registry prefix, char *name, UINT4 *); +int NR_reg_get2_int8(NR_registry prefix, char *name, INT8 *); +int NR_reg_get2_uint8(NR_registry prefix, char *name, UINT8 *); +int NR_reg_get2_double(NR_registry prefix, char *name, double *); +int NR_reg_get2_bytes(NR_registry prefix, char *name, UCHAR *out, size_t size, size_t *length); +int NR_reg_get2_string(NR_registry prefix, char *name, char *out, size_t size); int NR_reg_alloc2_string(NR_registry prefix, char *name, char **); int NR_reg_alloc2_data(NR_registry prefix, char *name, Data *); int NR_reg_set_char(NR_registry name, char data); int NR_reg_set_uchar(NR_registry name, UCHAR data); +int NR_reg_set_int2(NR_registry name, INT2 data); +int NR_reg_set_uint2(NR_registry name, UINT2 data); int NR_reg_set_int4(NR_registry name, INT4 data); int NR_reg_set_uint4(NR_registry name, UINT4 data); +int NR_reg_set_int8(NR_registry name, INT8 data); +int NR_reg_set_uint8(NR_registry name, UINT8 data); +int NR_reg_set_double(NR_registry name, double data); int NR_reg_set_registry(NR_registry name); int NR_reg_set_bytes(NR_registry name, UCHAR *data, size_t length); int NR_reg_set_string(NR_registry name, char *data); +int NR_reg_set2_char(NR_registry prefix, char *name, char data); int NR_reg_set2_uchar(NR_registry prefix, char *name, UCHAR data); - +int NR_reg_set2_int2(NR_registry prefix, char *name, INT2 data); +int NR_reg_set2_uint2(NR_registry prefix, char *name, UINT2 data); +int NR_reg_set2_int4(NR_registry prefix, char *name, INT4 data); +int NR_reg_set2_uint4(NR_registry prefix, char *name, UINT4 data); +int NR_reg_set2_int8(NR_registry prefix, char *name, INT8 data); +int NR_reg_set2_uint8(NR_registry prefix, char *name, UINT8 data); +int NR_reg_set2_double(NR_registry prefix, char *name, double data); + +int NR_reg_set2_bytes(NR_registry prefix, char *name, UCHAR *data, size_t length); int NR_reg_set2_string(NR_registry prefix, char *name, char *data); int NR_reg_del(NR_registry name); +int NR_reg_fin(NR_registry name); + int NR_reg_get_child_count(NR_registry parent, unsigned int *count); int NR_reg_get_child_registry(NR_registry parent, unsigned int i, NR_registry child); +int NR_reg_get2_child_count(NR_registry base, NR_registry name, unsigned int *count); +int NR_reg_get2_child_registry(NR_registry base, NR_registry name, unsigned int i, NR_registry child); +int NR_reg_get_children(NR_registry parent, NR_registry children[], size_t size, size_t *length); + +int NR_reg_dump(void); /* convenience methods, call RFREE on the returned data */ int NR_reg_alloc_data(NR_registry name, Data *data); @@ -114,7 +146,9 @@ int NR_reg_alloc_string(NR_registry name, char **data); #define NR_REG_CB_ACTION_DELETE (1<<2) #define NR_REG_CB_ACTION_FINAL (1<<6) int NR_reg_register_callback(NR_registry name, char action, void (*cb)(void *cb_arg, char action, NR_registry name), void *cb_arg); +int NR_reg_unregister_callback(NR_registry name, char action, void (*cb)(void *cb_arg, char action, NR_registry name)); int NR_reg_make_registry(NR_registry parent, char *child, NR_registry out); +int NR_reg_make_child_registry(NR_registry parent, NR_registry descendant, unsigned int generation, NR_registry child); #endif diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/registry/registry_int.h b/dom/media/webrtc/transport/third_party/nrappkit/src/registry/registry_int.h @@ -1,3 +1,13 @@ +#if 0 +#define NR_LOG_REGISTRY BLAHBLAH() +#define LOG_REGISTRY BLAHBLAH() +static int BLAHBLAH() { +int blahblah; +r_log_register("registry",&blahblah); +return blahblah; +} +#endif + /* * * registry_int.h diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/registry/registry_local.c b/dom/media/webrtc/transport/third_party/nrappkit/src/registry/registry_local.c @@ -54,11 +54,11 @@ #endif #include <ctype.h> #include <stdlib.h> -#include <csi_platform.h> #include "registry.h" #include "registry_int.h" #include "registry_vtbl.h" #include "r_assoc.h" +#include "nr_common.h" #include "r_log.h" #include "r_errors.h" #include "r_macros.h" @@ -102,25 +102,35 @@ typedef struct nr_array_registry_node_ { static int nr_reg_local_init(nr_registry_module *me); static int nr_reg_local_get_char(NR_registry name, char *data); static int nr_reg_local_get_uchar(NR_registry name, UCHAR *data); +static int nr_reg_local_get_int2(NR_registry name, INT2 *data); static int nr_reg_local_get_uint2(NR_registry name, UINT2 *data); static int nr_reg_local_get_int4(NR_registry name, INT4 *data); static int nr_reg_local_get_uint4(NR_registry name, UINT4 *data); +static int nr_reg_local_get_int8(NR_registry name, INT8 *data); static int nr_reg_local_get_uint8(NR_registry name, UINT8 *data); static int nr_reg_local_get_double(NR_registry name, double *data); static int nr_reg_local_get_registry(NR_registry name, NR_registry data); static int nr_reg_local_get_bytes(NR_registry name, UCHAR *data, size_t size, size_t *length); static int nr_reg_local_get_string(NR_registry name, char *data, size_t size); static int nr_reg_local_get_length(NR_registry name, size_t *len); +static int nr_reg_local_get_type(NR_registry name, NR_registry_type type); static int nr_reg_local_set_char(NR_registry name, char data); static int nr_reg_local_set_uchar(NR_registry name, UCHAR data); +static int nr_reg_local_set_int2(NR_registry name, INT2 data); +static int nr_reg_local_set_uint2(NR_registry name, UINT2 data); static int nr_reg_local_set_int4(NR_registry name, INT4 data); static int nr_reg_local_set_uint4(NR_registry name, UINT4 data); +static int nr_reg_local_set_int8(NR_registry name, INT8 data); +static int nr_reg_local_set_uint8(NR_registry name, UINT8 data); +static int nr_reg_local_set_double(NR_registry name, double data); static int nr_reg_local_set_registry(NR_registry name); static int nr_reg_local_set_bytes(NR_registry name, UCHAR *data, size_t length); static int nr_reg_local_set_string(NR_registry name, char *data); static int nr_reg_local_del(NR_registry name); static int nr_reg_local_get_child_count(NR_registry parent, size_t *count); static int nr_reg_local_get_children(NR_registry parent, NR_registry *data, size_t size, size_t *length); +static int nr_reg_local_fin(NR_registry name); +static int nr_reg_local_dump(int sorted); static int nr_reg_insert_node(char *name, void *node); static int nr_reg_change_node(char *name, void *node, void *old); static int nr_reg_get(char *name, int type, void *out); @@ -150,6 +160,7 @@ static int nr_reg_local_iter(NR_registry prefix, int (*action)(void *ptr, r_asso static int nr_reg_local_iter_delete(void *ptr, r_assoc_iterator *iter, char *prefix, char *name, nr_registry_node *node); static int nr_reg_local_find_children(void *ptr, r_assoc_iterator *iter, char *prefix, char *name, nr_registry_node *node); static int nr_reg_local_count_children(void *ptr, r_assoc_iterator *iter, char *prefix, char *name, nr_registry_node *node); +static int nr_reg_local_dump_print(void *ptr, r_assoc_iterator *iter, char *prefix, char *name, nr_registry_node *node); @@ -271,6 +282,29 @@ nr_reg_local_count_children(void *ptr, r_assoc_iterator *iter, char *prefix, cha return 0; } +int +nr_reg_local_dump_print(void *ptr, r_assoc_iterator *iter, char *prefix, char *name, nr_registry_node *node) +{ + int _status; + int freeit = 0; + char *data = 0; + + /* only print leaf nodes */ + if (node->type != NR_REG_TYPE_REGISTRY) { + data = nr_reg_alloc_node_data(name, node, &freeit); + if (ptr) + fprintf((FILE*)ptr, "%s: %s\n", name, data); + else + r_log(NR_LOG_REGISTRY, LOG_INFO, "%s: %s", name, data); + if (freeit) + RFREE(data); + } + + _status=0; + //abort: + return(_status); +} + int nr_reg_rfree(void *ptr) @@ -840,9 +874,11 @@ func(NR_registry name, type *out) \ NRREGLOCALGET(nr_reg_local_get_char, NR_REG_TYPE_CHAR, char) NRREGLOCALGET(nr_reg_local_get_uchar, NR_REG_TYPE_UCHAR, UCHAR) +NRREGLOCALGET(nr_reg_local_get_int2, NR_REG_TYPE_INT2, INT2) NRREGLOCALGET(nr_reg_local_get_uint2, NR_REG_TYPE_UINT2, UINT2) NRREGLOCALGET(nr_reg_local_get_int4, NR_REG_TYPE_INT4, INT4) NRREGLOCALGET(nr_reg_local_get_uint4, NR_REG_TYPE_UINT4, UINT4) +NRREGLOCALGET(nr_reg_local_get_int8, NR_REG_TYPE_INT8, INT8) NRREGLOCALGET(nr_reg_local_get_uint8, NR_REG_TYPE_UINT8, UINT8) NRREGLOCALGET(nr_reg_local_get_double, NR_REG_TYPE_DOUBLE, double) @@ -897,6 +933,30 @@ nr_reg_local_get_length(NR_registry name, size_t *length) return(_status); } +int +nr_reg_local_get_type(NR_registry name, NR_registry_type type) +{ + int r, _status; + nr_registry_node *node = 0; + char *str = 0; + + if ((r=nr_reg_is_valid(name))) + ABORT(r); + + if ((r=r_assoc_fetch(nr_registry, name, strlen(name)+1, (void*)&node))) + ABORT(r); + + str = nr_reg_type_name(node->type); + if (! str) + ABORT(R_BAD_ARGS); + + strncpy(type, str, sizeof(NR_registry_type)); + + _status=0; + abort: + return(_status); +} + #define NRREGLOCALSET(func, TYPE, type) \ int \ @@ -907,8 +967,13 @@ func(NR_registry name, type data) \ NRREGLOCALSET(nr_reg_local_set_char, NR_REG_TYPE_CHAR, char) NRREGLOCALSET(nr_reg_local_set_uchar, NR_REG_TYPE_UCHAR, UCHAR) +NRREGLOCALSET(nr_reg_local_set_int2, NR_REG_TYPE_INT2, INT2) +NRREGLOCALSET(nr_reg_local_set_uint2, NR_REG_TYPE_UINT2, UINT2) NRREGLOCALSET(nr_reg_local_set_int4, NR_REG_TYPE_INT4, INT4) NRREGLOCALSET(nr_reg_local_set_uint4, NR_REG_TYPE_UINT4, UINT4) +NRREGLOCALSET(nr_reg_local_set_int8, NR_REG_TYPE_INT8, INT8) +NRREGLOCALSET(nr_reg_local_set_uint8, NR_REG_TYPE_UINT8, UINT8) +NRREGLOCALSET(nr_reg_local_set_double, NR_REG_TYPE_DOUBLE, double) int nr_reg_local_set_registry(NR_registry name) @@ -1016,31 +1081,67 @@ nr_reg_local_get_children(NR_registry parent, NR_registry *data, size_t size, si return(_status); } +int +nr_reg_local_fin(NR_registry name) +{ + int r, _status; + + if ((r=nr_reg_raise_event(name, NR_REG_CB_ACTION_FINAL))) + ABORT(r); + + _status=0; + abort: + return(_status); +} + +int +nr_reg_local_dump(int sorted) +{ + int r, _status; + + if ((r=nr_reg_local_iter(NR_TOP_LEVEL_REGISTRY, nr_reg_local_dump_print, 0))) + ABORT(r); + + _status=0; + abort: + return(_status); +} + static nr_registry_module_vtbl nr_reg_local_vtbl = { nr_reg_local_init, nr_reg_local_get_char, nr_reg_local_get_uchar, + nr_reg_local_get_int2, nr_reg_local_get_uint2, nr_reg_local_get_int4, nr_reg_local_get_uint4, + nr_reg_local_get_int8, nr_reg_local_get_uint8, nr_reg_local_get_double, nr_reg_local_get_registry, nr_reg_local_get_bytes, nr_reg_local_get_string, nr_reg_local_get_length, + nr_reg_local_get_type, nr_reg_local_set_char, nr_reg_local_set_uchar, + nr_reg_local_set_int2, + nr_reg_local_set_uint2, nr_reg_local_set_int4, nr_reg_local_set_uint4, + nr_reg_local_set_int8, + nr_reg_local_set_uint8, + nr_reg_local_set_double, nr_reg_local_set_registry, nr_reg_local_set_bytes, nr_reg_local_set_string, nr_reg_local_del, nr_reg_local_get_child_count, - nr_reg_local_get_children + nr_reg_local_get_children, + nr_reg_local_fin, + nr_reg_local_dump }; static nr_registry_module nr_reg_local_module = { 0, &nr_reg_local_vtbl }; diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/registry/registry_vtbl.h b/dom/media/webrtc/transport/third_party/nrappkit/src/registry/registry_vtbl.h @@ -49,9 +49,11 @@ typedef struct nr_registry_module_vtbl_ { int (*get_char)(NR_registry name, char *out); int (*get_uchar)(NR_registry name, UCHAR *out); + int (*get_int2)(NR_registry name, INT2 *out); int (*get_uint2)(NR_registry name, UINT2 *out); int (*get_int4)(NR_registry name, INT4 *out); int (*get_uint4)(NR_registry name, UINT4 *out); + int (*get_int8)(NR_registry name, INT8 *out); int (*get_uint8)(NR_registry name, UINT8 *out); int (*get_double)(NR_registry name, double *out); int (*get_registry)(NR_registry name, NR_registry out); @@ -59,11 +61,17 @@ typedef struct nr_registry_module_vtbl_ { int (*get_bytes)(NR_registry name, UCHAR *out, size_t size, size_t *length); int (*get_string)(NR_registry name, char *out, size_t size); int (*get_length)(NR_registry name, size_t *length); + int (*get_type)(NR_registry name, NR_registry_type type); int (*set_char)(NR_registry name, char data); int (*set_uchar)(NR_registry name, UCHAR data); + int (*set_int2)(NR_registry name, INT2 data); + int (*set_uint2)(NR_registry name, UINT2 data); int (*set_int4)(NR_registry name, INT4 data); int (*set_uint4)(NR_registry name, UINT4 data); + int (*set_int8)(NR_registry name, INT8 data); + int (*set_uint8)(NR_registry name, UINT8 data); + int (*set_double)(NR_registry name, double data); int (*set_registry)(NR_registry name); int (*set_bytes)(NR_registry name, UCHAR *data, size_t length); @@ -73,6 +81,10 @@ typedef struct nr_registry_module_vtbl_ { int (*get_child_count)(NR_registry parent, size_t *count); int (*get_children)(NR_registry parent, NR_registry *data, size_t size, size_t *length); + + int (*fin)(NR_registry name); + + int (*dump)(int sorted); } nr_registry_module_vtbl; struct nr_registry_module_ { diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/registry/registrycb.c b/dom/media/webrtc/transport/third_party/nrappkit/src/registry/registrycb.c @@ -44,11 +44,11 @@ #include <assert.h> #include <string.h> -#include <csi_platform.h> #include "registry.h" #include "registry_int.h" #include "r_assoc.h" #include "r_errors.h" +#include "nr_common.h" #include "r_log.h" #include "r_macros.h" @@ -77,6 +77,7 @@ static int compute_cb_id(void *cb, char action, unsigned char cb_id[SIZEOF_CB_ID static int nr_reg_info_free(void *ptr); static int nr_reg_raise_event_recurse(char *name, char *tmp, int action); static int nr_reg_register_callback(NR_registry name, char action, void (*cb)(void *cb_arg, char action, NR_registry name), void *cb_arg); +static int nr_reg_unregister_callback(char *name, char action, void (*cb)(void *cb_arg, char action, NR_registry name)); int nr_reg_cb_init() @@ -187,6 +188,55 @@ nr_reg_register_callback(NR_registry name, char action, void (*cb)(void *cb_arg, } int +nr_reg_unregister_callback(char *name, char action, void (*cb)(void *cb_arg, char action, NR_registry name)) +{ + int r, _status; + r_assoc *assoc = 0; + int size; + unsigned char cb_id[SIZEOF_CB_ID]; + + if (name == 0 || cb == 0) + ABORT(R_BAD_ARGS); + + if (nr_registry_callbacks == 0) + ABORT(R_FAILED); + + if ((r=nr_reg_is_valid(name))) + ABORT(r); + + if ((r=nr_reg_validate_action(action))) + ABORT(r); + + if ((r=r_assoc_fetch(nr_registry_callbacks, name, strlen(name)+1, (void*)&assoc))) { + if (r != R_NOT_FOUND) + ABORT(r); + } + else { + if ((r=compute_cb_id(cb, action, cb_id))) + ABORT(r); + + if ((r=r_assoc_delete(assoc, (char*)cb_id, SIZEOF_CB_ID))) { + if (r != R_NOT_FOUND) + ABORT(r); + } + + if ((r=r_assoc_num_elements(assoc, &size))) + ABORT(r); + + if (size == 0) { + if ((r=r_assoc_delete(nr_registry_callbacks, name, strlen(name)+1))) + ABORT(r); + } + } + + _status=0; + abort: + r_log(NR_LOG_REGISTRY, LOG_DEBUG, "unregister callback %p on '%s' for '%s' %s", cb, name, nr_reg_action_name(action), (_status ? "FAILED" : "succeeded")); + + return(_status); +} + +int compute_cb_id(void *cb, char action, unsigned char cb_id[SIZEOF_CB_ID]) { /* callbacks are identified by the pointer to the cb function plus @@ -365,3 +415,26 @@ NR_reg_register_callback(NR_registry name, char action, void (*cb)(void *cb_arg, abort: return(_status); } + +int +NR_reg_unregister_callback(NR_registry name, char action, void (*cb)(void *cb_arg, char action, NR_registry name)) +{ + int r, _status; + size_t i; + + for (i = 0; i < sizeof(CB_ACTIONS); ++i) { + if (action & CB_ACTIONS[i]) { + if ((r=nr_reg_unregister_callback(name, CB_ACTIONS[i], cb))) + ABORT(r); + + action &= ~(CB_ACTIONS[i]); + } + } + + if (action) + ABORT(R_BAD_ARGS); + + _status=0; + abort: + return(_status); +} diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/share/nr_api.h b/dom/media/webrtc/transport/third_party/nrappkit/src/share/nr_api.h @@ -40,8 +40,11 @@ #define _nr_pce_h #include <sys/queue.h> +#include <csi_platform.h> #include <r_common.h> #include <r_log.h> +#include <nrstats.h> +#include <nr_plugin.h> #include <async_wait.h> #endif diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/share/nr_common.h b/dom/media/webrtc/transport/third_party/nrappkit/src/share/nr_common.h @@ -0,0 +1,108 @@ +/** + nr_common.h + + + Copyright (C) 2006, Network Resonance, Inc. + All Rights Reserved + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of Network Resonance, Inc. nor the name of any + contributors to this software may be used to endorse or promote + products derived from this software without specific prior written + permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + + */ + + +#ifndef _nr_common_h +#define _nr_common_h + +#include <csi_platform.h> + +#ifdef USE_MPATROL +#define USEDEBUG 1 +#include <mpatrol.h> +#endif + +#ifdef USE_DMALLOC +#include <dmalloc.h> +#endif + +#include <string.h> +#include <time.h> + +#ifdef WIN32 +#include <winsock2.h> +#include <errno.h> +#else +#include <sys/errno.h> +#endif + +#ifdef HAVE_SYS_TIME_H +#include <sys/time.h> +#endif + +#include <sys/types.h> +#include <sys/queue.h> +#include <r_log.h> + +extern int NR_LOG_REASSD; + +#include "registry.h" +#include "nrstats.h" + +typedef struct nr_captured_packet_ { + UCHAR cap_interface; /* 1 for primary, 2 for secondary */ + struct timeval ts; /* The time this packet was captured */ + UINT4 len; /* The length of the packet */ + UINT8 packet_number; /* The listener's packet index */ +} nr_captured_packet; + +#ifndef NR_ROOT_PATH +#define NR_ROOT_PATH "/usr/local/ctc/" +#endif + +#define NR_ARCHIVE_DIR NR_ROOT_PATH "archive/" +#define NR_TEMP_DIR NR_ROOT_PATH "tmp/" +#define NR_ARCHIVE_STATEFILE NR_ROOT_PATH "archive/state" +#define NR_CAPTURED_PID_FILENAME NR_ROOT_PATH "captured.pid" +#define NR_REASSD_PID_FILENAME NR_ROOT_PATH "reassd.pid" +#define NR_MODE_FILENAME NR_ROOT_PATH "mode.txt" + +char *nr_revision_number(void); + + + + +/* Memory buckets for CTC memory types */ +#define NR_MEM_TCP 1 +#define NR_MEM_HTTP 2 +#define NR_MEM_DELIVERY 3 +#define NR_MEM_OUT_HM 4 +#define NR_MEM_OUT_SSL 5 +#define NR_MEM_SSL 7 +#define NR_MEM_COMMON 8 +#define NR_MEM_CODEC 9 + +#endif + diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/share/nr_reg_keys.h b/dom/media/webrtc/transport/third_party/nrappkit/src/share/nr_reg_keys.h @@ -0,0 +1,167 @@ +/* + * + * nr_reg_keys.h + * + * $Source: /Users/ekr/tmp/nrappkit-dump/nrappkit/src/share/nr_reg_keys.h,v $ + * $Revision: 1.3 $ + * $Date: 2008/01/29 00:34:00 $ + * + * + * Copyright (C) 2006, Network Resonance, Inc. + * All Rights Reserved + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Network Resonance, Inc. nor the name of any + * contributors to this software may be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + */ + +#ifndef __NR_REG_KEYS_H__ +#define __NR_REG_KEYS_H__ + +#include <stdio.h> + +#define NR_REG_NAME_LENGTH_MIN 1 +#define NR_REG_NAME_LENGTH_MAX 32 + +#define NR_REG_HOSTNAME "hostname" +#define NR_REG_ADDRESS "address" +#define NR_REG_NETMASKSIZE "netmasksize" +#define NR_REG_ADDRESS_NETMASKSIZE "address/netmasksize" /* use only in clic files */ +#define NR_REG_PORT "port" + +#define NR_REG_LOGGING_SYSLOG_ENABLED "logging.syslog.enabled" +#define NR_REG_LOGGING_SYSLOG_SERVERS "logging.syslog.servers" +#define NR_REG_LOGGING_SYSLOG_FACILITY "logging.syslog.facility" +#define NR_REG_LOGGING_SYSLOG_LEVEL "logging.syslog.level" + +#define NR_REG_CAPTURED_DAEMONS "captured.daemons" + +#define NR_REG_LISTEND_ENABLED "listend.enabled" + +#define NR_REG_LISTEND_MAX_INPUT_BUFFER_SIZE "listend.max_input_buffer_size" +#define NR_REG_LISTEND_MAX_INPUT_BUFFER_SIZE_MIN 1 // 1 byte? +#define NR_REG_LISTEND_MAX_INPUT_BUFFER_SIZE_MAX (10ULL*1024*1024*1024) // 10 GB + +#define NR_REG_LISTEND_INTERFACE "listend.interface" +#define NR_REG_LISTEND_INTERFACE_PRIMARY "listend.interface.primary" +#define NR_REG_LISTEND_INTERFACE_SECONDARY "listend.interface.secondary" +#define NR_REG_LISTEND_LISTEN_ON_BOTH_INTERFACES "listend.interface.listen_on_both_interfaces" +#define NR_REG_LISTEND_ENABLE_VLAN "listend.enable_vlan" + +#define NR_REG_LISTEND_LISTEN_TO "listend.listen_to" +#define NR_REG_LISTEND_IGNORE "listend.ignore" + +#define NR_REG_LISTEND_PORT_MIN 0 +#define NR_REG_LISTEND_PORT_MAX 65535 + +#define NR_REG_REASSD_MAX_MEMORY_CONSUMPTION "reassd.max_memory_consumption" +#define NR_REG_REASSD_MAX_MEMORY_CONSUMPTION_MIN (10*1024) // 100 KB +#define NR_REG_REASSD_MAX_MEMORY_CONSUMPTION_MAX (10ULL*1024*1024*1024) // 10 GB + +#define NR_REG_REASSD_DECODER_TCP_IGNORE_CHECKSUMS "reassd.decoder.tcp.ignore_checksums" + +#define NR_REG_REASSD_DECODER_TCP_MAX_CONNECTIONS_IN_SYN_STATE "reassd.decoder.tcp.max_connections_in_syn_state" +#define NR_REG_REASSD_DECODER_TCP_MAX_CONNECTIONS_IN_SYN_STATE_MIN 1 +#define NR_REG_REASSD_DECODER_TCP_MAX_CONNECTIONS_IN_SYN_STATE_MAX 500000 + +#define NR_REG_REASSD_DECODER_TCP_MAX_SIMULTANEOUS_CONNECTIONS "reassd.decoder.tcp.max_simultaneous_connections" +#define NR_REG_REASSD_DECODER_TCP_MAX_SIMULTANEOUS_CONNECTIONS_MIN 1 +#define NR_REG_REASSD_DECODER_TCP_MAX_SIMULTANEOUS_CONNECTIONS_MAX 1000000 // 1 million + +#define NR_REG_REASSD_DECODER_SSL_MAX_SESSION_CACHE_SIZE "reassd.decoder.ssl.max_session_cache_size" +#define NR_REG_REASSD_DECODER_SSL_MAX_SESSION_CACHE_SIZE_MIN 0 +#define NR_REG_REASSD_DECODER_SSL_MAX_SESSION_CACHE_SIZE_MAX (1ULL*1024*1024*1024) // 1GB + +#define NR_REG_REASSD_DECODER_SSL_REVEAL_LOCAL_KEYS "reassd.decoder.ssl.reveal.local.keys" + +#define NR_REG_REASSD_DECODER_HTTP_HANGING_RESPONSE_TIMEOUT "reassd.decoder.http.hanging_response_timeout" +#define NR_REG_REASSD_DECODER_HTTP_HANGING_RESPONSE_TIMEOUT_MIN 1 +#define NR_REG_REASSD_DECODER_HTTP_HANGING_RESPONSE_TIMEOUT_MAX 1023 + +#define NR_REG_REASSD_DECODER_HTTP_HANGING_TRANSMISSION_TIMEOUT "reassd.decoder.http.hanging_transmission_timeout" +#define NR_REG_REASSD_DECODER_HTTP_HANGING_TRANSMISSION_TIMEOUT_MIN 1 +#define NR_REG_REASSD_DECODER_HTTP_HANGING_TRANSMISSION_TIMEOUT_MAX 1023 + +#define NR_REG_REASSD_DECODER_HTTP_MAX_HTTP_MESSAGE_SIZE "reassd.decoder.http.max_http_message_size" +#define NR_REG_REASSD_DECODER_HTTP_MAX_HTTP_MESSAGE_SIZE_MIN 0 +#define NR_REG_REASSD_DECODER_HTTP_MAX_HTTP_MESSAGE_SIZE_MAX (10ULL*1024*1024*1024) + +/* PCE-only: */ +#define NR_REG_LISTEND_ARCHIIVE "listend.archive" +#define NR_REG_LISTEND_ARCHIVE_MAX_SIZE "listend.archive.max_size" +#define NR_REG_LISTEND_ARCHIVE_MAX_SIZE_MIN 0 +#define NR_REG_LISTEND_ARCHIVE_MAX_SIZE_MAX (10ULL*1024*1024*1024*1024) // 10 TB + +#define NR_REG_LISTEND_ARCHIVE_RECORDING_ENABLED "listend.archive.recording_enabled" + +#define NR_REG_REASSD_DECODER_NET_DELIVER_BATCH_INTERVAL "reassd.decoder.net_deliver.batch_interval" +#define NR_REG_REASSD_DECODER_NET_DELIVER_BATCH_INTERVAL_MIN 0 +#define NR_REG_REASSD_DECODER_NET_DELIVER_BATCH_INTERVAL_MAX 1023 + +#define NR_REG_REASSD_DECODER_NET_DELIVER_MAX_QUEUE_DEPTH "reassd.decoder.net_deliver.max_queue_depth" +#define NR_REG_REASSD_DECODER_NET_DELIVER_MAX_QUEUE_DEPTH_MIN 0 +#define NR_REG_REASSD_DECODER_NET_DELIVER_MAX_QUEUE_DEPTH_MAX (1ULL*1024*1024*1024) // 1 GB + +#define NR_REG_REASSD_DECODER_NET_DELIVER_MY_KEY_CERTIFICATE "reassd.decoder.net_deliver.my_key.certificate" +#define NR_REG_REASSD_DECODER_NET_DELIVER_MY_KEY_PRIVATE_KEY "reassd.decoder.net_deliver.my_key.private_key" +#define NR_REG_REASSD_DECODER_NET_DELIVER_PEER "reassd.decoder.net_deliver.peer" +#define NR_REG_REASSD_DECODER_NET_DELIVER_PEER_PORT_MIN 0 +#define NR_REG_REASSD_DECODER_NET_DELIVER_PEER_PORT_MAX 65535 + +#define NR_REG_REASSD_DECODER_NET_DELIVER_POLLING_INTERVAL "reassd.decoder.net_deliver.polling_interval" +#define NR_REG_REASSD_DECODER_NET_DELIVER_POLLING_INTERVAL_MIN 1 +#define NR_REG_REASSD_DECODER_NET_DELIVER_POLLING_INTERVAL_MAX 1023 + +#define NR_REG_REASSD_DECODER_NET_DELIVER_STATELESS "reassd.decoder.net_deliver.stateless" +#define NR_REG_REASSD_DECODER_NET_DELIVER_WATCHDOG_TIMER "reassd.decoder.net_deliver.watchdog_timer" +#define NR_REG_REASSD_DECODER_NET_DELIVER_WATCHDOG_TIMER_MIN 0 +#define NR_REG_REASSD_DECODER_NET_DELIVER_WATCHDOG_TIMER_MAX 666 + +/* ASA-only: */ +#define NR_REG_MIGRATE_ENABLED "migrate.enabled" + +#define NR_REG_MIGRATE_INACTIVITY_TIMEOUT "migrate.inactivity_timeout" +#define NR_REG_MIGRATE_INACTIVITY_TIMEOUT_MIN 0 +#define NR_REG_MIGRATE_INACTIVITY_TIMEOUT_MAX 1023 + +#define NR_REG_MIGRATE_MIN_LOCAL_SIZE "migrate.min_local_size" +#define NR_REG_MIGRATE_MIN_OVERLAP_SIZE "migrate.min_overlap_size" +#define NR_REG_MIGRATE_RETRANSMIT_FREQUENCY "migrate.retransmit_frequency" +#define NR_REG_MIGRATE_RETRIES "migrate.retries" +#define NR_MIGRATE_LOCATION_NUMBER_MIN 0 +#define NR_MIGRATE_LOCATION_NUMBER_MAX 255 + +#define NR_REG_REVELATION_ENABLE "revelation.enabled" +#define NR_REG_REVELATION_MAX_PER_HOUR "revelation.max_per_hour" +#define NR_REG_REVELATION_MAX_PER_HOUR_PER_PORTAL "revelation.max_per_hour_per_portal" + +/* Appliance-only: */ +#define NR_REG_SNMP_ENABLED "snmp.enabled" +#define NR_REG_CLOCK_TIMEZONE "clock.timezone" + +#endif + diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/stats/nrstats.h b/dom/media/webrtc/transport/third_party/nrappkit/src/stats/nrstats.h @@ -0,0 +1,118 @@ +/* + * + * nrstats.h + * + * $Source: /Users/ekr/tmp/nrappkit-dump/nrappkit/src/stats/nrstats.h,v $ + * $Revision: 1.4 $ + * $Date: 2007/06/26 22:37:55 $ + * + * API for keeping and sharing statistics + * + * + * Copyright (C) 2003-2005, Network Resonance, Inc. + * Copyright (C) 2006, Network Resonance, Inc. + * All Rights Reserved + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Network Resonance, Inc. nor the name of any + * contributors to this software may be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + */ + +#ifndef __NRSTATS_H__ +#define __NRSTATS_H__ + +#include <sys/types.h> +#ifdef WIN32 +#include <time.h> +#else +#include <sys/time.h> +#endif +#include <r_types.h> + +#ifndef CAPTURE_USER +#define CAPTURE_USER "pcecap" +#endif + +#define NR_MAX_STATS_TYPES 256 /* max number of stats objects */ +#define NR_MAX_STATS_TYPE_NAME 26 + +typedef struct NR_stats_type_ { + char name[NR_MAX_STATS_TYPE_NAME]; + int (*reset)(void *stats); + int (*print)(void *stats, char *stat_namespace, void (*output)(void *handle, const char *fmt, ...), void *handle); + int (*get_lib_name)(char **libname); + unsigned int size; +} NR_stats_type; + +typedef struct NR_stats_app_ { + time_t last_counter_reset; + time_t last_restart; + UINT8 total_restarts; + char version[64]; +} NR_stats_app; + +extern NR_stats_type *NR_stats_type_app; + +/* everything measured in bytes */ +typedef struct NR_stats_memory_ { + UINT8 current_size; + UINT8 max_size; + UINT8 in_use; + UINT8 in_use_max; +} NR_stats_memory; + +extern NR_stats_type *NR_stats_type_memory; + +/* all functions below return 0 on success, else they return an + * error code */ + +/* if errprintf is null, warnings and errors will be sent to /dev/null */ +extern int NR_stats_startup(char *app_name, char *user_name, void (*errprintf)(void *handle, const char *fmt, ...), void *errhandle); +extern int NR_stats_shutdown(void); +#define NR_STATS_CREATE (1<<0) +extern int NR_stats_get(char *module_name, NR_stats_type *type, int flag, void **stats); +extern int NR_stats_clear(void *stats); /* zeroizes */ +extern int NR_stats_reset(void *stats); /* zeros "speedometers" */ +extern int NR_stats_register(NR_stats_type *type); +extern int NR_stats_acquire_mutex(void *stats); +extern int NR_stats_release_mutex(void *stats); +// TODO: should _get_names take an app_name argument (0==all)???? +extern int NR_stats_get_names(unsigned int *nnames, char ***names); +extern int NR_stats_get_by_name(char *name, NR_stats_type **type, void **stats); +extern int NR_stats_get_lib_name(void *stats, char **lib_name); +extern int NR_stats_rmids(void); + +extern char *NR_prefix_to_stats_module(char *prefix); + +#define NR_INCREMENT_STAT(stat) do { \ + stat++; if(stat>stat##_max) stat##_max=stat; \ + } while (0) +#define NR_UPDATE_STAT(stat,newval) do { \ + stat=newval; if(stat>stat##_max) stat##_max=stat; \ + } while (0) + +#endif diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/util/byteorder.c b/dom/media/webrtc/transport/third_party/nrappkit/src/util/byteorder.c @@ -35,10 +35,10 @@ briank@networkresonance.com Wed May 16 16:46:00 PDT 2007 */ +#include "nr_common.h" #ifndef WIN32 #include <arpa/inet.h> #endif -#include <csi_platform.h> #include "r_types.h" #include "byteorder.h" diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/util/hex.c b/dom/media/webrtc/transport/third_party/nrappkit/src/util/hex.c @@ -45,6 +45,8 @@ static char bin2hex_map[][3] = { "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0a", "0b", "0c", "0d", "0e", "0f", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "1a", "1b", "1c", "1d", "1e", "1f", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "2a", "2b", "2c", "2d", "2e", "2f", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "3a", "3b", "3c", "3d", "3e", "3f", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "4a", "4b", "4c", "4d", "4e", "4f", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "5a", "5b", "5c", "5d", "5e", "5f", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "6a", "6b", "6c", "6d", "6e", "6f", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "7a", "7b", "7c", "7d", "7e", "7f", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "8a", "8b", "8c", "8d", "8e", "8f", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "9a", "9b", "9c", "9d", "9e", "9f", "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "aa", "ab", "ac", "ad", "ae", "af", "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "ba", "bb", "bc", "bd", "be", "bf", "c0", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "ca", "cb", "cc", "cd", "ce", "cf", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "da", "db", "dc", "dd", "de", "df", "e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "ea", "eb", "ec", "ed", "ee", "ef", "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "fa", "fb", "fc", "fd", "fe", "ff" }; +static int hex2bin_map[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0 /* '0' */, 1 /* '1' */, 2 /* '2' */, 3 /* '3' */, 4 /* '4' */, 5 /* '5' */, 6 /* '6' */, 7 /* '7' */, 8 /* '8' */, 9 /* '9' */, -1, -1, -1, -1, -1, -1, -1, 10 /* 'A' */, 11 /* 'B' */, 12 /* 'C' */, 13 /* 'D' */, 14 /* 'E' */, 15 /* 'F' */, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 10 /* 'a' */, 11 /* 'b' */, 12 /* 'c' */, 13 /* 'd' */, 14 /* 'e' */, 15 /* 'f' */, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; + int nr_nbin2hex(UCHAR *bin, size_t binlen, char hex[], size_t size, size_t *len) { @@ -70,3 +72,38 @@ nr_nbin2hex(UCHAR *bin, size_t binlen, char hex[], size_t size, size_t *len) abort: return(_status); } + + +int +nr_nhex2bin(char *hex, size_t hexlen, UCHAR bin[], size_t size, size_t *len) +{ + int _status; + size_t binlen; + int h1; + int h2; + size_t i; + + if (hexlen % 2) + ABORT(R_BAD_ARGS); + + binlen = hexlen/2; + + if (size < binlen) + ABORT(R_BAD_ARGS); + + for (i = 0; i < binlen; ++i) { + h1 = hex2bin_map[(int)*hex++]; + h2 = hex2bin_map[(int)*hex++]; + + if (h1 == -1 || h2 == -1) + ABORT(R_BAD_ARGS); + + bin[i] = (h1 << 4) | h2; + } + + *len = binlen; + + _status=0; + abort: + return(_status); +} diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/util/hex.h b/dom/media/webrtc/transport/third_party/nrappkit/src/util/hex.h @@ -41,6 +41,7 @@ #define _hex_h int nr_nbin2hex(UCHAR *bin, size_t binlen, char hex[], size_t size, size_t *len); +int nr_nhex2bin(char *hex, size_t hexlen, UCHAR bin[], size_t size, size_t *len); #endif diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/util/libekr/r_assoc.c b/dom/media/webrtc/transport/third_party/nrappkit/src/util/libekr/r_assoc.c @@ -117,6 +117,7 @@ struct r_assoc_ { static int destroy_assoc_chain(r_assoc_el *chain); static int r_assoc_fetch_bucket(r_assoc *assoc, char *key,int len,r_assoc_el **bucketp); +static int copy_assoc_chain(r_assoc_el **knewp, r_assoc_el *old); int r_assoc_create( r_assoc **assocp, @@ -184,6 +185,56 @@ static int destroy_assoc_chain(r_assoc_el *chain) return(0); } +static int copy_assoc_chain(r_assoc_el **knewp, r_assoc_el *old) + { + r_assoc_el *knew = 0, *ptr = 0, *tmp = 0; + int r,_status; + + ptr=0; /* Pacify GCC's uninitialized warning. + It's not correct */ + if(!old) { + *knewp=0; + return(0); + } + for(;old;old=old->next){ + if(!(tmp=(r_assoc_el *)RCALLOC(sizeof(r_assoc_el)))) + ABORT(R_NO_MEMORY); + + if(!knew){ + knew=tmp; + ptr=knew; + } + else{ + ptr->next=tmp; + tmp->prev=ptr; + ptr=tmp; + } + + ptr->destroy=old->destroy; + ptr->copy=old->copy; + + if(old->copy){ + if(r=old->copy(&ptr->data,old->data)) + ABORT(r); + } + else + ptr->data=old->data; + + if(!(ptr->key=(char *)RMALLOC(old->key_len))) + ABORT(R_NO_MEMORY); + memcpy(ptr->key,old->key,ptr->key_len=old->key_len); + } + + *knewp=knew; + + _status=0; + abort: + if(_status){ + destroy_assoc_chain(knew); + } + return(_status); + } + static int r_assoc_fetch_bucket( r_assoc *assoc, char *key, @@ -278,6 +329,70 @@ int r_assoc_insert( return(_status); } +int r_assoc_delete(r_assoc *assoc, char *key, int len) + { + int r; + r_assoc_el *bucket = 0; + UINT4 hash_value; + + if(r=r_assoc_fetch_bucket(assoc,key,len,&bucket)){ + if(r!=R_NOT_FOUND) + ERETURN(r); + return(r); + } + + /* Now remove the element from the hash chain */ + if(bucket->prev){ + bucket->prev->next=bucket->next; + } + else { + hash_value=assoc->hash_func(key,len,assoc->bits); + assoc->chains[hash_value]=bucket->next; + } + + if(bucket->next) + bucket->next->prev=bucket->prev; + + /* Remove the data */ + if(bucket->destroy) + bucket->destroy(bucket->data); + + RFREE(bucket->key); + RFREE(bucket); + assoc->num_elements--; + + return(0); + } + +int r_assoc_copy(r_assoc **knewp, r_assoc *old) + { + int r,_status,i; + r_assoc *knew = 0; + + if(!(knew=(r_assoc *)RCALLOC(sizeof(r_assoc)))) + ABORT(R_NO_MEMORY); + knew->size=old->size; + knew->bits=old->bits; + knew->hash_func=old->hash_func; + + if(!(knew->chains=(r_assoc_el **)RCALLOC(sizeof(r_assoc_el)*old->size))) + ABORT(R_NO_MEMORY); + for(i=0;i<knew->size;i++){ + if(r=copy_assoc_chain(knew->chains+i,old->chains[i])) + ABORT(r); + } + knew->num_elements=old->num_elements; + + *knewp=knew; + + _status=0; + abort: + if(_status){ + r_assoc_destroy(&knew); + } + return(_status); + } + int r_assoc_num_elements(r_assoc *assoc,int *sizep) { *sizep=assoc->num_elements; @@ -370,6 +485,20 @@ int r_assoc_iter_delete(r_assoc_iterator *iter) } +/*This is a hack from AMS. Supposedly, it's pretty good for strings, even + though it doesn't take into account all the data*/ +int r_assoc_simple_hash_compute(char *key, int len, int bits) + { + UINT4 h=0; + + h=key[0] +(key[len-1] * len); + + h &= (1<<bits) - 1; + + return(h); + } + + int r_crc32(char *data,int len,UINT4 *crcval); int r_assoc_crc32_hash_compute(char *data, int len, int bits) diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/util/libekr/r_assoc.h b/dom/media/webrtc/transport/third_party/nrappkit/src/util/libekr/r_assoc.h @@ -100,8 +100,11 @@ int r_assoc_insert(r_assoc *assoc,char *key,int len, #define R_ASSOC_NEW 0x2 int r_assoc_fetch(r_assoc *assoc,char *key, int len, void **value); +int r_assoc_delete(r_assoc *assoc,char *key, int len); +int r_assoc_copy(r_assoc **knew,r_assoc *old); int r_assoc_destroy(r_assoc **assocp); +int r_assoc_simple_hash_compute(char *key, int len,int bits); int r_assoc_crc32_hash_compute(char *key, int len,int bits); /*We need iterators, but I haven't written them yet*/ diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/util/libekr/r_data.c b/dom/media/webrtc/transport/third_party/nrappkit/src/util/libekr/r_data.c @@ -109,6 +109,20 @@ int r_data_create(Data **dp, const UCHAR *d, size_t l) return(_status); } + +int r_data_alloc_mem(Data *d, size_t l) + { + int _status; + + if(!(d->data=(UCHAR *)RMALLOC(l))) + ABORT(R_NO_MEMORY); + d->len=l; + + _status=0; + abort: + return(_status); + } + int r_data_alloc(Data **dp, size_t l) { Data *d_=0; @@ -155,6 +169,37 @@ int r_data_destroy(Data **dp) return(0); } +int r_data_destroy_v(void *v) + { + Data *d = 0; + + if(!v) + return(0); + + d=(Data *)v; + r_data_zfree(d); + + RFREE(d); + + return(0); + } + +int r_data_destroy_vp(void **v) + { + Data *d = 0; + + if(!v || !*v) + return(0); + + d=(Data *)*v; + r_data_zfree(d); + + *v=0; + RFREE(d); + + return(0); + } + int r_data_copy(Data *dst, Data *src) { if(!(dst->data=(UCHAR *)RMALLOC(src->len))) @@ -173,3 +218,12 @@ int r_data_zfree(Data *d) RFREE(d->data); return(0); } + +int r_data_compare(Data *d1, Data *d2) + { + if(d1->len<d2->len) + return(-1); + if(d2->len<d1->len) + return(-1); + return(memcmp(d1->data,d2->data,d1->len)); + } diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/util/libekr/r_data.h b/dom/media/webrtc/transport/third_party/nrappkit/src/util/libekr/r_data.h @@ -92,9 +92,13 @@ typedef struct Data_ { int r_data_create(Data **dp,const UCHAR *d,size_t l); int r_data_alloc(Data **dp, size_t l); int r_data_make(Data *dp, const UCHAR *d,size_t l); +int r_data_alloc_mem(Data *d,size_t l); int r_data_destroy(Data **dp); +int r_data_destroy_v(void *v); +int r_data_destroy_vp(void **vp); int r_data_copy(Data *dst,Data *src); int r_data_zfree(Data *d); +int r_data_compare(Data *d1,Data *d2); #define INIT_DATA(a,b,c) (a).data=b; (a).len=c #define ATTACH_DATA(a,b) (a).data=b; (a).len=sizeof(b) diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/util/libekr/r_errors.c b/dom/media/webrtc/transport/third_party/nrappkit/src/util/libekr/r_errors.c @@ -91,6 +91,19 @@ static struct { char *str; } errors[] = NR_ERROR_MAPPING; +int nr_verr_exit(char *fmt,...) + { + va_list ap; + + va_start(ap,fmt); + vfprintf(stderr,fmt,ap); + + if (fmt[0] != '\0' && fmt[strlen(fmt)-1] != '\n') + fprintf(stderr,"\n"); + + exit(1); + } + char * nr_strerror(int errnum) { diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/util/libekr/r_errors.h b/dom/media/webrtc/transport/third_party/nrappkit/src/util/libekr/r_errors.h @@ -118,6 +118,8 @@ { R_RETRY, "Retry may be possible" },\ } +int nr_verr_exit(char *fmt,...); + char *nr_strerror(int errnum); int nr_strerror_r(int errnum, char *strerrbuf, size_t buflen); diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/util/libekr/r_memory.c b/dom/media/webrtc/transport/third_party/nrappkit/src/util/libekr/r_memory.c @@ -115,6 +115,33 @@ void r_free(void *ptr) free(chunk); } +void *r_realloc(void *ptr, size_t size) + { + r_malloc_chunk *chunk = 0, *nchunk = 0; + size_t total; + + if(!ptr) return(r_malloc(255,size)); + + chunk=(r_malloc_chunk *)GET_CHUNK_ADDR_FROM_MEM_ADDR(ptr); +#ifdef SANITY_CHECKS + assert(chunk->hdr==HDR_FLAG); +#endif + + total=size + sizeof(r_malloc_chunk); + + if(!(nchunk=realloc(chunk,total))) + return(0); + + mem_usage-=CHUNK_SIZE(nchunk->size); + mem_stats[nchunk->type]-=nchunk->size; + + nchunk->size=size; + mem_usage+=CHUNK_SIZE(nchunk->size); + mem_stats[nchunk->type]+=nchunk->size; + + return(nchunk->memory); + } + char *r_strdup(const char *str) { int len; @@ -133,3 +160,28 @@ char *r_strdup(const char *str) return(nstr); } +int r_mem_get_usage(UINT4 *usagep) + { + *usagep=mem_usage; + + return(0); + } + +int r_memory_dump_stats() + { + int i; + + printf("Total memory usage: %d\n",mem_usage); + printf("Memory usage by bucket\n"); + for(i=0;i<256;i++){ + if(mem_stats[i]){ + printf("%d\t%d\n",i,mem_stats[i]); + } + } + return(0); + } + +void *r_malloc_compat(size_t size) + { + return(r_malloc(255,size)); + } diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/util/libekr/r_memory.h b/dom/media/webrtc/transport/third_party/nrappkit/src/util/libekr/r_memory.h @@ -45,9 +45,13 @@ #include "r_types.h" void *r_malloc(int type, size_t size); +void *r_malloc_compat(size_t size); void *r_calloc(int type,size_t number,size_t size); void r_free (void *ptr); +void *r_realloc(void *ptr,size_t size); char *r_strdup(const char *str); +int r_mem_get_usage(UINT4 *usage); +int r_memory_dump_stats(void); #ifdef NO_MALLOC_REPLACE diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/util/libekr/r_replace.c b/dom/media/webrtc/transport/third_party/nrappkit/src/util/libekr/r_replace.c @@ -0,0 +1,107 @@ +/** + r_replace.c + + + Copyright (C) 2002-2003, Network Resonance, Inc. + Copyright (C) 2006, Network Resonance, Inc. + All Rights Reserved + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of Network Resonance, Inc. nor the name of any + contributors to this software may be used to endorse or promote + products derived from this software without specific prior written + permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + + + */ + +/** + r_replace.c + + + Copyright (C) 1999-2000 RTFM, Inc. + All Rights Reserved + + This package is a SSLv3/TLS protocol analyzer written by Eric Rescorla + <ekr@rtfm.com> and licensed by RTFM, Inc. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. All advertising materials mentioning features or use of this software + must display the following acknowledgement: + + This product includes software developed by Eric Rescorla for + RTFM, Inc. + + 4. Neither the name of RTFM, Inc. nor the name of Eric Rescorla may be + used to endorse or promote products derived from this + software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY ERIC RESCORLA AND RTFM, INC. ``AS IS'' AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY SUCH DAMAGE. + + $Id: r_replace.c,v 1.2 2006/08/16 19:39:17 adamcain Exp $ + + + ekr@rtfm.com Sun Oct 1 11:18:49 2000 + */ + +#include "r_common.h" + +#ifndef HAVE_STRDUP + +char *strdup(str) + char *str; + { + int len=strlen(str); + char *n = 0; + + if(!(n=(char *)malloc(len+1))) + return(0); + + memcpy(n,str,len+1); + + return(n); + } +#endif + + +#ifdef SUPPLY_ATEXIT +int atexit(void (*func)(void)){ + ; +} +#endif diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/util/libekr/r_thread.h b/dom/media/webrtc/transport/third_party/nrappkit/src/util/libekr/r_thread.h @@ -0,0 +1,68 @@ +/** + r_thread.h + + + Copyright (C) 1999, RTFM, Inc. + Copyright (C) 2006, Network Resonance, Inc. + All Rights Reserved + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of Network Resonance, Inc. nor the name of any + contributors to this software may be used to endorse or promote + products derived from this software without specific prior written + permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + + + ekr@rtfm.com Tue Feb 23 14:58:36 1999 + */ + + +#ifndef _r_thread_h +#define _r_thread_h + +typedef void *r_thread; +typedef void *r_rwlock; +typedef void * r_cond; + +int r_thread_fork (void (*func)(void *),void *arg, + r_thread *tid); +int r_thread_destroy (r_thread tid); +int r_thread_yield (void); +int r_thread_exit (void); +int r_thread_wait_last (void); +int r_thread_self (void); + +int r_rwlock_create (r_rwlock **lockp); +int r_rwlock_destroy (r_rwlock **lock); +int r_rwlock_lock (r_rwlock *lock,int action); + +int r_cond_init (r_cond *cond); +int r_cond_wait (r_cond cond); +int r_cond_signal (r_cond cond); + +#define R_RWLOCK_UNLOCK 0 +#define R_RWLOCK_RLOCK 1 +#define R_RWLOCK_WLOCK 2 + +#endif + diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/util/libekr/r_time.c b/dom/media/webrtc/transport/third_party/nrappkit/src/util/libekr/r_time.c @@ -113,6 +113,26 @@ int r_timeval_diff( return(0); } +int r_timeval_add(struct timeval *t1, struct timeval *t2, struct timeval *sum) + { + long tv_sec,tv_usec,d; + + tv_sec=t1->tv_sec + t2->tv_sec; + + d=t1->tv_usec + t2->tv_usec; + if(d>1000000){ + tv_sec++; + tv_usec=d-1000000; + } + else{ + tv_usec=d; + } + + sum->tv_sec=tv_sec; + sum->tv_usec=tv_usec; + + return(0); + } int r_timeval_cmp(struct timeval *t1, struct timeval *t2) { diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/util/libekr/r_time.h b/dom/media/webrtc/transport/third_party/nrappkit/src/util/libekr/r_time.h @@ -92,6 +92,7 @@ #endif int r_timeval_diff(struct timeval *t1,struct timeval *t0, struct timeval *diff); +int r_timeval_add(struct timeval *t1,struct timeval *t2, struct timeval *sum); int r_timeval_cmp(struct timeval *t1,struct timeval *t2); UINT8 r_timeval2int(struct timeval *tv); diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/util/p_buf.c b/dom/media/webrtc/transport/third_party/nrappkit/src/util/p_buf.c @@ -40,9 +40,7 @@ #include <string.h> #include <stddef.h> -#include <sys/queue.h> -#include <csi_platform.h> -#include <r_log.h> +#include "nr_common.h" #include "p_buf.h" diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/util/util.c b/dom/media/webrtc/transport/third_party/nrappkit/src/util/util.c @@ -48,7 +48,7 @@ #ifdef OPENSSL #include <openssl/evp.h> #endif -#include <csi_platform.h> +#include "nr_common.h" #include "r_common.h" #include "registry.h" #include "util.h" @@ -56,6 +56,114 @@ int nr_util_default_log_facility=LOG_COMMON; +int nr_get_filename(char *base, char *name, char **namep) + { + int len=strlen(base)+strlen(name)+2; + char *ret=0; + int _status; + + if(!(ret=(char *)RMALLOC(len))) + ABORT(R_NO_MEMORY); + if(base[strlen(base)-1]!='/'){ + sprintf(ret,"%s/%s",base,name); + } + else{ + sprintf(ret,"%s%s",base,name); + } + *namep=ret; + _status=0; + abort: + return(_status); + } + +void nr_errprintf_log(const char *format,...) + { + va_list ap; + + va_start(ap,format); + + r_vlog(nr_util_default_log_facility,LOG_ERR,format,ap); + + va_end(ap); + } + +void nr_errprintf_log2(void *ignore, const char *format,...) + { + va_list ap; + + va_start(ap,format); + + r_vlog(nr_util_default_log_facility,LOG_ERR,format,ap); + + va_end(ap); + } + + +int nr_fwrite_all(FILE *fp,UCHAR *buf,int len) + { + int r,_status; + + while(len){ + r=fwrite(buf,1,len,fp); + if(r==0) + ABORT(R_IO_ERROR); + + len-=r; + buf+=r; + } + + _status=0; + abort: + return(_status); + } + +int nr_read_data(int fd, char *buf, int len) + { + int r,_status; + + while(len){ + r=NR_SOCKET_READ(fd,buf,len); + if(r<=0) + ABORT(R_EOD); + + buf+=r; + len-=r; + } + + + _status=0; + abort: + return(_status); + } + +#ifdef WIN32 + // TODO +#else +int nr_drop_privileges(char *username) + { + int _status; + + /* Drop privileges */ + if ((getuid() == 0) || geteuid()==0) { + struct passwd *passwd; + + if ((passwd = getpwnam(CAPTURE_USER)) == 0){ + r_log(LOG_GENERIC,LOG_EMERG,"Couldn't get user %s",CAPTURE_USER); + ABORT(R_INTERNAL); + } + + if(setuid(passwd->pw_uid)!=0){ + r_log(LOG_GENERIC,LOG_EMERG,"Couldn't drop privileges"); + ABORT(R_INTERNAL); + } + } + + _status=0; + abort: + return(_status); + } +#endif + int nr_bin2hex(UCHAR *in,int len,UCHAR *out) { while(len){ @@ -70,6 +178,174 @@ int nr_bin2hex(UCHAR *in,int len,UCHAR *out) return(0); } +int nr_hex_ascii_dump(Data *data) + { + UCHAR *ptr=data->data; + int len=data->len; + + while(len){ + int i; + int bytes=MIN(len,16); + + for(i=0;i<bytes;i++) + printf("%.2x ",ptr[i]&255); + /* Fill */ + for(i=0;i<(16-bytes);i++) + printf(" "); + printf(" "); + + for(i=0;i<bytes;i++){ + if(isprint(ptr[i])) + printf("%c",ptr[i]); + else + printf("."); + } + printf("\n"); + + len-=bytes; + ptr+=bytes; + } + return(0); + } + +#ifdef OPENSSL +int nr_sha1_file(char *filename,UCHAR *out) + { + EVP_MD_CTX md_ctx; + FILE *fp=0; + int r,_status; + UCHAR buf[1024]; + int out_len; + + EVP_MD_CTX_init(&md_ctx); + + if(!(fp=fopen(filename,"r"))){ + r_log(LOG_COMMON,LOG_ERR,"Couldn't open file %s",filename); + ABORT(R_NOT_FOUND); + } + + EVP_DigestInit_ex(&md_ctx,EVP_sha1(),0); + + while(1){ + r=fread(buf,1,sizeof(buf),fp); + + if(r<0){ + r_log(LOG_COMMON,LOG_ERR,"Error reading from %s",filename); + ABORT(R_INTERNAL); + } + + if(!r) + break; + + EVP_DigestUpdate(&md_ctx,buf,r); + } + + EVP_DigestFinal(&md_ctx,out,(unsigned int*)&out_len); + if(out_len!=20) + ABORT(R_INTERNAL); + + _status=0; + abort: + EVP_MD_CTX_cleanup(&md_ctx); + if(fp) fclose(fp); + + return(_status); + } + +#endif + +#ifdef WIN32 + // TODO +#else + +int nr_write_pid_file(char *pid_filename) + { + FILE *fp; + int _status; + + if(!pid_filename) + ABORT(R_BAD_ARGS); + + unlink(pid_filename); + + if(!(fp=fopen(pid_filename,"w"))){ + r_log(LOG_GENERIC,LOG_CRIT,"Couldn't open PID file: %s",strerror(errno)); + ABORT(R_NOT_FOUND); + } + + fprintf(fp,"%d\n",getpid()); + + fclose(fp); + + chmod(pid_filename,S_IRUSR | S_IRGRP | S_IROTH); + + _status=0; + abort: + return(_status); + } +#endif + +int nr_reg_uint4_fetch_and_check(NR_registry key, UINT4 min, UINT4 max, int log_fac, int die, UINT4 *val) + { + int r,_status; + UINT4 my_val; + + if(r=NR_reg_get_uint4(key,&my_val)){ + r_log(log_fac,LOG_ERR,"Couldn't get key '%s', error %d",key,r); + ABORT(r); + } + + if((min>0) && (my_val<min)){ + r_log(log_fac,LOG_ERR,"Invalid value for key '%s'=%lu, (min = %lu)",key,(unsigned long)my_val,(unsigned long)min); + ABORT(R_BAD_DATA); + } + + if(my_val>max){ + r_log(log_fac,LOG_ERR,"Invalid value for key '%s'=%lu, (max = %lu)",key,(unsigned long)my_val,(unsigned long)max); + ABORT(R_BAD_DATA); + } + + *val=my_val; + _status=0; + + abort: + if(die && _status){ + r_log(log_fac,LOG_CRIT,"Exiting due to invalid configuration (key '%s')",key); + exit(1); + } + return(_status); + } + +int nr_reg_uint8_fetch_and_check(NR_registry key, UINT8 min, UINT8 max, int log_fac, int die, UINT8 *val) + { + int r,_status; + UINT8 my_val; + + if(r=NR_reg_get_uint8(key,&my_val)){ + r_log(log_fac,LOG_ERR,"Couldn't get key '%s', error %d",key,r); + ABORT(r); + } + + if(my_val<min){ + r_log(log_fac,LOG_ERR,"Invalid value for key '%s'=%llu, (min = %llu)",key,my_val,min); + ABORT(R_BAD_DATA); + } + + if(my_val>max){ + r_log(log_fac,LOG_ERR,"Invalid value for key '%s'=%llu, (max = %llu)",key,my_val,max); + ABORT(R_BAD_DATA); + } + + *val=my_val; + _status=0; + + abort: + if(die && _status){ + r_log(log_fac,LOG_CRIT,"Exiting due to invalid configuration (key '%s')",key); + exit(1); + } + return(_status); + } #if defined(LINUX) || defined(WIN32) /*- @@ -136,6 +412,250 @@ size_t strlcat(char *dst, const char *src, size_t siz) #endif /* LINUX or WIN32 */ +#if defined(USE_OWN_INET_NTOP) +#include <errno.h> +#ifdef WIN32 +#include <Ws2ipdef.h> +#ifndef EAFNOSUPPORT +#define EAFNOSUPPORT WSAEAFNOSUPPORT +#endif +#else +#include <sys/socket.h> +#endif +#define INET6 + +/* inet_ntop implementation from NetBSD */ + +/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1996-1999 by Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#if !defined(NS_INADDRSZ) +# define NS_INADDRSZ 4 +#endif +#if !defined(NS_IN6ADDRSZ) +# define NS_IN6ADDRSZ 16 +#endif +#if !defined(NS_INT16SZ) +# define NS_INT16SZ 2 +#endif + +/* + * WARNING: Don't even consider trying to compile this on a system where + * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. + */ + +static const char *inet_ntop4(const unsigned char *src, char *dst, size_t size); +#ifdef INET6 +static const char *inet_ntop6(const unsigned char *src, char *dst, size_t size); +#endif /* INET6 */ + +/* char * + * inet_ntop(af, src, dst, size) + * convert a network format address to presentation format. + * return: + * pointer to presentation format address (`dst'), or NULL (see errno). + * author: + * Paul Vixie, 1996. + */ +const char * +inet_ntop(int af, const void *src, char *dst, size_t size) +{ + + switch (af) { + case AF_INET: + return (inet_ntop4(src, dst, size)); +#ifdef INET6 + case AF_INET6: + return (inet_ntop6(src, dst, size)); +#endif /* INET6 */ + default: + errno = EAFNOSUPPORT; + return (NULL); + } + /* NOTREACHED */ +} + +/* const char * + * inet_ntop4(src, dst, size) + * format an IPv4 address, more or less like inet_ntoa() + * return: + * `dst' (as a const) + * notes: + * (1) uses no statics + * (2) takes a unsigned char* not an in_addr as input + * author: + * Paul Vixie, 1996. + */ +static const char * +inet_ntop4(const unsigned char *src, char *dst, size_t size) +{ + char tmp[sizeof "255.255.255.255"]; + int l; + + l = snprintf(tmp, sizeof(tmp), "%u.%u.%u.%u", + src[0], src[1], src[2], src[3]); + if (l <= 0 || (size_t) l >= size) { + errno = ENOSPC; + return (NULL); + } + strlcpy(dst, tmp, size); + return (dst); +} + +#ifdef INET6 +/* const char * + * inet_ntop6(src, dst, size) + * convert IPv6 binary address into presentation (printable) format + * author: + * Paul Vixie, 1996. + */ +static const char * +inet_ntop6(const unsigned char *src, char *dst, size_t size) +{ + /* + * Note that int32_t and int16_t need only be "at least" large enough + * to contain a value of the specified size. On some systems, like + * Crays, there is no such thing as an integer variable with 16 bits. + * Keep this in mind if you think this function should have been coded + * to use pointer overlays. All the world's not a VAX. + */ + char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"]; + char *tp = 0, *ep = 0; + struct { int base, len; } best, cur; + unsigned int words[NS_IN6ADDRSZ / NS_INT16SZ]; + int i; + int advance; + + /* + * Preprocess: + * Copy the input (bytewise) array into a wordwise array. + * Find the longest run of 0x00's in src[] for :: shorthanding. + */ + memset(words, '\0', sizeof words); + for (i = 0; i < NS_IN6ADDRSZ; i++) + words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3)); + best.base = -1; + cur.base = -1; + best.len = -1; /* XXX gcc */ + cur.len = -1; /* XXX gcc */ + for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { + if (words[i] == 0) { + if (cur.base == -1) + cur.base = i, cur.len = 1; + else + cur.len++; + } else { + if (cur.base != -1) { + if (best.base == -1 || cur.len > best.len) + best = cur; + cur.base = -1; + } + } + } + if (cur.base != -1) { + if (best.base == -1 || cur.len > best.len) + best = cur; + } + if (best.base != -1 && best.len < 2) + best.base = -1; + + /* + * Format the result. + */ + tp = tmp; + ep = tmp + sizeof(tmp); + for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { + /* Are we inside the best run of 0x00's? */ + if (best.base != -1 && i >= best.base && + i < (best.base + best.len)) { + if (i == best.base) + *tp++ = ':'; + continue; + } + /* Are we following an initial run of 0x00s or any real hex? */ + if (i != 0) { + if (tp + 1 >= ep) + return (NULL); + *tp++ = ':'; + } + /* Is this address an encapsulated IPv4? */ + if (i == 6 && best.base == 0 && + (best.len == 6 || + (best.len == 7 && words[7] != 0x0001) || + (best.len == 5 && words[5] == 0xffff))) { + if (!inet_ntop4(src+12, tp, (size_t)(ep - tp))) + return (NULL); + tp += strlen(tp); + break; + } + advance = snprintf(tp, (size_t)(ep - tp), "%x", words[i]); + if (advance <= 0 || advance >= ep - tp) + return (NULL); + tp += advance; + } + /* Was it a trailing run of 0x00's? */ + if (best.base != -1 && (best.base + best.len) == + (NS_IN6ADDRSZ / NS_INT16SZ)) { + if (tp + 1 >= ep) + return (NULL); + *tp++ = ':'; + } + if (tp + 1 >= ep) + return (NULL); + *tp++ = '\0'; + + /* + * Check for overflow, copy, and we're done. + */ + if ((size_t)(tp - tmp) > size) { + errno = ENOSPC; + return (NULL); + } + strlcpy(dst, tmp, size); + return (dst); +} +#endif /* INET6 */ + +#ifdef WIN32 +/* Not exactly, will forgive stuff like <addr>:<port> */ +int inet_pton(int af, const char *src, void *dst) +{ + struct sockaddr_storage ss; + int addrlen = sizeof(ss); + + if (af != AF_INET && af != AF_INET6) { + return -1; + } + + if (!WSAStringToAddressA(src, af, NULL, (struct sockaddr*)&ss, &addrlen)) { + if (af == AF_INET) { + struct sockaddr_in *in = (struct sockaddr_in*)&ss; + memcpy(dst, &in->sin_addr, sizeof(struct in_addr)); + } else { + struct sockaddr_in6 *in6 = (struct sockaddr_in6*)&ss; + memcpy(dst, &in6->sin6_addr, sizeof(struct in6_addr)); + } + return 1; + } + return 0; +} +#endif /* WIN32 */ + +#endif #ifdef WIN32 #include <time.h> diff --git a/dom/media/webrtc/transport/third_party/nrappkit/src/util/util.h b/dom/media/webrtc/transport/third_party/nrappkit/src/util/util.h @@ -42,9 +42,22 @@ #include "registry.h" +int nr_get_filename(char *base,char *name, char **namep); +void nr_errprintf_log(const char *fmt,...); +void nr_errprintf_log2(void *ignore, const char *fmt,...); extern int nr_util_default_log_facility; +int nr_read_data(int fd,char *buf,int len); +int nr_drop_privileges(char *username); +int nr_hex_ascii_dump(Data *data); +int nr_fwrite_all(FILE *fp,UCHAR *buf,int len); +int nr_sha1_file(char *filename,UCHAR *out); int nr_bin2hex(UCHAR *in,int len,UCHAR *out); +int nr_rm_tree(char *path); +int nr_write_pid_file(char *pid_filename); + +int nr_reg_uint4_fetch_and_check(NR_registry key, UINT4 min, UINT4 max, int log_fac, int die, UINT4 *val); +int nr_reg_uint8_fetch_and_check(NR_registry key, UINT8 min, UINT8 max, int log_fac, int die, UINT8 *val); #endif