/** Duplicate this socket, including its underlying descriptor. @return the duplicate StreamSocket on success, NULL+errno on failure. */ virtual YO_NEW_REF StreamSocket* dup() { socket_t socket_ = Socket::create(get_domain(), TYPE, get_protocol()); if (socket_ != static_cast<socket_t>(-1)) { return new StreamSocket(get_domain(), get_protocol(), socket_); } else { return NULL; } }
virtual YO_NEW_REF TcpSocket* dup() { socket_t socket_ = Socket::create(get_domain(), TYPE, PROTOCOL); if (socket_ != static_cast<socket_t>(-1)) { return new TcpSocket(get_domain(), socket_); } else { return NULL; } }
int DNS::make_RR_string(char* start, int offset, int number,char*& rr) { char* field_start = start + offset; int RR_offset = 0; if(number == 0) return RR_offset; for(int i = 0;i < number; i++) { unique_ptr<char> domain(new char[256]); RR_offset += get_domain(start,field_start + RR_offset,domain.get()); rr += sprintf(rr,"%s is ",domain.get()); fixedRR* frr = (fixedRR*) (field_start + RR_offset); unsigned short DNS_class; unsigned short type; int ttl; unsigned short RDlen = 0; DNS_class = ntohs(frr->dns_class); type = ntohs(frr->type); ttl = ntohl(frr->TTL); RR_offset += sizeof(fixedRR); if(frr->dns_class != 1) { RDlen = ntohs(*(unsigned short*)(field_start + RR_offset)); } else { RDlen = (*(unsigned short*)(field_start + RR_offset)); } RR_offset += sizeof(unsigned short); if(type == DNS_A) { string name; unsigned long ip = *(unsigned long*)(field_start + RR_offset); IN_ADDR in_ip; in_ip.s_addr = ip; name = inet_ntoa(in_ip); rr += sprintf(rr,"%s\n",name.c_str()); RR_offset += sizeof(unsigned long); } if(type == DNS_CNAME) { unique_ptr<char> domain(new char[256]); RR_offset += get_domain(start,field_start + RR_offset,domain.get()); rr += sprintf(rr,"alised to %s\n",domain.get()); } if(type == DNS_PTR) { unique_ptr<char> domain(new char[256]); RR_offset += get_domain(start,field_start + RR_offset,domain.get()); rr += sprintf(rr,"%s\n",domain.get()); } } return RR_offset; }
static void do_args(char** argv) { /* process the arguments according to the ARGV pattern domain */ char** ap; CIStream argsbuf; COStream outbuf; const char* remaining; boolean ok; outbuf = make_buffer_output_stream(); cos_putch(outbuf, '\n'); for ( ap = argv ; *ap != NULL ; ap++ ) { cos_puts(outbuf, *ap); cos_putch(outbuf, '\n'); } argsbuf = convert_output_to_input( outbuf ); outbuf = make_buffer_output_stream(); ok = translate ( argsbuf, get_domain(argv_domain_name), outbuf, NULL ); cis_close(argsbuf); argsbuf = convert_output_to_input( outbuf ); remaining = cis_whole_string(argsbuf); while ( isspace(*remaining) ) remaining++; if ( remaining[0] != '\0' ) { fprintf(stderr, "Unrecognized arguments:\n%s", remaining); ok = FALSE; } cis_close(argsbuf); if ( !ok ) exit_status = EXS_ARG; }
str* pdt_get_domain(pdt_tree_t *pl, str* sdomain, str *code, int *plen) { pdt_tree_t *it; int len; str *domain=NULL; if(pl==NULL || sdomain==NULL || sdomain->s==NULL || code == NULL || code->s == NULL) { LM_INFO("bad parameters\n"); return NULL; } it = pl; while(it!=NULL && str_strcmp(&it->sdomain, sdomain)<0) it = it->next; if(it==NULL || str_strcmp(&it->sdomain, sdomain)>0) return NULL; domain = get_domain(it, code, &len); if(plen!=NULL) *plen = len; return domain; }
int set_global_virq_handler(struct domain *d, uint32_t virq) { struct domain *old; if (virq >= NR_VIRQS) return -EINVAL; if (!virq_is_global(virq)) return -EINVAL; if (global_virq_handlers[virq] == d) return 0; if (unlikely(!get_domain(d))) return -EINVAL; spin_lock(&global_virq_handlers_lock); old = global_virq_handlers[virq]; global_virq_handlers[virq] = d; spin_unlock(&global_virq_handlers_lock); if (old != NULL) put_domain(old); return 0; }
/* [email protected] */ static char *parse_chpass_clause (const char *clause, const char *username, const char *defdomain, const char *newpass, const char *newpass_crypt) { static struct var_data vd[]={ {"local_part", NULL, sizeof("local_part"), 0}, {"domain", NULL, sizeof("domain"), 0}, {"newpass", NULL, sizeof("newpass"), 0}, {"newpass_crypt", NULL, sizeof("newpass_crypt"), 0}, {NULL, NULL, 0, 0}}; if (clause == NULL || *clause == '\0' || !username || *username == '\0' || !newpass || *newpass == '\0' || !newpass_crypt || *newpass_crypt == '\0') return NULL; vd[0].value = get_localpart (username); vd[1].value = get_domain (username, defdomain); vd[2].value = validate_password (newpass); vd[3].value = validate_password (newpass_crypt); if (!vd[0].value || !vd[1].value || !vd[2].value || !vd[3].value) return NULL; return (parse_string (clause, vd)); }
static void query(struct evbuffer *rsps, char *url) { struct rulelist *node = cfg.rulelist_head; char *domain = get_domain(url); if (domain == NULL) return; while (node != NULL) { struct hashmap_s *map = node->data; struct hashentry_s *it = hashmap_find_head(map, domain); while (it != NULL) { if (strstr(url, it->data) != NULL || astermatch(url, it->data) == 0) evbuffer_add_printf(rsps, "%s|%s\n", node->name, it->data); it = hashmap_find_next(it, domain); } node = node->next; } }
bool Socket::bind(const SocketAddress& _name) { const SocketAddress* name = _name.filter(get_domain()); if (name != NULL) { return ::bind(*this, *name, name->len()) != -1; } else { return false; } }
size_t HashKey(const KeyType& key) const { net_domain* domain = get_domain(key->sa_family); if (domain == NULL) return 0; return domain->address_module->hash_address(key, false); }
bool Socket::getsockname(SocketAddress& sockname) const { socklen_t socknamelen = sockname.len(); if (::getsockname(*this, sockname, &socknamelen) != -1) { debug_assert_eq(sockname.get_family(), get_domain()); return true; } else { return false; } }
void lease_update_from_configs(void) { /* changes to the config may change current leases. */ struct dhcp_lease *lease; struct dhcp_config *config; char *name; for (lease = leases; lease; lease = lease->next) if (lease->flags & (LEASE_TA | LEASE_NA)) continue; else if ((config = find_config(daemon->dhcp_conf, NULL, lease->clid, lease->clid_len, lease->hwaddr, lease->hwaddr_len, lease->hwaddr_type, NULL)) && (config->flags & CONFIG_NAME) && (!(config->flags & CONFIG_ADDR) || config->addr.s_addr == lease->addr.s_addr)) lease_set_hostname(lease, config->hostname, 1, get_domain(lease->addr), NULL); else if ((name = host_from_dns(lease->addr))) lease_set_hostname(lease, name, 1, get_domain(lease->addr), NULL); /* updates auth flag only */ }
static const char *get_user_jid() { static std::string _jid; if (_jid.empty()) { std::stringstream ss; ss << "normaluser" << "@" << get_domain(); _jid = ss.str(); } return _jid.c_str(); }
bool Socket::connect(const SocketAddress& _peername) { const SocketAddress* peername = _peername.filter(get_domain()); if (peername != NULL) { if (::connect(*this, *peername, peername->len()) != -1) { return true; } else { return errno == EISCONN; } } else { return false; } }
// 返回 mcu jid static const char *get_mcu_jid() { static std::string _jid; if (_jid.empty()) { std::stringstream ss; ss << "mse_s_000000000000_mcu_1" << "@" << get_domain(); _jid = ss.str(); } return _jid.c_str(); }
static int jpsd_tdf_domain_cfg_handle_change(const bn_binding_array *arr, uint32 idx, bn_binding *binding, void *data) { int err; int i; char *rule = NULL; const tstring *name = NULL; const char *t_domain = NULL; domain_t *domain = NULL; tstr_array *name_parts = NULL; tbool *rechecked_licenses = data; UNUSED_ARGUMENT(arr); UNUSED_ARGUMENT(idx); bail_null(rechecked_licenses); err = bn_binding_get_name(binding, &name); bail_error(err); if (bn_binding_name_pattern_match(ts_str(name), "/nkn/jpsd/tdf/domain/**")) { bn_binding_get_name_parts(binding, &name_parts); bail_error_null(err, name_parts); if (bn_binding_name_parts_pattern_match_va(name_parts, 4, 2, "*", "rule")) { t_domain = tstr_array_get_str_quick(name_parts, 4); bail_error(err); err = bn_binding_get_str(binding, ba_value, bt_string, NULL, &rule); if (rule == NULL) goto bail; log_debug("Read .../nkn/jpsd/tdf/domain as : \"%s\"", t_domain); domain = get_domain(t_domain); for (i = 0; i < MAX_DOMAIN_RULE; i++) { if (g_domain_rule[i].active && (strcmp(g_domain_rule[i].name, rule) == 0)) { memcpy(&domain->rule, &g_domain_rule[i], sizeof(domain->rule)); break; } } safe_free(rule); insert_domain(domain); } else { goto bail; } } bail: tstr_array_free(&name_parts); return err; }
int main() { // Model, Domain and Boundary const auto flow = std::make_unique<Flow>("Couette3D"); const auto lbmodel = flow->get_lbmodel(); const auto domain = flow->get_domain(); const auto boundary = flow->get_boundary(); // Define problem and its data const auto problem = std::make_unique<PLBPD>(lbmodel, domain, boundary); auto simdata = SimData(domain->get_dimensions(), lbmodel->get_num_directions()); // Solve problem problem->initialize(simdata); simdata.write_state("init_state.h5"); problem->march_in_time(flow->get_num_timesteps(), simdata); simdata.write_state("final_state.h5"); problem->print_times(); }
/* [email protected] */ static char *parse_select_clause (const char *clause, const char *username, const char *defdomain) { static struct var_data vd[]={ {"local_part", NULL, sizeof("local_part"), 0}, {"domain", NULL, sizeof("domain"), 0}, {NULL, NULL, 0, 0}}; if (clause == NULL || *clause == '\0' || !username || *username == '\0') return NULL; vd[0].value = get_localpart (username); vd[1].value = get_domain (username, defdomain); if (!vd[0].value || !vd[1].value) return NULL; return (parse_string (clause, vd)); }
static int jpsd_tdf_domain_delete_cfg_handle_change(const bn_binding_array *arr, uint32 idx, bn_binding *binding, void *data) { int err; const tstring *name = NULL; const char *t_domain = NULL; domain_t *domain = NULL; tstr_array *name_parts = NULL; tbool *rechecked_licenses = data; UNUSED_ARGUMENT(arr); UNUSED_ARGUMENT(idx); bail_null(rechecked_licenses); err = bn_binding_get_name(binding, &name); bail_error(err); if (bn_binding_name_pattern_match(ts_str(name), "/nkn/jpsd/tdf/domain/*")) { int incarn; bn_binding_get_name_parts(binding, &name_parts); bail_error_null(err, name_parts); t_domain = tstr_array_get_str_quick(name_parts, 4); bail_error(err); domain = get_domain(t_domain); if (domain == NULL) goto bail; delete_domain(domain); pthread_rwlock_wrlock(&domain->rwlock); domain->name[0] = '\0'; domain->active = 0; domain->incarn++; memset(&domain->rule, 0, sizeof(domain_rule_t)); pthread_rwlock_unlock(&domain->rwlock); } else { goto bail; } bail: tstr_array_free(&name_parts); return err; }
struct domain *find_domain_by_id(domid_t dom) { struct domain *d; read_lock(&domlist_lock); d = domain_hash[DOMAIN_HASH(dom)]; while ( d != NULL ) { if ( d->domain_id == dom ) { if ( unlikely(!get_domain(d)) ) d = NULL; break; } d = d->next_in_hashbucket; } read_unlock(&domlist_lock); return d; }
int NEO_cache_domain(TRbDict * dict, char *str, URLNODE_T * urlNode) { int nodeLen; unsigned signs[4]; char domain[MAX_URL_LEN]; void *tmp; DOMAINNODE_T *domainNode; if (get_domain(str, domain, MAX_URL_LEN) == -1) return -1; assert(MD5(domain, strlen(domain), (unsigned char *) signs)); if (rb_dict_search(dict, signs, (void **) &domainNode) == 0) { // found!!! assert(domainNode && domainNode->urlDict); printf("src : %llu %s\n", *(KEY_T *) signs, domain); } else { // not found!!! tmp = (void *) calloc(sizeof(KEY_T), +sizeof(DOMAINNODE_T)); assert(tmp); memcpy(tmp, signs, sizeof(KEY_T)); // insert a new domain rb_dict_insert(dict, tmp, tmp + sizeof(KEY_T), 0); // creat urlcache about this domain domainNode = (DOMAINNODE_T *) (tmp + sizeof(KEY_T)); snprintf(domainNode->domain, MAX_DOMAIN_LEN, "%s", domain); __cache_init(domainNode); } url_trim(str); __cache_url(domainNode->urlDict, NULL, str, urlNode); return 0; }
ssize_t DatagramSocket::sendmsg( const iovec* iov, int iovlen, const MessageFlags& flags, const SocketAddress& peername ) { msghdr msghdr_; memset(&msghdr_, 0, sizeof(msghdr_)); msghdr_.msg_iov = const_cast<iovec*>(iov); msghdr_.msg_iovlen = iovlen; const SocketAddress* peername_ = peername.filter(get_domain()); if (peername_ != NULL) { const sockaddr* peername_sockaddr = *peername_; msghdr_.msg_name = const_cast<sockaddr*>(peername_sockaddr); msghdr_.msg_namelen = peername_->len(); } else { return -1; } return ::sendmsg(*this, &msghdr_, flags); }
ssize_t DatagramSocket::sendto( const void* buf, size_t buflen, const MessageFlags& flags, const SocketAddress& peername ) { const SocketAddress* peername_ = peername.filter(get_domain()); if (peername_ != NULL) { return ::sendto( *this, static_cast<const char*>(buf), buflen, flags, *peername_, peername_->len() ); } else { return -1; } }
static void gen_conditions_for_pow_cst_base (tree base, tree expn, vec<gimple> conds, unsigned *nconds) { inp_domain exp_domain; /* Validate the range of the base constant to make sure it is consistent with check_pow. */ REAL_VALUE_TYPE mv; REAL_VALUE_TYPE bcv = TREE_REAL_CST (base); gcc_assert (!REAL_VALUES_EQUAL (bcv, dconst1) && !REAL_VALUES_LESS (bcv, dconst1)); real_from_integer (&mv, TYPE_MODE (TREE_TYPE (base)), 256, UNSIGNED); gcc_assert (!REAL_VALUES_LESS (mv, bcv)); exp_domain = get_domain (0, false, false, 127, true, false); gen_conditions_for_domain (expn, exp_domain, conds, nconds); }
unsigned NEO_cache_check(TRbDict * dict, char *str) { unsigned signs[4]; char domain[MAX_URL_LEN]; DOMAINNODE_T *tmp = NULL; if (get_domain(str, domain, MAX_URL_LEN) == -1) return (unsigned) -1; assert(MD5(domain, strlen(domain), (unsigned char *) signs)); if (rb_dict_search(dict, signs, (void **) &tmp) != 0) { return 0; } else { assert(tmp); return rb_dict_count(((DOMAINNODE_T *) tmp)->urlDict); } return 0; }
struct domain *get_domain_by_id(domid_t dom) { struct domain *d; rcu_read_lock(&domlist_read_lock); for ( d = rcu_dereference(domain_hash[DOMAIN_HASH(dom)]); d != NULL; d = rcu_dereference(d->next_in_hashbucket) ) { if ( d->domain_id == dom ) { if ( unlikely(!get_domain(d)) ) d = NULL; break; } } rcu_read_unlock(&domlist_read_lock); return d; }
struct nl_client * vr_get_nl_client(unsigned int proto) { int ret; unsigned int sock_proto = proto; struct nl_client *cl; cl = nl_register_client(); if (!cl) return NULL; parse_ini_file(); if (proto == VR_NETLINK_PROTO_DEFAULT) sock_proto = get_protocol(); ret = nl_socket(cl, get_domain(), get_type(), sock_proto); if (ret <= 0) goto fail; ret = nl_connect(cl, get_ip(), get_port()); if (ret < 0) goto fail; if ((proto == VR_NETLINK_PROTO_DEFAULT) && (vrouter_get_family_id(cl) <= 0)) goto fail; return cl; fail: if (cl) nl_free_client(cl); return NULL; }
static long __evtchn_close(struct domain *d1, int port1) { struct domain *d2 = NULL; struct vcpu *v; struct evtchn *chn1, *chn2; int port2; long rc = 0; again: spin_lock(&d1->evtchn_lock); if ( !port_is_valid(d1, port1) ) { rc = -EINVAL; goto out; } chn1 = evtchn_from_port(d1, port1); /* Guest cannot close a Xen-attached event channel. */ if ( unlikely(chn1->consumer_is_xen) ) { rc = -EINVAL; goto out; } switch ( chn1->state ) { case ECS_FREE: case ECS_RESERVED: rc = -EINVAL; goto out; case ECS_UNBOUND: break; case ECS_PIRQ: pirq_guest_unbind(d1, chn1->u.pirq); d1->pirq_to_evtchn[chn1->u.pirq] = 0; break; case ECS_VIRQ: for_each_vcpu ( d1, v ) { if ( v->virq_to_evtchn[chn1->u.virq] != port1 ) continue; v->virq_to_evtchn[chn1->u.virq] = 0; spin_barrier(&v->virq_lock); } break; case ECS_IPI: break; case ECS_INTERDOMAIN: if ( d2 == NULL ) { d2 = chn1->u.interdomain.remote_dom; /* If we unlock d1 then we could lose d2. Must get a reference. */ if ( unlikely(!get_domain(d2)) ) BUG(); if ( d1 < d2 ) { spin_lock(&d2->evtchn_lock); } else if ( d1 != d2 ) { spin_unlock(&d1->evtchn_lock); spin_lock(&d2->evtchn_lock); goto again; } } else if ( d2 != chn1->u.interdomain.remote_dom ) { /* * We can only get here if the port was closed and re-bound after * unlocking d1 but before locking d2 above. We could retry but * it is easier to return the same error as if we had seen the * port in ECS_CLOSED. It must have passed through that state for * us to end up here, so it's a valid error to return. */ rc = -EINVAL; goto out; } port2 = chn1->u.interdomain.remote_port; BUG_ON(!port_is_valid(d2, port2)); chn2 = evtchn_from_port(d2, port2); BUG_ON(chn2->state != ECS_INTERDOMAIN); BUG_ON(chn2->u.interdomain.remote_dom != d1); chn2->state = ECS_UNBOUND; chn2->u.unbound.remote_domid = d1->domain_id; break; default: BUG(); } /* Clear pending event to avoid unexpected behavior on re-bind. */ clear_bit(port1, shared_info_addr(d1, evtchn_pending)); /* Reset binding to vcpu0 when the channel is freed. */ chn1->state = ECS_FREE; chn1->notify_vcpu_id = 0; xsm_evtchn_close_post(chn1); out: if ( d2 != NULL ) { if ( d1 != d2 ) spin_unlock(&d2->evtchn_lock); put_domain(d2); } spin_unlock(&d1->evtchn_lock); return rc; }
status_t icmp6_receive_data(net_buffer *buffer) { TRACE(("ICMPv6 received some data, buffer length %" B_PRIu32 "\n", buffer->size)); net_domain* domain = get_domain(buffer); if (domain == NULL) return B_ERROR; NetBufferHeaderReader<icmp6_hdr> bufferHeader(buffer); if (bufferHeader.Status() < B_OK) return bufferHeader.Status(); icmp6_hdr &header = bufferHeader.Data(); TRACE((" got type %u, code %u, checksum 0x%x\n", header.icmp6_type, header.icmp6_code, header.icmp6_cksum)); net_address_module_info* addressModule = domain->address_module; // compute and check the checksum if (Checksum::PseudoHeader(addressModule, gBufferModule, buffer, IPPROTO_ICMPV6) != 0) return B_BAD_DATA; switch (header.icmp6_type) { case ICMP6_ECHO_REPLY: break; case ICMP6_ECHO_REQUEST: { if (buffer->interface_address != NULL) { // We only reply to echo requests of our local interface; we // don't reply to broadcast requests if (!domain->address_module->equal_addresses( buffer->interface_address->local, buffer->destination)) break; } net_buffer *reply = gBufferModule->duplicate(buffer); if (reply == NULL) return B_NO_MEMORY; gBufferModule->swap_addresses(reply); // There already is an ICMP header, and we'll reuse it NetBufferHeaderReader<icmp6_hdr> header(reply); header->icmp6_type = ICMP6_ECHO_REPLY; header->icmp6_code = 0; header->icmp6_cksum = 0; header.Sync(); *ICMP6ChecksumField(reply) = Checksum::PseudoHeader(addressModule, gBufferModule, buffer, IPPROTO_ICMPV6); status_t status = domain->module->send_data(NULL, reply); if (status < B_OK) { gBufferModule->free(reply); return status; } } default: // unrecognized messages go to neighbor discovery protocol handler return sIPv6NDPModule->receive_data(buffer); } gBufferModule->free(buffer); return B_OK; }
static void handle_request(void *ctx) { conn_t *conn = ctx; struct evbuffer *rsps = evbuffer_new(); struct state *s = conn->state; if (strcmp(conn->method, "GET") == 0) { if (strcmp(conn->url, "/getproxies") == 0) get_proxies(rsps); else if (strcmp(conn->url, "/getlists") == 0) get_lists(rsps); else if (strncmp(conn->url, "/query?", 7) == 0) query(rsps, evhttp_decode_uri(conn->url + 7)); else if (strcmp(conn->url, "/getlog") == 0) get_log(rsps); else if (strcmp(conn->url, "/gettrylist") == 0) get_trylist(rsps); else if (strcmp(conn->url, "/getversion") == 0) evbuffer_add_printf(rsps, VERSION); } else if (strcmp(conn->method, "POST") == 0) { struct evkeyvalq kv; struct evhttp_uri *uri = evhttp_uri_parse_with_flags(conn->url, 0); evhttp_parse_query_str(evhttp_uri_get_query(uri), &kv); char *cont; if (s->length) cont = s->body; const char *path = evhttp_uri_get_path(uri); if (strcmp(path, "/addrule") == 0 || strcmp(path, "/rmrule") == 0) { struct evkeyvalq kvc; evhttp_parse_query_str(cont, &kvc); char *list = evhttp_decode_uri(evhttp_find_header(&kvc, "list")); char *rule = evhttp_decode_uri(evhttp_find_header(&kvc, "rule")); if (get_domain(rule) == NULL) evbuffer_add_printf(rsps, "Invalid rule."); else { if (strcmp(path, "/addrule") == 0) update_rule(list, rule); else remove_rule(list, rule); evbuffer_add_printf(rsps, "OK"); } free(list); free(rule); free(cont); } else if (strcmp(path, "/flush") == 0) { flush_list(); evbuffer_add_printf(rsps, "OK"); } else if (strcmp(path, "/rmlog") == 0) { rm_log(rsps); } else if (strcmp(path, "/purgetrylist") == 0) { purgetrylist(rsps); } evhttp_uri_free(uri); } ret(conn->be_client, rsps); evbuffer_free(rsps); }