int invert(DenseMatrix& A, size_t nn) { integer n = static_cast<int>(nn != npos ? nn : A.nRows()); int info=0; ct_dgetrf(n, n, A.ptrColumn(0), static_cast<int>(A.nRows()), &A.ipiv()[0], info); if (info != 0) { if (A.m_printLevel) { writelogf("invert(DenseMatrix& A, int nn): DGETRS returned INFO = %d\n", info); } if (! A.m_useReturnErrorCode) { throw CELapackError("invert(DenseMatrix& A, int nn)", "DGETRS returned INFO = "+int2str(info)); } return info; } vector_fp work(n); integer lwork = static_cast<int>(work.size()); ct_dgetri(n, A.ptrColumn(0), static_cast<int>(A.nRows()), &A.ipiv()[0], &work[0], lwork, info); if (info != 0) { if (A.m_printLevel) { writelogf("invert(DenseMatrix& A, int nn): DGETRS returned INFO = %d\n", info); } if (! A.m_useReturnErrorCode) { throw CELapackError("invert(DenseMatrix& A, int nn)", "DGETRI returned INFO="+int2str(info)); } } return info; }
int main (void) { int int2str (int num); int2str(-456); return 0; }
static inline int mi_print_b2be_dlg(struct mi_node *rpl, b2b_table htable, unsigned int hsize) { int i, len; char* p; b2b_dlg_t* dlg; dlg_leg_t* leg; struct mi_node *node=NULL, *node1=NULL, *node_l=NULL; struct mi_attr* attr; for(i = 0; i< hsize; i++) { lock_get(&htable[i].lock); dlg = htable[i].first; while(dlg) { p = int2str((unsigned long)(dlg->id), &len); node = add_mi_node_child(rpl, MI_DUP_VALUE, "dlg", 3, p, len); if(node == NULL) goto error; attr = add_mi_attr(node, MI_DUP_VALUE, "param", 5, dlg->param.s, dlg->param.len); if(attr == NULL) goto error; p = int2str((unsigned long)(dlg->state), &len); attr = add_mi_attr(node, MI_DUP_VALUE, "state", 5, p, len); if(attr == NULL) goto error; p = int2str((unsigned long)(dlg->last_invite_cseq), &len); attr = add_mi_attr(node, MI_DUP_VALUE, "last_invite_cseq", 16, p, len); if(attr == NULL) goto error; p = int2str((unsigned long)(dlg->last_method), &len); attr = add_mi_attr(node, MI_DUP_VALUE, "last_method", 11, p, len); if(attr == NULL) goto error; if (dlg->last_reply_code) { p = int2str((unsigned long)(dlg->last_reply_code), &len); attr = add_mi_attr(node,MI_DUP_VALUE,"last_reply_code",15,p,len); if(attr == NULL) goto error; } p = int2str((unsigned long)(dlg->db_flag), &len); attr = add_mi_attr(node, MI_DUP_VALUE, "db_flag", 7, p, len); if(attr == NULL) goto error; if (dlg->ruri.len) { node1 = add_mi_node_child(node, MI_DUP_VALUE, "ruri", 4, dlg->ruri.s, dlg->ruri.len); if(node1 == NULL) goto error; } node1 = add_mi_node_child(node, MI_DUP_VALUE, "callid", 6, dlg->callid.s, dlg->callid.len); if(node1 == NULL) goto error; node1 = add_mi_node_child(node, MI_DUP_VALUE, "from", 4, dlg->from_dname.s, dlg->from_dname.len); if(node1 == NULL) goto error; attr = add_mi_attr(node1, MI_DUP_VALUE, "uri", 3, dlg->from_uri.s, dlg->from_uri.len); if(attr == NULL) goto error; attr = add_mi_attr(node1, MI_DUP_VALUE, "tag", 3, dlg->tag[0].s, dlg->tag[0].len); if(attr == NULL) goto error; node1 = add_mi_node_child(node, MI_DUP_VALUE, "to", 2, dlg->to_dname.s, dlg->to_dname.len); if(node1 == NULL) goto error; attr = add_mi_attr(node1, MI_DUP_VALUE, "uri", 3, dlg->to_uri.s, dlg->to_uri.len); if(attr == NULL) goto error; attr = add_mi_attr(node1, MI_DUP_VALUE, "tag", 3, dlg->tag[1].s, dlg->tag[1].len); if(attr == NULL) goto error; node1 = add_mi_node_child(node, MI_DUP_VALUE, "cseq", 4, NULL, 0); if(node1 == NULL) goto error; p = int2str((unsigned long)(dlg->cseq[0]), &len); attr = add_mi_attr(node1, MI_DUP_VALUE, "caller", 6, p, len); if(attr == NULL) goto error; p = int2str((unsigned long)(dlg->cseq[1]), &len); attr = add_mi_attr(node1, MI_DUP_VALUE, "callee", 6, p, len); if(attr == NULL) goto error; if (dlg->route_set[0].len||dlg->route_set[1].len) { node1 = add_mi_node_child(node,MI_DUP_VALUE,"route_set",9,NULL,0); if(node1 == NULL) goto error; if (dlg->route_set[0].len) { attr = add_mi_attr(node1, MI_DUP_VALUE, "caller", 6, dlg->route_set[0].s, dlg->route_set[0].len); if(attr == NULL) goto error; } if (dlg->route_set[1].len) { attr = add_mi_attr(node1, MI_DUP_VALUE, "callee", 6, dlg->route_set[1].s, dlg->route_set[1].len); if(attr == NULL) goto error; } } node1 = add_mi_node_child(node, MI_DUP_VALUE, "contact", 7, NULL, 0); if(node1 == NULL) goto error; attr = add_mi_attr(node1, MI_DUP_VALUE, "caller", 6, dlg->contact[0].s, dlg->contact[0].len); if(attr == NULL) goto error; attr = add_mi_attr(node1, MI_DUP_VALUE, "callee", 6, dlg->contact[1].s, dlg->contact[1].len); if(attr == NULL) goto error; if (dlg->send_sock) { node1 = add_mi_node_child(node, MI_DUP_VALUE, "send_sock", 9, dlg->send_sock->name.s, dlg->send_sock->name.len); if(node1 == NULL) goto error; } if(dlg->uac_tran||dlg->uas_tran||dlg->update_tran||dlg->cancel_tm_tran) { node1 = add_mi_node_child(node, MI_DUP_VALUE, "tm_tran", 7, NULL, 0); if(node1 == NULL) goto error; if(dlg->uac_tran) attr = add_mi_attr(node1,MI_DUP_VALUE,"uac",3,NULL,0); if(attr == NULL) goto error; if(dlg->uas_tran) attr = add_mi_attr(node1,MI_DUP_VALUE,"uas",3,NULL,0); if(attr == NULL) goto error; if(dlg->update_tran) attr = add_mi_attr(node1,MI_DUP_VALUE,"update",6,NULL,0); if(attr == NULL) goto error; if(dlg->cancel_tm_tran) attr = add_mi_attr(node1,MI_DUP_VALUE,"cancel_tm",9,NULL,0); if(attr == NULL) goto error; } if ( (leg=dlg->legs)!=NULL ) { node_l = add_mi_node_child(node, MI_IS_ARRAY, "LEGS", 4, NULL, 0); if(node_l == NULL) goto error; while(leg) { p = int2str((unsigned long)(leg->id), &len); node1 = add_mi_node_child(node_l, MI_DUP_VALUE, "leg", 3, p, len); if(node1 == NULL) goto error; attr = add_mi_attr(node1, MI_DUP_VALUE, "tag", 3, leg->tag.s, leg->tag.len); if(attr == NULL) goto error; p = int2str((unsigned long)(leg->cseq), &len); attr = add_mi_attr(node1, MI_DUP_VALUE, "cseq", 4, p, len); if(attr == NULL) goto error; attr = add_mi_attr(node1, MI_DUP_VALUE, "contact", 7, leg->contact.s, leg->contact.len); if(attr == NULL) goto error; if(leg->route_set.len) { attr = add_mi_attr(node1, MI_DUP_VALUE, "route_set", 8, leg->route_set.s, leg->route_set.len); if(attr == NULL) goto error; } leg=leg->next; } } dlg = dlg->next; } lock_release(&htable[i].lock); } return 0; error: lock_release(&htable[i].lock); LM_ERR("failed to add node\n"); return -1; }
/* mi function implementations */ struct mi_root* mi_stats(struct mi_root* cmd_tree, void* param) { struct mi_root *rpl_tree; struct mi_node *node=NULL, *rpl=NULL; struct mi_attr* attr; char* p; int i, len; pl_pipe_t *it; rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN); if (rpl_tree==0) return 0; rpl = &rpl_tree->node; for(i=0; i<_pl_pipes_ht->htsize; i++) { lock_get(&_pl_pipes_ht->slots[i].lock); it = _pl_pipes_ht->slots[i].first; while(it) { if (it->algo != PIPE_ALGO_NOP) { node = add_mi_node_child(rpl, 0, "PIPE", 4, 0, 0); if(node == NULL) { lock_release(&_pl_pipes_ht->slots[i].lock); goto error; } attr = add_mi_attr(node, MI_DUP_VALUE, "id", 2, it->name.s, it->name.len); if(attr == NULL) { lock_release(&_pl_pipes_ht->slots[i].lock); goto error; } p = int2str((unsigned long)(it->load), &len); attr = add_mi_attr(node, MI_DUP_VALUE, "load", 4, p, len); if(attr == NULL) { lock_release(&_pl_pipes_ht->slots[i].lock); goto error; } p = int2str((unsigned long)(it->last_counter), &len); attr = add_mi_attr(node, MI_DUP_VALUE, "counter", 7, p, len); if(attr == NULL) { lock_release(&_pl_pipes_ht->slots[i].lock); goto error; } } it = it->next; } lock_release(&_pl_pipes_ht->slots[i].lock); } #if 0 p = int2str((unsigned long)(*drop_rate), &len); node = add_mi_node_child(rpl, MI_DUP_VALUE, "DROP_RATE", 9, p, len); #endif return rpl_tree; error: LM_ERR("Unable to create reply\n"); free_mi_tree(rpl_tree); return 0; }
struct mi_root* mi_get_pipes(struct mi_root* cmd_tree, void* param) { struct mi_root *rpl_tree; struct mi_node *node=NULL, *rpl=NULL; struct mi_attr* attr; str algo; char* p; int i, len; pl_pipe_t *it; rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN); if (rpl_tree==0) return 0; rpl = &rpl_tree->node; for(i=0; i<_pl_pipes_ht->htsize; i++) { lock_get(&_pl_pipes_ht->slots[i].lock); it = _pl_pipes_ht->slots[i].first; while(it) { if (it->algo != PIPE_ALGO_NOP) { node = add_mi_node_child(rpl, 0, "PIPE", 4, 0, 0); if(node == NULL) { lock_release(&_pl_pipes_ht->slots[i].lock); goto error; } attr = add_mi_attr(node, MI_DUP_VALUE, "id" , 2, it->name.s, it->name.len); if(attr == NULL) { lock_release(&_pl_pipes_ht->slots[i].lock); goto error; } if (str_map_int(algo_names, it->algo, &algo)) { lock_release(&_pl_pipes_ht->slots[i].lock); goto error; } attr = add_mi_attr(node, 0, "algorithm", 9, algo.s, algo.len); if(attr == NULL) { lock_release(&_pl_pipes_ht->slots[i].lock); goto error; } p = int2str((unsigned long)(it->limit), &len); attr = add_mi_attr(node, MI_DUP_VALUE, "limit", 5, p, len); if(attr == NULL) { lock_release(&_pl_pipes_ht->slots[i].lock); goto error; } p = int2str((unsigned long)(it->counter), &len); attr = add_mi_attr(node, MI_DUP_VALUE, "counter", 7, p, len); if(attr == NULL) { lock_release(&_pl_pipes_ht->slots[i].lock); goto error; } } it = it->next; } lock_release(&_pl_pipes_ht->slots[i].lock); } return rpl_tree; error: LM_ERR("Unable to create reply\n"); free_mi_tree(rpl_tree); return 0; }
/**************************** MI functions ******************************/ static inline int internal_mi_print_dlg(struct mi_node *rpl, struct dlg_cell *dlg, int with_context) { struct mi_node* node= NULL; struct mi_node* node1 = NULL; struct mi_attr* attr= NULL; struct dlg_profile_link *dl; struct dlg_val* dv; int len; char* p; int i; node = add_mi_node_child(rpl, 0, "dialog",6 , 0, 0 ); if (node==0) goto error; attr = addf_mi_attr( node, 0, "hash", 4, "%u:%u", dlg->h_entry, dlg->h_id ); if (attr==0) goto error; p= int2str((unsigned long)dlg->state, &len); node1 = add_mi_node_child( node, MI_DUP_VALUE, "state", 5, p, len); if (node1==0) goto error; p= int2str((unsigned long)dlg->user_flags, &len); node1 = add_mi_node_child( node, MI_DUP_VALUE, "user_flags", 10, p, len); if (node1==0) goto error; p= int2str((unsigned long)dlg->start_ts, &len); node1 = add_mi_node_child(node,MI_DUP_VALUE,"timestart",9, p, len); if (node1==0) goto error; p= int2str((unsigned long)(dlg->tl.timeout?((unsigned int)time(0) + dlg->tl.timeout - get_ticks()):0), &len); node1 = add_mi_node_child(node,MI_DUP_VALUE, "timeout", 7, p, len); if (node1==0) goto error; node1 = add_mi_node_child(node, MI_DUP_VALUE, "callid", 6, dlg->callid.s, dlg->callid.len); if(node1 == 0) goto error; node1 = add_mi_node_child(node, MI_DUP_VALUE, "from_uri", 8, dlg->from_uri.s, dlg->from_uri.len); if(node1 == 0) goto error; node1 = add_mi_node_child(node, MI_DUP_VALUE, "to_uri", 6, dlg->to_uri.s, dlg->to_uri.len); if(node1 == 0) goto error; if (dlg->legs_no[DLG_LEGS_USED]>0) { node1 = add_mi_node_child(node, MI_DUP_VALUE, "caller_tag", 10, dlg->legs[DLG_CALLER_LEG].tag.s, dlg->legs[DLG_CALLER_LEG].tag.len); if(node1 == 0) goto error; node1 = add_mi_node_child(node, MI_DUP_VALUE, "caller_contact", 14, dlg->legs[DLG_CALLER_LEG].contact.s, dlg->legs[DLG_CALLER_LEG].contact.len); if(node1 == 0) goto error; node1 = add_mi_node_child(node, MI_DUP_VALUE, "callee_cseq", 11, dlg->legs[DLG_CALLER_LEG].r_cseq.s, dlg->legs[DLG_CALLER_LEG].r_cseq.len); if(node1 == 0) goto error; node1 = add_mi_node_child(node, MI_DUP_VALUE,"caller_route_set",16, dlg->legs[DLG_CALLER_LEG].route_set.s, dlg->legs[DLG_CALLER_LEG].route_set.len); if(node1 == 0) goto error; node1 = add_mi_node_child(node, 0,"caller_bind_addr",16, dlg->legs[DLG_CALLER_LEG].bind_addr->sock_str.s, dlg->legs[DLG_CALLER_LEG].bind_addr->sock_str.len); if(node1 == 0) goto error; } for( i=1 ; i < dlg->legs_no[DLG_LEGS_USED] ; i++ ) { node1 = add_mi_node_child(node, MI_DUP_VALUE, "callee_tag", 10, dlg->legs[i].tag.s, dlg->legs[i].tag.len); if(node1 == 0) goto error; node1 = add_mi_node_child(node, MI_DUP_VALUE, "callee_contact", 14, dlg->legs[i].contact.s, dlg->legs[i].contact.len); if(node1 == 0) goto error; node1 = add_mi_node_child(node, MI_DUP_VALUE, "caller_cseq", 11, dlg->legs[i].r_cseq.s, dlg->legs[i].r_cseq.len); if(node1 == 0) goto error; node1 = add_mi_node_child(node, MI_DUP_VALUE,"callee_route_set",16, dlg->legs[i].route_set.s, dlg->legs[i].route_set.len); if(node1 == 0) goto error; if (dlg->legs[i].bind_addr) { node1 = add_mi_node_child(node, 0, "callee_bind_addr",16, dlg->legs[i].bind_addr->sock_str.s, dlg->legs[i].bind_addr->sock_str.len); } else { node1 = add_mi_node_child(node, 0, "callee_bind_addr",16,0,0); } if(node1 == 0) goto error; } if (with_context) { node1 = add_mi_node_child(node, 0, "context", 7, 0, 0); if(node1 == 0) goto error; /* print dlg values -> iterate the list */ for( dv=dlg->vals ; dv ; dv=dv->next) { addf_mi_node_child(node1, MI_DUP_VALUE, MI_SSTR("value"), "%.*s = %.*s",dv->name.len,dv->name.s,dv->val.len,dv->val.s); } /* print dlg profiles */ for( dl=dlg->profile_links ; dl ; dl=dl->next) { addf_mi_node_child(node1, MI_DUP_VALUE, MI_SSTR("profile"), "%.*s = %.*s",dl->profile->name.len,dl->profile->name.s, dl->value.len,ZSW(dl->value.s)); } /* print external context info */ run_dlg_callbacks( DLGCB_MI_CONTEXT, dlg, NULL, DLG_DIR_NONE, (void *)node1); } return 0; error: LM_ERR("failed to add node\n"); return -1; }
doublereal MolarityIonicVPSSTP::err(const std::string& msg) const { throw CanteraError("MolarityIonicVPSSTP","Base class method " +msg+" called. Equation of state type: "+int2str(eosType())); return 0; }
int xhttp_rpc_build_header(rpc_ctx_t *ctx) { int i, j; char *p = ctx->reply.body.s; char *buf = ctx->reply.buf.s; str code; int max_page_len = ctx->reply.buf.len; int mod = ctx->mod; int cmd = ctx->cmd; str name; str exec_name = {(char*)ver_name, ver_name_len}; str server_hdr = {(char*)full_version, full_version_len}; XHTTP_RPC_COPY_10(p,XHTTP_RPC_Response_Head_1, exec_name, XHTTP_RPC_Response_Head_2, XHTTP_RPC_Response_Head_3, XHTTP_RPC_Response_Title_Table_1, exec_name, XHTTP_RPC_Response_Title_Table_2, server_hdr, XHTTP_RPC_Response_Title_Table_4, /* Building module menu */ XHTTP_RPC_Response_Menu_Table_1); for(i=0; i<xhttp_rpc_mod_cmds_size; i++) { if(i!=mod) { XHTTP_RPC_COPY(p,XHTTP_RPC_Response_Menu_Table_2); } else { XHTTP_RPC_COPY(p,XHTTP_RPC_Response_Menu_Table_2b); } XHTTP_RPC_COPY(p,XHTTP_RPC_SLASH); if (xhttp_rpc_root.len) { XHTTP_RPC_COPY_2(p,xhttp_rpc_root,XHTTP_RPC_SLASH); } XHTTP_RPC_COPY_3(p,xhttp_rpc_mod_cmds[i].mod, XHTTP_RPC_Response_Menu_Table_3, xhttp_rpc_mod_cmds[i].mod); if(i!=mod) { XHTTP_RPC_COPY(p,XHTTP_RPC_Response_Menu_Table_4); } else { XHTTP_RPC_COPY(p,XHTTP_RPC_Response_Menu_Table_4b); } } XHTTP_RPC_COPY(p,XHTTP_RPC_Response_Menu_Table_5); if (ctx->arg_received) { /* Build an rpc reply */ name.s = (char*)rpc_sarray[xhttp_rpc_mod_cmds[mod].rpc_e_index+cmd]->name; name.len = strlen(name.s); /* Print comand name */ XHTTP_RPC_COPY_4(p,XHTTP_RPC_Response_Menu_Cmd_Table_1, XHTTP_RPC_Response_Menu_Cmd_tr_1, XHTTP_RPC_Response_Menu_Cmd_td_1a, XHTTP_RPC_SLASH); if (xhttp_rpc_root.len) { XHTTP_RPC_COPY_2(p,xhttp_rpc_root, XHTTP_RPC_SLASH); } XHTTP_RPC_COPY_6(p,xhttp_rpc_mod_cmds[mod].mod, XHTTP_RPC_SLASH, name, XHTTP_RPC_Response_Menu_Cmd_td_3a, name, XHTTP_RPC_Response_Menu_Cmd_td_4a); /* Print response code */ XHTTP_RPC_COPY(p,XHTTP_RPC_Response_Menu_Cmd_td_1d); code.s = int2str((unsigned long)ctx->reply.code, &code.len); XHTTP_RPC_COPY_10(p,code, XHTTP_RPC_SEMICOLON, ctx->reply.reason, XHTTP_RPC_Response_Menu_Cmd_td_4d, XHTTP_RPC_Response_Menu_Cmd_tr_2, XHTTP_RPC_Response_Menu_Cmd_tr_1, XHTTP_RPC_Response_Menu_Cmd_td_1d, XHTTP_RPC_Response_Menu_Cmd_td_4d, XHTTP_RPC_Response_Menu_Cmd_td_1d, XHTTP_RPC_CODE_1); } else if (mod>=0) { /* Building command menu */ if (ctx->reply.body.len==0 && ctx->reply.code!=200) { code.s = int2str((unsigned long)ctx->reply.code, &code.len); XHTTP_RPC_COPY_5(p,XHTTP_RPC_CODE_1, code, XHTTP_RPC_SEMICOLON, ctx->reply.reason, XHTTP_RPC_CODE_2); } else { name.s = (char*)rpc_sarray[xhttp_rpc_mod_cmds[mod].rpc_e_index]->name; name.len = strlen(name.s); /* Build the list of comands for the selected module */ XHTTP_RPC_COPY_4(p,XHTTP_RPC_Response_Menu_Cmd_Table_1, XHTTP_RPC_Response_Menu_Cmd_tr_1, XHTTP_RPC_Response_Menu_Cmd_td_1a, XHTTP_RPC_SLASH); if (xhttp_rpc_root.len) { XHTTP_RPC_COPY_2(p,xhttp_rpc_root,XHTTP_RPC_SLASH); } XHTTP_RPC_COPY_6(p,xhttp_rpc_mod_cmds[mod].mod, XHTTP_RPC_SLASH, name, XHTTP_RPC_Response_Menu_Cmd_td_3a, name, XHTTP_RPC_Response_Menu_Cmd_td_4a); if (cmd>=0) { name.s = (char*)rpc_sarray[xhttp_rpc_mod_cmds[mod].rpc_e_index+cmd]->name; name.len = strlen(name.s); XHTTP_RPC_COPY_3(p,XHTTP_RPC_Response_Menu_Cmd_td_1b, name, XHTTP_RPC_Response_Menu_Cmd_td_4b); } XHTTP_RPC_COPY(p,XHTTP_RPC_Response_Menu_Cmd_tr_2); for(j=1; j<xhttp_rpc_mod_cmds[mod].size; j++) { name.s = (char*)rpc_sarray[xhttp_rpc_mod_cmds[mod].rpc_e_index+j]->name; name.len = strlen(name.s); XHTTP_RPC_COPY_3(p,XHTTP_RPC_Response_Menu_Cmd_tr_1, XHTTP_RPC_Response_Menu_Cmd_td_1a, XHTTP_RPC_SLASH); if (xhttp_rpc_root.len) { XHTTP_RPC_COPY_2(p,xhttp_rpc_root, XHTTP_RPC_SLASH); } XHTTP_RPC_COPY_6(p,xhttp_rpc_mod_cmds[mod].mod, XHTTP_RPC_SLASH, name, XHTTP_RPC_Response_Menu_Cmd_td_3a, name, XHTTP_RPC_Response_Menu_Cmd_td_4a); if (cmd>=0) { if (j==1) { XHTTP_RPC_COPY_5(p, XHTTP_RPC_Response_Menu_Cmd_td_1c, XHTTP_RPC_CMD_ROWSPAN, XHTTP_RPC_Response_Menu_Cmd_td_3c, XHTTP_RPC_Post_1, XHTTP_RPC_Response_Menu_Cmd_td_4c); } else if (j>XHTTP_RPC_ROWSPAN) { XHTTP_RPC_COPY_3(p, XHTTP_RPC_Response_Menu_Cmd_td_1d, XHTTP_RPC_NBSP, XHTTP_RPC_Response_Menu_Cmd_td_4d); } } XHTTP_RPC_COPY(p,XHTTP_RPC_Response_Menu_Cmd_tr_2); } if (cmd>=0) { if (j==1) { XHTTP_RPC_COPY_10(p,XHTTP_RPC_Response_Menu_Cmd_tr_1, XHTTP_RPC_Response_Menu_Cmd_td_1d, XHTTP_RPC_NBSP, XHTTP_RPC_Response_Menu_Cmd_td_4d, XHTTP_RPC_Response_Menu_Cmd_td_1c, XHTTP_RPC_CMD_ROWSPAN, XHTTP_RPC_Response_Menu_Cmd_td_3c, XHTTP_RPC_Post_1, XHTTP_RPC_Response_Menu_Cmd_td_4c, XHTTP_RPC_Response_Menu_Cmd_tr_2); j++; } for(; j<=XHTTP_RPC_ROWSPAN; j++) { XHTTP_RPC_COPY_5(p,XHTTP_RPC_Response_Menu_Cmd_tr_1, XHTTP_RPC_Response_Menu_Cmd_td_1d, XHTTP_RPC_NBSP, XHTTP_RPC_Response_Menu_Cmd_td_4d, XHTTP_RPC_Response_Menu_Cmd_tr_2); } } } XHTTP_RPC_COPY_2(p,XHTTP_RPC_Response_Menu_Cmd_Table_2, XHTTP_RPC_Response_Foot); } else { if (ctx->reply.body.len==0 && ctx->reply.code!=200) { code.s = int2str((unsigned long)ctx->reply.code, &code.len); XHTTP_RPC_COPY_5(p,XHTTP_RPC_CODE_1, code, XHTTP_RPC_SEMICOLON, ctx->reply.reason, XHTTP_RPC_CODE_2); } XHTTP_RPC_COPY(p,XHTTP_RPC_Response_Foot); } ctx->reply.body.len = p - ctx->reply.body.s; return 0; error: LM_ERR("buffer 2 small\n"); ctx->reply.body.len = p - ctx->reply.body.s; return -1; }
//ndif int cgiMain() { //#ifdef _MANAGE_FIREWALL_ fwRuleList *list; fwRule *rule; struct list *lpublic; struct list *lfirewall; int i=0; int ruleType = 0; //得到rule的类型, fileter dnat snat input char ruleTypeStr[10];//FILTER SNAT DNAT INPUT char *encry=(char *)malloc(BUF_LEN); char *str; int manager=-1; void *fwrule_dbus_connection = NULL; int iWallTotalNum = 0; int iSNATTotalNum = 0; int iDNATTotalNum = 0; int iInputTotalNum = 0; lpublic=get_chain_head("../htdocs/text/public.txt"); lfirewall=get_chain_head("../htdocs/text/firewall.txt"); memset(encry,0,BUF_LEN); cgiFormStringNoNewlines("UN", encry, BUF_LEN); str=dcryption(encry); if(str==NULL) { ShowErrorPage(search(lpublic,"ill_user")); /*用户非法*/ return 0; } manager = checkuser_group(str); cgiHeaderContentType("text/html"); //list=(fwRuleList *)malloc(sizeof(fwRuleList)); //memset( list, 0, sizeof(fwRuleList) ); //ParseDoc( list ); //do init data int ret = -1; u_long rule_num; fwRule *rule_array; DcliWInit(); ccgi_dbus_init(); char plotid[10] = { 0 }; int p_id = 1; // int instRun = DCLI_VRRP_INSTANCE_NO_CREATED; cgiFormStringNoNewlines("plotid", plotid, 10); int slot[MAX_SLOT]= { 0 }; static instance_parameter *paraHead1 = NULL; list_instance_parameter(¶Head1, SNMPD_SLOT_CONNECT); if (NULL == paraHead1) { return 0; } if(strcmp(plotid, "") == 0) { p_id = paraHead1->parameter.slot_id; } else { p_id = atoi(plotid); } ccgi_ReInitDbusConnection(&fwrule_dbus_connection, p_id, DISTRIBUTFAG); ret = ac_manage_show_firewall_rule(fwrule_dbus_connection,NULL, NULL, &rule_array, &rule_num); fprintf(stderr,"ret:%d\n",ret); //ShowAlert(search(lpublic,"instance_not_exist")); //} fprintf(stderr,"rule_num:%d\n",rule_num); fprintf(stderr,"rule_num:%p\n",rule_array); if(0 == ret && rule_array && rule_num){ rule = rule_array; } cgiFormStringNoNewlines( "ruleType", ruleTypeStr, sizeof(ruleTypeStr) ); if( strcmp("FW_DNAT", ruleTypeStr) == 0 ) { ruleType = FW_DNAT; } else if( strcmp("FW_SNAT",ruleTypeStr) == 0) { ruleType = FW_SNAT; } // add by chensheng, on 2010-04-15, for input chain else if (strcmp("FW_INPUT", ruleTypeStr) == 0) { ruleType = FW_INPUT; } else { ruleType = FW_WALL; strcpy( ruleTypeStr, "FW_WALL" ); } fprintf( cgiOut, "<html xmlns=\"http://www.w3.org/1999/xhtml\"> \n" ); fprintf( cgiOut, "<head> \n" ); fprintf( cgiOut, "<meta http-equiv=Content-Type content=text/html; charset=gb2312> \n" ); //下面三句话用于禁止页面缓存 fprintf( cgiOut, "<META HTTP-EQUIV=\"pragma\" CONTENT=\"no-cache\"> \n"); fprintf( cgiOut, "<META HTTP-EQUIV=\"Cache-Control\" CONTENT=\"no-cache, must-revalidate\"> \n" ); fprintf( cgiOut, "<META HTTP-EQUIV=\"expires\" CONTENT=\"Wed, 26 Feb 1997 08:21:57 GMT\"> \n"); fprintf( cgiOut, "<title>%s</title> \n", search( lfirewall, "title_fw" ) ); fprintf( cgiOut, "<link rel=stylesheet href=/style.css type=text/css> \n" ); fprintf( cgiOut, "<style type=text/css> \n" ); fprintf( cgiOut, ".usrlis {overflow-x:hidden; overflow:auto; width: 416px; height: 270px; clip: rect( ); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px} \n" ); fprintf( cgiOut, "</style> \n" ); fprintf( cgiOut, "</head> \n" ); fprintf( cgiOut, "<script src=\"/fw.js\"></script> \n" ); fprintf( cgiOut, "<script type='text/javascript'>\n" ); fprintf( cgiOut, "function autoCheckHeight()\n" ); fprintf( cgiOut, "{\n");//-75是因为又加了连接左边的高度增加了 fprintf( cgiOut, " if( document.getElementById('list').offsetHeight > 150 )\n" ); fprintf( cgiOut, " document.getElementById('FILL_OBJ').style.height = document.getElementById('list').offsetHeight - 100;\n"); fprintf( cgiOut, " else\n"\ " document.getElementById('FILL_OBJ').style.height = 1;" ); fprintf( cgiOut, "}\n"); switch( ruleType ) { case FW_DNAT: case FW_SNAT: //添加snat //rule = list->snat; fprintf( cgiOut, "var fwrulesFW_SNAT = new Array(); \n" ); if( rule != NULL ) { // while( (void*)0 != rule ) for(i = 0;i<rule_num;i++) { // type id ordernum *name enable status *comment *ineth *outeth // srctype *srcadd dsttype *dstadd protocl sptype *sport dptype *dport // act natiptype *natipadd natpttype *natport if( rule[i].type == FW_SNAT ){ fprintf( cgiOut, "fwrulesFW_SNAT[%d] = new fwrule( \"%d\", \"%d\",\"%d\",", i, rule[i].type, rule[i].id, rule[i].ordernum ); fprintf( cgiOut, "\"%s\", \"%d\", \"%d\", \"%s\", \"%s\", \"%s\", ", rule[i].name, rule[i].enable, rule[i].status, rule[i].comment, rule[i].ineth, rule[i].outeth ); fprintf( cgiOut, "\"%d\", \"%s\", \"%d\", \"%s\", \"%d\", \"%d\",\"%s\", \"%d\", \"%s\", ", rule[i].srctype, rule[i].srcadd, rule[i].dsttype, rule[i].dstadd, rule[i].protocl, rule[i].sptype, rule[i].sport, rule[i].dptype, rule[i].dport ); fprintf( cgiOut, "\"%d\", \"%d\",\"%s\",\"%d\",\"%s\", '%s', '%s' );\n", rule[i].act, rule[i].natiptype, rule[i].natipadd, rule[i].natpttype, rule[i].natport, rule[i].pkg_state, rule[i].string_filter ); iSNATTotalNum++; } //fprintf( cgiOut, "alert(fwrulesFW_SNAT[%d]->type);\n", i ); //rule = rule->next; //i++; } } //rule = list->dnat; //rule = rule_array; i = 0; fprintf( cgiOut, "var fwrulesFW_DNAT = new Array(); \n" ); if( rule != NULL ) { // while( (void*)0 != rule ) for(i = 0;i<rule_num;i++) { // ddd sdd sss dsd sdd sds dds ds // type id ordernum *name enable status *comment *ineth *outeth // srctype *srcadd dsttype *dstadd protocl sptype *sport dptype *dport // act natiptype *natipadd natpttype *natport if(FW_DNAT == rule[i].type){ fprintf( cgiOut, "fwrulesFW_DNAT[%d] = new fwrule( \"%d\", \"%d\",\"%d\",", i, rule[i].type, rule[i].id, rule[i].ordernum ); fprintf( cgiOut, "\"%s\", \"%d\", \"%d\", \"%s\", \"%s\", \"%s\", ", rule[i].name, rule[i].enable, rule[i].status, rule[i].comment, rule[i].ineth, rule[i].outeth ); fprintf( cgiOut, "\"%d\", \"%s\", \"%d\", \"%s\", \"%d\", \"%d\",\"%s\", \"%d\", \"%s\", ", rule[i].srctype, rule[i].srcadd, rule[i].dsttype, rule[i].dstadd, rule[i].protocl, rule[i].sptype, rule[i].sport, rule[i].dptype, rule[i].dport ); fprintf( cgiOut, "\"%d\", \"%d\",\"%s\",\"%d\",\"%s\", '%s', '%s' );\n", rule[i].act, rule[i].natiptype, rule[i].natipadd, rule[i].natpttype, rule[i].natport, rule[i].pkg_state, rule[i].string_filter ); iDNATTotalNum ++; } //fprintf( cgiOut, "alert(fwrulesFW_DNAT[%d]->type);\n", i ); } } break; // add by chensheng, on 2010-04-15, for input chain case FW_INPUT: // rule = rule_array; fprintf( cgiOut, "var fwrulesFW_INPUT = new Array(); \n" ); if( rule != NULL ) { for(i = 0;i<rule_num;i++) { // type id ordernum *name enable status *comment *ineth *outeth // srctype *srcadd dsttype *dstadd protocl sptype *sport dptype *dport // act natiptype *natipadd natpttype *natport if(FW_INPUT == rule[i].type){ fprintf( cgiOut, "fwrulesFW_INPUT[%d] = new fwrule( \"%d\", \"%d\",\"%d\",", i, rule[i].type, rule[i].id, rule[i].ordernum ); fprintf( cgiOut, "\"%s\", \"%d\", \"%d\", \"%s\", \"%s\", \"%s\", ", rule[i].name, rule[i].enable, rule[i].status, rule[i].comment, rule[i].ineth, rule[i].outeth ); fprintf( cgiOut, "\"%d\", \"%s\", \"%d\", \"%s\", \"%d\", \"%d\",\"%s\", \"%d\", \"%s\", ", rule[i].srctype, rule[i].srcadd, rule[i].dsttype, rule[i].dstadd, rule[i].protocl, rule[i].sptype, rule[i].sport, rule[i].dptype, rule[i].dport ); fprintf( cgiOut, "\"%d\", \"%d\",\"%s\",\"%d\",\"%s\", '%s', '%s' );\n", rule[i].act, rule[i].natiptype, rule[i].natipadd, rule[i].natpttype, rule[i].natport, rule[i].pkg_state, rule[i].string_filter ); iInputTotalNum++; } //fprintf( cgiOut, "alert('%s');\n", rule->string_filter ); } } break; case FW_WALL: default: //rule = rule_array; fprintf( cgiOut, "var fwrulesFW_WALL = new Array(); \n" ); if( rule != NULL ) { for(i = 0;i<rule_num;i++) { // type id ordernum *name enable status *comment *ineth *outeth // srctype *srcadd dsttype *dstadd protocl sptype *sport dptype *dport // act natiptype *natipadd natpttype *natport if(FW_WALL==rule[i].type){ fprintf( cgiOut, "fwrulesFW_WALL[%d] = new fwrule( \"%d\", \"%d\",\"%d\",", i, rule[i].type, rule[i].id, rule[i].ordernum ); fprintf( cgiOut, "\"%s\", \"%d\", \"%d\", \"%s\", \"%s\", \"%s\", ", rule[i].name, rule[i].enable, rule[i].status, rule[i].comment, rule[i].ineth, rule[i].outeth ); fprintf( cgiOut, "\"%d\", \"%s\", \"%d\", \"%s\", \"%d\", \"%d\",\"%s\", \"%d\", \"%s\", ", rule[i].srctype, rule[i].srcadd, rule[i].dsttype, rule[i].dstadd, rule[i].protocl, rule[i].sptype, rule[i].sport, rule[i].dptype, rule[i].dport ); fprintf( cgiOut, "\"%d\", \"%d\",\"%s\",\"%d\",\"%s\", '%s', '%s' );\n", rule[i].act, rule[i].natiptype, rule[i].natipadd, rule[i].natpttype, rule[i].natport, rule[i].pkg_state, rule[i].string_filter ); iWallTotalNum++; } //fprintf( cgiOut, "alert('%s');\n", rule->string_filter ); } } break; } fprintf( cgiOut, "</script>"\ "<script src=/instanceid_onchange.js>"\ "</script>"\ "<body> \n" ); fprintf( cgiOut, "<form action='wp_fwrulemodify.cgi' method='post'> \n" ); fprintf( cgiOut, "<input type='hidden' name='UN' value='%s'>", encry ); fprintf( cgiOut, "<input type='hidden' name='ruleType' value='%s'>", ruleTypeStr ); fprintf( cgiOut, "<div align=center> \n" ); fprintf( cgiOut, "<table width=976 border=0 cellpadding=0 cellspacing=0> \n" ); fprintf( cgiOut, "<tr><td width=8 align=left valign=top background=/images/di22.jpg><img src=/images/youce4.jpg width=8 height=30/></td> \n" ); fprintf( cgiOut, "<td width=51 align=left valign=bottom background=/images/di22.jpg><img src=/images/youce33.jpg width=37 height=24/></td> \n" ); if( FW_WALL == ruleType ) { fprintf( cgiOut, "<td width=153 align=left valign=bottom id=%s background=/images/di22.jpg>%s </td> \n", search(lpublic,"title_style"), search( lfirewall, "title_fw_rule") ); } else if( FW_INPUT == ruleType ) { fprintf( cgiOut, "<td width=153 align=left valign=bottom id=%s background=/images/di22.jpg>%s </td> \n", search(lpublic,"title_style"), search( lfirewall, "title_input") ); } else { fprintf( cgiOut, "<td width=153 align=left valign=bottom id=%s background=/images/di22.jpg>%s </td> \n", search(lpublic,"title_style"), search( lfirewall, "title_nat") ); } fprintf( cgiOut, "<td width=690 align=right valign=bottom background=/images/di22.jpg> \n" ); fprintf(cgiOut,"<table width=130 border=0 cellspacing=0 cellpadding=0>"\ "<tr>\n" ); if( 0 == manager ) fprintf( cgiOut, "<td width=62 align=center><input id='but' type='submit' name='submit_doallrules' style='background-image:url(/images/%s)' value=''></td>\n", search(lpublic,"img_ok") ); else fprintf(cgiOut,"<td width=62 align=left><a href=wp_firewall.cgi?UN=%s target=mainFrame><img src=/images/%s border=0 width=62 height=20/></a></td>",encry,search(lpublic,"img_ok")); fprintf(cgiOut,"<td width=62 align=left><a href=wp_firewall.cgi?UN=%s target=mainFrame><img src=/images/%s border=0 width=62 height=20/></a></td>",encry,search(lpublic,"img_cancel")); fprintf(cgiOut,"</tr>"\ "</table>"); fprintf( cgiOut, "</td> \n" ); fprintf( cgiOut, "<td width=74 align=right valign=top background=/images/di22.jpg><img src=/images/youce3.jpg width=31 height=30/></td> \n" ); fprintf( cgiOut, "</tr> \n" ); fprintf( cgiOut, "<tr><td colspan=5 align=center valign=middle> \n" ); fprintf( cgiOut, "<table width=976 border=0 cellpadding=0 cellspacing=0 bgcolor=#f0eff0> \n" ); fprintf( cgiOut, "<tr><td width=12 align=left valign=top background=/images/di888.jpg> </td> \n" ); fprintf( cgiOut, "<td width=948> \n" ); fprintf( cgiOut, "<table width=947 border=0 cellspacing=0 cellpadding=0> \n" ); fprintf( cgiOut, "<tr height=4 valign=bottom><td width=120> </td> \n" ); fprintf( cgiOut, "<td width=827 valign=bottom><img src=/images/bottom_05.gif width=827 height=4/></td> \n" ); fprintf( cgiOut, "</tr> \n" ); fprintf( cgiOut, "<tr><td> \n" ); fprintf( cgiOut, "<table width=120 border=0 cellspacing=0 cellpadding=0> \n" ); fprintf( cgiOut, "<tr height=25><td id=tdleft> </td></tr> \n" ); //if( ruleType != FW_DNAT && ruleType != FW_SNAT ) if (FW_WALL == ruleType ) { fprintf( cgiOut, "<tr height=26><td align=left id=tdleft background=/images/bottom_bg.gif style=\"border-right:0\"><font id=%s>%s</font></td></tr> \n", search(lpublic,"menu_san"), search( lfirewall, "title_fw_rule") ); fprintf( cgiOut, "<tr height=25><td align=left id=tdleft><a href='wp_fwruleview.cgi?UN=%s&ruleType=FW_SNAT' target=mainFrame class=top><font id=%s>%s</font></a></td></tr> \n", encry, search(lpublic,"menu_san"), search( lfirewall, "title_nat") ); fprintf( cgiOut, "<tr height=25><td align=left id=tdleft><a href='wp_fwruleview.cgi?UN=%s&ruleType=FW_INPUT' target=mainFrame class=top><font id=%s>%s</font></a></td></tr> \n", encry, search(lpublic,"menu_san"), search( lfirewall, "title_input") ); } else if (FW_SNAT == ruleType || FW_DNAT == ruleType) { fprintf( cgiOut, "<tr height=25><td align=left id=tdleft><a href='wp_fwruleview.cgi?UN=%s&ruleType=FW_WALL' target=mainFrame class=top><font id=%s>%s</font></a></td></tr> \n",encry, search(lpublic,"menu_san"), search( lfirewall, "title_fw_rule") ); fprintf( cgiOut, "<tr height=26><td align=left id=tdleft background=/images/bottom_bg.gif style=\"border-right:0\"><font id=%s>%s</font></td></tr> \n", search(lpublic,"menu_san"), search( lfirewall, "title_nat") ); fprintf( cgiOut, "<tr height=25><td align=left id=tdleft><a href='wp_fwruleview.cgi?UN=%s&ruleType=FW_INPUT' target=mainFrame class=top><font id=%s>%s</font></a></td></tr> \n",encry, search(lpublic,"menu_san"), search( lfirewall, "title_input") ); } else { fprintf( cgiOut, "<tr height=25><td align=left id=tdleft><a href='wp_fwruleview.cgi?UN=%s&ruleType=FW_WALL' target=mainFrame class=top><font id=%s>%s</font></a></td></tr> \n",encry, search(lpublic,"menu_san"), search( lfirewall, "title_fw_rule") ); fprintf( cgiOut, "<tr height=25><td align=left id=tdleft><a href='wp_fwruleview.cgi?UN=%s&ruleType=FW_SNAT' target=mainFrame class=top><font id=%s>%s</font></a></td></tr> \n",encry, search(lpublic,"menu_san"), search( lfirewall, "title_nat") ); fprintf( cgiOut, "<tr height=26><td align=left id=tdleft background=/images/bottom_bg.gif style=\"border-right:0\"><font id=%s>%s</font></td></tr> \n", search(lpublic,"menu_san"), search( lfirewall, "title_input") ); } //添加各种规则的入口 if( 0 == manager ) { fprintf( cgiOut, "<tr height=25><td align=left id=tdleft><a href='wp_fwruleedit.cgi?UN=%s&ruleID=%d&ruleNum=%d&ruleType=FW_WALL&editType=add' target=mainFrame class=top><font id=%s>%s</font><font id=%s>%s</font><font id=%s>%s</font></a></td></tr> \n",encry,iWallTotalNum+1, iWallTotalNum, search(lpublic,"menu_san"), search( lfirewall, "add_new"),search(lpublic,"menu_san"), search( lfirewall, "title_fw"),search(lpublic,"menu_san"), search( lfirewall, "add_rule") ); fprintf( cgiOut, "<tr height=25><td align=left id=tdleft><a href='wp_fwruleedit.cgi?UN=%s&ruleID=%d&ruleNum=%d&ruleType=FW_SNAT&editType=add' target=mainFrame class=top><font id=%s>%s</font><font id=%s>%s</font><font id=%s>%s</font></a></td></tr> \n",encry,iSNATTotalNum+1, iSNATTotalNum, search(lpublic,"menu_san"), search( lfirewall, "add_new"),search(lpublic,"menu_san"), "SNAT ",search(lpublic,"menu_san"), search( lfirewall, "add_rule") ); fprintf( cgiOut, "<tr height=25><td align=left id=tdleft><a href='wp_fwruleedit.cgi?UN=%s&ruleID=%d&ruleNum=%d&ruleType=FW_DNAT&editType=add' target=mainFrame class=top><font id=%s>%s</font><font id=%s>%s</font><font id=%s>%s</font></a></td></tr> \n",encry,iDNATTotalNum+1, iDNATTotalNum, search(lpublic,"menu_san"), search( lfirewall, "add_new"),search(lpublic,"menu_san"), "DNAT ",search(lpublic,"menu_san"), search( lfirewall, "add_rule") ); fprintf( cgiOut, "<tr height=25><td align=left id=tdleft><a href='wp_fwruleedit.cgi?UN=%s&ruleID=%d&ruleNum=%d&ruleType=FW_INPUT&editType=add' target=mainFrame class=top><font id=%s>%s</font><font id=%s>%s</font><font id=%s>%s</font></a></td></tr> \n",encry,iInputTotalNum+1,iInputTotalNum, search(lpublic,"menu_san"), search( lfirewall, "add_new"),search(lpublic,"menu_san"), "INPUT ",search(lpublic,"menu_san"), search( lfirewall, "add_rule") ); } else { fprintf( cgiOut, "<tr height=25><td align=left id=tdleft> </td></tr><tr height=25><td align=left id=tdleft> </td></tr><tr height=25><td align=left id=tdleft> </td></tr>\n" ); } /* fprintf( cgiOut, "<tr height=25><td align=left id=tdleft><a href='wp_fwruleview.cgi?UN=%s&ruleType=FW_WALL' target=mainFrame class=top><font id=%s>%s</font></a></td></tr> \n",encry, search(lpublic,"menu_san"), search( lfirewall, "title_fw_rule") ); fprintf( cgiOut, "<tr height=25><td align=left id=tdleft><a href='wp_fwruleview.cgi?UN=%s&ruleType=FW_WALL' target=mainFrame class=top><font id=%s>%s</font></a></td></tr> \n",encry, search(lpublic,"menu_san"), search( lfirewall, "title_fw_rule") ); */ //三种规则入口结束 fprintf( cgiOut, "<tr><td align=left id='FILL_OBJ' style='height:100px;padding-left:10px;border-right:1px solid #707070;color:#000000;text-align:center'> </td></tr> \n" ); fprintf( cgiOut, "</table> \n" ); fprintf( cgiOut, "</td> \n" ); fprintf( cgiOut, "<td align=left style=\"background-color:#ffffff; border-right:1px solid #707070; padding-left:30px\">"\ "<div id=\"list\" align=\"left\" style=\"width:768px;overflow:auto\">\n"); //输出表格。 //当前类型 { char str_RULEPOSTION_SELECTOR[512]; char str_POP_MENU[512]; char popMenuName[32]; char str_url_del[128]; char str_url_edit[128]; instance_parameter *p_q = NULL; fprintf( cgiOut, "<span>%s<select name=plotid id=plotid style=width:72px onchange=plotid_change(this)></span><hr color=#163871 />\n",search(lfirewall,"slot_num")); for(p_q=paraHead1;(NULL != p_q);p_q=p_q->next) { if(p_q->parameter.slot_id == p_id) { fprintf(cgiOut,"<option value=\"%d\" selected>%d</option>",p_q->parameter.slot_id,p_q->parameter.slot_id); } else { fprintf(cgiOut,"<option value=\"%d\">%d</option>",p_q->parameter.slot_id,p_q->parameter.slot_id); } } fprintf(cgiOut, "<script type=text/javascript>\n"); fprintf(cgiOut, "function plotid_change( obj )\n"\ "{\n"\ "var plotid = obj.options[obj.selectedIndex].value;\n"\ "var url = 'wp_fwruleview.cgi?UN=%s&ruleType=%s&plotid='+plotid;\n"\ "window.location.href = url;\n"\ "}\n", encry, ruleTypeStr); fprintf(cgiOut,"</script>\n"); fprintf(cgiOut,"</select>\n"); if( FW_WALL == ruleType ) { //启动关闭防火墙的按钮~~~ if( 0 == manager ) { if( 0 == fwServiceStatus() )//running { fprintf( cgiOut, "<span>%s:%s ! <a href='wp_fwrulemodify.cgi?UN=%s&doFireWall=stop'><font color=blue>%s</font></a></span><hr color=#163871 />\n", search(lfirewall,"rule_fwstate"),search(lfirewall,"rule_fwstate_running"), encry,search(lfirewall,"rule_fw_stop") ); } else { fprintf( cgiOut, "<span>%s:%s ! <a href='wp_fwrulemodify.cgi?UN=%s&doFireWall=start'><font color=blue>%s</font></a></span><hr color=#163871 />\n", search(lfirewall,"rule_fwstate"),search(lfirewall,"rule_fwstate_stoped"), encry,search(lfirewall,"rule_fw_start") ); } } //firewall //表头 fprintf( cgiOut, TABLE_HEAD, search(lpublic,"menu_thead"), search( lfirewall, "rule_position" ), search(lpublic,"menu_thead"), search( lfirewall, "rule_name_detail" ), search(lpublic,"menu_thead"), search( lfirewall, "rule_action" ), search(lpublic,"menu_thead"), search( lfirewall, "rule_state" ) ); //内容 if( 0 == iWallTotalNum ) { if(0 == manager) fprintf( cgiOut, "<tr><td colspan=6><div>%s <a href='wp_fwruleedit.cgi?UN=%s&ruleID=0&ruleNum=0&ruleType=FW_WALL&editType=add' target=mainFrame class=top><i>%s</i></a> %s </td></tr>\n", search(lfirewall,"rule_no_pre"), encry, search(lfirewall,"rule_no_here"), search(lfirewall,"rule_no_post") ); } else { // rule = rule_array; int i =0; for(i = 0;i<rule_num;i++) { if(rule[i].type==FW_WALL){ sprintf( str_RULEPOSTION_SELECTOR, RULEPOSTION_SELECTOR, iWallTotalNum, i+1, ruleTypeStr, encry ); sprintf( popMenuName,"popMenuName%s%d",ruleTypeStr,i); sprintf( str_url_edit, "wp_fwruleedit.cgi?UN=%s&plotid=%d&ruleID=%d&ruleNum=%d&ruleType=%s&editType=edit", encry, p_id, rule[i].id,iWallTotalNum,ruleTypeStr ); sprintf( str_url_del, "wp_fwrulemodify.cgi?UN=%s&plotid=%d&delRuleIndex=%d&ruleNum=%d&ruleType=%s", encry, p_id, rule[i].id,iWallTotalNum,ruleTypeStr ); sprintf( str_POP_MENU, POP_MENU, popMenuName,popMenuName,iWallTotalNum-i, popMenuName,search( lfirewall, "rule_edit" ),str_url_edit , popMenuName,search( lfirewall, "rule_delete" ),str_url_del, popMenuName ); char *action=NULL; switch( rule[i].act ) { case FW_ACCEPT: action = search(lfirewall,"rule_action_allow"); break; case FW_DROP: action = search(lfirewall,"rule_action_deny"); break; case FW_REJECT: action = search(lfirewall,"rule_action_reject"); break; case FW_TCPMSS: action = "TCPMSS"; break; default: break; } fprintf( cgiOut, TABLE_LINE, setclour((rule[i].id)%2)/*class*/, ruleTypeStr/*ruletype*/,i,ruleTypeStr/*ruletype*/,i, int2str(rule[i].id),/*pos*/ "......", action, (rule[i].enable)?search(lfirewall,"rule_enabled"):search(lfirewall,"rule_disabled"), (0 == manager)?str_POP_MENU:"", ruleTypeStr,i); } } //加入一个空行,解决popmenu显示不下的问题。 //fprintf( cgiOut, "<tr height=25><td colspan=7 /></tr>\n"); } //结束 fprintf( cgiOut, "</table>\n" ); //加一行,否则弹出popmenu时会显示滚动条 fprintf( cgiOut, "<table ><tr height=25><td></td></tr></table>\n"); } else if (FW_SNAT == ruleType || FW_DNAT == ruleType) { //nat // snat //表头 strcpy( ruleTypeStr, "FW_SNAT" ); fprintf( cgiOut, "<b>%s:</b><hr color=#163871 />", search( lfirewall, "ruleedit_trans_source_addr" ) ); // fprintf( cgiOut, TABLE_HEAD, search( lfirewall, "rule_position" ), search( lfirewall, "rule_name_detail" ), search( lfirewall, "rule_action" ), search( lfirewall, "rule_state" ) ); fprintf( cgiOut, TABLE_HEAD, search(lpublic,"menu_thead"), search( lfirewall, "rule_position" ), search(lpublic,"menu_thead"), search( lfirewall, "rule_name_detail" ), search(lpublic,"menu_thead"), "", search(lpublic,"menu_thead"), search( lfirewall, "rule_state" ) ); //内容 if( 0 == iSNATTotalNum ) { if(0 == manager) fprintf( cgiOut, "<tr><td colspan=6><div>%s <a href='wp_fwruleedit.cgi?UN=%s&ruleID=0&ruleNum=0&ruleType=FW_SNAT&editType=add' target=mainFrame class=top><i>%s</i></a> %s </td></tr>\n", search(lfirewall,"rule_no_pre"), encry, search(lfirewall,"rule_no_here"), search(lfirewall,"rule_no_post") ); } else { //rule = rule_array; i = 0; for(i = 0;i<rule_num;i++) { if(rule[i].type==FW_SNAT){ sprintf( str_RULEPOSTION_SELECTOR, RULEPOSTION_SELECTOR, iSNATTotalNum, i+1, ruleTypeStr, encry ); sprintf( popMenuName,"popMenuName%s%d",ruleTypeStr,i); sprintf( str_url_edit, "wp_fwruleedit.cgi?UN=%s&plotid=%d&ruleID=%d&ruleNum=%d&ruleType=%s&editType=edit", encry, p_id, rule[i].id,iWallTotalNum,ruleTypeStr ); sprintf( str_url_del, "wp_fwrulemodify.cgi?UN=%s&plotid=%d&delRuleIndex=%d&ruleNum=%d&ruleType=%s", encry, p_id, rule[i].id,iWallTotalNum,ruleTypeStr ); sprintf( str_POP_MENU, POP_MENU, popMenuName,popMenuName,iSNATTotalNum-i, popMenuName,search( lfirewall, "rule_edit" ),str_url_edit , popMenuName,search( lfirewall, "rule_delete" ),str_url_del, popMenuName ); fprintf( cgiOut, TABLE_LINE, setclour((rule[i].id)%2)/*class*/, ruleTypeStr/*ruletype*/,i,ruleTypeStr/*ruletype*/,i, int2str(rule[i].id),/*pos*/ "......", "", (rule[i].enable)?search(lfirewall,"rule_enabled"):search(lfirewall,"rule_disabled"), (0 == manager)?str_POP_MENU:"", ruleTypeStr,i); } } } //结束 fprintf( cgiOut, "</table>\n" ); //加一行,否则弹出popmenu时会显示滚动条 fprintf( cgiOut, "<table ><tr height=25><td></td></tr></table>\n"); // dnat //表头 strcpy( ruleTypeStr, "FW_DNAT" ); fprintf( cgiOut, "<br /><b>%s:</b><hr color=#163871 />", search( lfirewall, "ruleedit_trans_dest_addr" ) ); fprintf( cgiOut, TABLE_HEAD, search(lpublic,"menu_thead"), search( lfirewall, "rule_position" ), search(lpublic,"menu_thead"), search( lfirewall, "rule_name_detail" ), search(lpublic,"menu_thead"), "", search(lpublic,"menu_thead"), search( lfirewall, "rule_state" ) ); //内容 if( 0 == iDNATTotalNum ) { if(0 == manager) fprintf( cgiOut, "<tr><td colspan=6><div>%s <a href='wp_fwruleedit.cgi?UN=%s&ruleID=0&ruleNum=0&ruleType=FW_DNAT&editType=add' target=mainFrame class=top><i>%s</i></a> %s </td></tr>\n", search(lfirewall,"rule_no_pre"), encry, search(lfirewall,"rule_no_here"), search(lfirewall,"rule_no_post") ); } else { // rule = rule_array; i = 0; for(i = 0;i<rule_num;i++) { if(rule[i].type == FW_DNAT){ sprintf( str_RULEPOSTION_SELECTOR, RULEPOSTION_SELECTOR, iDNATTotalNum, i+1, ruleTypeStr, encry ); sprintf( popMenuName,"popMenuName%s%d",ruleTypeStr,i); sprintf( str_url_edit, "wp_fwruleedit.cgi?UN=%s&ruleID=%d&ruleNum=%d&ruleType=%s&editType=edit", encry,i+1,iDNATTotalNum,ruleTypeStr ); sprintf( str_url_del, "wp_fwrulemodify.cgi?UN=%s&delRuleIndex=%d&ruleNum=%d&ruleType=%s", encry,i+1,iDNATTotalNum,ruleTypeStr ); sprintf( str_POP_MENU, POP_MENU, popMenuName,popMenuName,iDNATTotalNum-i, popMenuName,search( lfirewall, "rule_edit" ),str_url_edit , popMenuName,search( lfirewall, "rule_delete" ),str_url_del, popMenuName ); fprintf( cgiOut, TABLE_LINE, setclour((rule[i].id)%2)/*class*/, ruleTypeStr/*ruletype*/,i,ruleTypeStr/*ruletype*/,i, int2str(rule[i].id),/*pos*/ "......", "", (rule[i].enable)?search(lfirewall,"rule_enabled"):search(lfirewall,"rule_disabled"), (0 == manager)?str_POP_MENU:"", ruleTypeStr,i); } } } //结束 fprintf( cgiOut, "</table>\n" ); //加一行,否则弹出popmenu时会显示滚动条 fprintf( cgiOut, "<table ><tr height=25><td></td></tr></table>\n"); //对于nat,添加一个需要开启防火墙的提示 if( FW_WALL != ruleType ) { fprintf(cgiOut,"<table width=766px>\n" ); fprintf(cgiOut,"<tr>"\ "<td id=sec1 style=\"border-bottom:2px solid #53868b;font-size:14px\">%s</td>",search(lpublic,"description")); fprintf(cgiOut,"</tr>"); fprintf(cgiOut,"<tr height=25 style=padding-top:2px>"\ "<td style=font-size:14px;color:#FF0000>%s</td>"\ "</tr>",search(lfirewall,"nat_need")); fprintf(cgiOut,"</table>" ); } } else { //firewall //表头 fprintf( cgiOut, "<br /><b>%s:</b><hr color=#163871 />", search( lfirewall, "rule_input_description" ) ); fprintf( cgiOut, TABLE_HEAD, search(lpublic,"menu_thead"), search( lfirewall, "rule_position" ), search(lpublic,"menu_thead"), search( lfirewall, "rule_name_detail" ), search(lpublic,"menu_thead"), search( lfirewall, "rule_action" ), search(lpublic,"menu_thead"), search( lfirewall, "rule_state" ) ); //内容 if( 0 == iInputTotalNum) { if(0 == manager) fprintf( cgiOut, "<tr><td colspan=6><div>%s <a href='wp_fwruleedit.cgi?UN=%s&ruleID=0&ruleNum=0&ruleType=FW_INPUT&editType=add' target=mainFrame class=top><i>%s</i></a> %s </td></tr>\n", search(lfirewall,"rule_no_pre"), encry, search(lfirewall,"rule_no_here"), search(lfirewall,"rule_no_post") ); } else { //rule = rule_array; i = 0; for(i = 0;i<rule_num;i++) { if(rule[i].type == FW_INPUT){ sprintf( str_RULEPOSTION_SELECTOR, RULEPOSTION_SELECTOR, iInputTotalNum, i+1, ruleTypeStr, encry ); sprintf( popMenuName,"popMenuName%s%d",ruleTypeStr,i); sprintf( str_url_edit, "wp_fwruleedit.cgi?UN=%s&plotid=%d&ruleID=%d&ruleNum=%d&ruleType=%s&editType=edit", encry, p_id, rule[i].id,iWallTotalNum,ruleTypeStr ); sprintf( str_url_del, "wp_fwrulemodify.cgi?UN=%s&plotid=%d&delRuleIndex=%d&ruleNum=%d&ruleType=%s", encry, p_id, rule[i].id,iWallTotalNum,ruleTypeStr ); sprintf( str_POP_MENU, POP_MENU, popMenuName,popMenuName,iInputTotalNum-i, popMenuName,search( lfirewall, "rule_edit" ),str_url_edit , popMenuName,search( lfirewall, "rule_delete" ),str_url_del, popMenuName ); char *action=NULL; switch( rule[i].act ) { case FW_ACCEPT: action = search(lfirewall,"rule_action_allow"); break; case FW_DROP: action = search(lfirewall,"rule_action_deny"); break; case FW_REJECT: action = search(lfirewall,"rule_action_reject"); break; //case FW_TCPMSS: // action = "TCPMSS"; // break; default: break; } fprintf( cgiOut, TABLE_LINE, setclour((rule[i].id)%2)/*class*/, ruleTypeStr/*ruletype*/,i,ruleTypeStr/*ruletype*/,i, int2str(rule[i].id),/*pos*/ "......", action, (rule[i].enable)?search(lfirewall,"rule_enabled"):search(lfirewall,"rule_disabled"), (0 == manager)?str_POP_MENU:"", ruleTypeStr,i); } } //加入一个空行,解决popmenu显示不下的问题。 //fprintf( cgiOut, "<tr height=25><td colspan=7 /></tr>\n"); } //结束 fprintf( cgiOut, "</table>\n" ); //加一行,否则弹出popmenu时会显示滚动条 fprintf( cgiOut, "<table ><tr height=25><td></td></tr></table>\n"); //对于nat,添加一个需要开启防火墙的提示 if( FW_WALL != ruleType ) { fprintf(cgiOut,"<table width=766px>\n" ); fprintf(cgiOut,"<tr>"\ "<td id=sec1 style=\"border-bottom:2px solid #53868b;font-size:14px\">%s</td>",search(lpublic,"description")); fprintf(cgiOut,"</tr>"); fprintf(cgiOut,"<tr height=25 style=padding-top:2px>"\ "<td style=font-size:14px;color:#FF0000>%s</td>"\ "</tr>",search(lfirewall,"input_need")); fprintf(cgiOut,"</table>" ); } } }//表格输出完成 fprintf( cgiOut, "</div></td> \n" ); fprintf( cgiOut, "</tr> \n" ); fprintf( cgiOut, "<tr height=4 valign=top><td width=120 height=4 align=right valign=top><img src=/images/bottom_07.gif width=1 height=10/></td> \n" ); fprintf( cgiOut, "<td width=827 height=4 valign=top bgcolor=#FFFFFF><img src=/images/bottom_06.gif width=827 height=15/></td> \n" ); fprintf( cgiOut, "</tr> \n" ); fprintf( cgiOut, "</table> \n" ); fprintf( cgiOut, "</td> \n" ); fprintf( cgiOut, "<td width=15 background=/images/di999.jpg> </td> \n" ); fprintf( cgiOut, "</tr> \n" ); fprintf( cgiOut, "</table> \n" ); fprintf( cgiOut, "</td> \n" ); fprintf( cgiOut, "</tr> \n" ); fprintf( cgiOut, "<tr><td colspan=3 align=left valign=top background=/images/di777.jpg><img src=/images/di555.jpg width=61 height=62/></td> \n" ); fprintf( cgiOut, "<td align=left valign=top background=/images/di777.jpg> </td> \n" ); fprintf( cgiOut, "<td align=left valign=top background=/images/di777.jpg><img src=/images/di666.jpg width=74 height=62/></td> \n" ); fprintf( cgiOut, "</tr> \n" ); fprintf( cgiOut, "</table> \n" ); fprintf( cgiOut, "</div> \n" ); fprintf( cgiOut, "</form> \n" ); fprintf( cgiOut, "</body> \n" ); fprintf( cgiOut, "<script type=\"text/javascript\"> \n" ); fprintf( cgiOut, "autoCheckHeight();\n" ); fprintf( cgiOut, "</script> \n" ); fprintf( cgiOut, " \n" ); fprintf( cgiOut, "</html> \n" ); //FreeList(list); free(encry); release(lpublic); release(lfirewall); free_instance_parameter_list(¶Head1); //endif return 0; }
int exec_avp(struct sip_msg *msg, char *cmd, pvname_list_p avpl) { int_str avp_val; int_str avp_name; unsigned short avp_type; FILE *pipe; int ret; char res_line[MAX_URI_SIZE+1]; str res; int exit_status; int i; pvname_list_t* crt; pid_t pid; /* pessimist: assume error by default */ ret=-1; pid = __popen3(cmd, NULL, &pipe, NULL); if (pid < 0) { LM_ERR("failed to run command: %s\n", cmd); ser_error=E_EXEC; return ret; } LM_DBG("Forked pid %d\n", pid); schedule_to_kill(pid); wait(&exit_status); /* read now line by line */ i=0; crt = avpl; while (fgets(res_line, MAX_URI_SIZE, pipe)) { res.s = res_line; res.len=strlen(res.s); trim_trailing(&res); /* skip empty line */ if (res.len==0) continue; /* ZT */ res.s[res.len]=0; avp_type = 0; if(crt==NULL) { avp_name.s.s = int2str(i + 1, &avp_name.s.len); if (!avp_name.s.s) { LM_ERR("cannot convert %d to string\n", i + 1); goto error; } avp_name.n = get_avp_id(&avp_name.s); if (avp_name.n < 0) { LM_ERR("cannot get avp id\n"); goto error; } } else { if(pv_get_avp_name(msg, &(crt->sname.pvp), &avp_name.n, &avp_type)!=0) { LM_ERR("can't get item name [%d]\n",i); goto error; } } avp_type |= AVP_VAL_STR; avp_val.s = res; if(add_avp(avp_type, avp_name.n, avp_val)!=0) { LM_ERR("unable to add avp\n"); goto error; } if(crt) crt = crt->next; i++; } if (i==0) LM_DBG("no result from %s\n", cmd); /* success */ ret=1; error: if (ferror(pipe)) { LM_ERR("pipe: %d/%s\n", errno, strerror(errno)); ser_error=E_EXEC; ret=-1; } pclose(pipe); if (WIFEXITED(exit_status)) { /* exited properly .... */ /* return false if script exited with non-zero status */ if (WEXITSTATUS(exit_status)!=0) ret=-1; } else { /* exited erroneously */ LM_ERR("cmd %s failed. exit_status=%d, errno=%d: %s\n", cmd, exit_status, errno, strerror(errno) ); ret=-1; } return ret; }
int initialize(int argc, char *argv[]) { tv.tv_sec = 2; tv.tv_usec = 500000; FD_ZERO(&list); // clear list FD_ZERO(&list_copy); // clear temporary sets FD_SET(STDIN, &list); // Add stdin fdmax = STDIN; // The biggest file descriptor yes = 1; ofnum = 0;//number of open files fdnum = 0;//number of file descriptors int cI; for(cI=0;cI<CLIENT_CACHE_LINES;cI++) { metacache[cI][0] = 0;//free metacache[cI][1] = -1;//TAG metacache[cI][2] = 0;//LRU metacache[cI][3] = -1;//OFi } srand (time(NULL));//randomize rand function int2str(rand() % (65536 - 1025) + 1025, myPORT, 10);//get a random port number for my pfs client memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; getownip(myIP); //inet_ntop(remoteaddr.ss_family, get_address((struct sockaddr*)&remoteaddr), myIP, INET6_ADDRSTRLEN); printf("My IP address and Port number are %s %s\n",myIP,myPORT); if(argc!=4){ fprintf(stderr,"Usage: pfs filename mmip mmport\n"); strcpy(mmIP, MMIP); strcpy(mmPORT, MMPORT); //exit(1); } else { strcpy(mmIP, argv[2]); strcpy(mmPORT, argv[3]); } //MM's IP&PORT mmFD = Connect2Server(mmIP, mmPORT);//Connect to Meta-data Manager (MM) FD_SET(mmFD, &list);//add to fd list fdmax = mmFD; // The biggest file descriptor char rpacket[BUFFER_SIZE] = ""; //Buffer for client data int size = MMR(rpacket, BUFFER_SIZE);//IMPORT 4 127.0.0.1 10001 127.0.0.1 10002 127.0.0.1 10003 127.0.0.1 10004 END. int fsnumI = findspace(rpacket,0,1);//File server number Index char packettype[6]; strncpy(packettype, rpacket, fsnumI-1); packettype[fsnum-1] = '\0'; if(!strcmp(packettype, "IMPORT")) { int firstI = findspace(rpacket,fsnumI,1);//First file server Index int nextI;// = findspace(packet,ffsI,1); //Next file server Index fsnum = str2int(rpacket+fsnumI,firstI-fsnumI-1);//number of file servers int i; for(i=0;i<fsnum;i++) { nextI = findspace(rpacket,firstI,1);//Port index strncpy(fs[i].ip, rpacket + firstI, nextI - firstI - 1); fs[i].ip[nextI - firstI - 1] = '\0'; firstI = findspace(rpacket,nextI,1);//IP index of next file server strncpy(fs[i].port, rpacket + nextI, firstI - nextI - 1); fs[i].port[firstI - nextI - 1] = '\0'; } for(i=0;i<fsnum;i++) { fs[i].fd = Connect2Server(fs[i].ip, fs[i].port);//Connect to FS FD_SET(fs[i].fd, &list);//add to fd list fdmax = fs[i].fd; // The biggest file descriptor size = recv(fs[i].fd, rpacket, sizeof(rpacket), 0); if (size == -1) perror("Error in receiving!"); rpacket[size] = '\0'; printf("Server: %s\n",rpacket);//IMPORT 4 127.0.0.1 10001 127.0.0.1 10002 127.0.0.1 10003 127.0.0.1 10004 END. } } else printf("No File Servers Imported!"); pthread_t harvesterThr, flusherThr; //Buffer Management Threads pthread_create(&harvesterThr, NULL, (void *) harvester, NULL); //??? debug it! pthread_create(&flusherThr, NULL, (void *) flusher, NULL); //pthread_join(harvesterThr, NULL);//every x-sec??? or when falls under threshold!??? //pthread_join(flusherThr, NULL);//every 30 seconds??? return 0; }
ssize_t pfs_write(int filedes, const void *buf, size_t nbyte, off_t offset, int *cache_hit) {//WRITE filename w offset length END. int ofI = 0; while((ofI < ofnum)&&(openfiles[ofI]->fd != filedes)) ofI++; if(ofI == ofnum) return -1; OpenFile* of = openfiles[ofI]; //save2cache(filedes,os,plen); char spacket[BUFFER_SIZE]; //Buffer for client data char Offset[7]; char Length[7]; strcpy(spacket,"WRITE "); strcat(spacket, of->filename); strcat(spacket, " "); strcat(spacket, of->mode); strcat(spacket, " "); int2str(offset/ONEKB,Offset,10); int2str(nbyte/ONEKB,Length,10); strcat(spacket, Offset); strcat(spacket, " "); strcat(spacket, Length); strcat(spacket," END."); if (send(mmFD, spacket, sizeof(spacket), 0) == -1) //OPEN pfs_file1 w Offset Length END. perror("Error in sending!"); char rpacket[BUFFER_SIZE] = ""; //Buffer for client data //int size = MMR(rpacket, BUFFER_SIZE);//WRITE filename fsoff sw offset length END. //int fnI = findspace(rpacket, 0, 1); //project2_2 //int osI = findspace(rpacket, fnI, 1); //0 //int swI = findspace(rpacket, osI, 1); //4 //int sI = findspace(rpacket, swI, 1); //0 //int lI = findspace(rpacket, sI, 1); //0 //int endI = findspace(rpacket, lI, 1); //w //offset ... nbyte //start = fsoffset + offset/(size*ONEKB), offset -> fsoffset + (offset+length)/(size*ONEKB) //first: offset % (size*ONEKB) -> min(offset+length, size*ONEKB) //intermediates: //last: 0 -> (offset+length)%(size*ONEKB) unsigned fsstart, from, to, plen; unsigned os = offset; unsigned len = nbyte; int i; for(i= of->fsoffset + (offset/(STRIP_SIZE*ONEKB)); (i-of->fsoffset)*(STRIP_SIZE*ONEKB) < (offset+nbyte); i++) {//Send for each FSs -> WRITE pfs_file1 from to(plen) END. //if (!fork()) //{ // this is the child process // close(myTFD); // child doesn't need the listener strcpy(spacket,"WRITE "); strcat(spacket, of->filename); strcat(spacket, " "); //0 ,1 ,2 ,3 + 4 ,5 ,6 ,7 + 8 ,9 ,10,11 //12,13,14,15 + 16,17,18,19 + 20,21,22,23 //24,25,26,27 + 28,29,30,31 + 32,33,34,35 //os=19->32 -> l=13, i=4, sw=3, fsstart = (i/of->stripe_width)*(STRIP_SIZE*ONEKB); from = fsstart + os%(STRIP_SIZE*ONEKB); to = fsstart + min(os%(STRIP_SIZE*ONEKB)+len, STRIP_SIZE*ONEKB); plen = to - from; char From[10]; char PLen[10]; int2str(from, From, 10); int2str(plen, PLen, 10); strcat(spacket, From); strcat(spacket, " "); strcat(spacket, PLen); strcat(spacket, " END.\n"); strncat(spacket, buf+os-offset, plen); if (send(fs[i%of->stripe_width].fd, spacket, sizeof(spacket), 0) == -1) perror("Error in sending!");//WRITE pfs_file1 from to(plen) END. //if (send(fs[i%of->stripe_width].fd, buf+os-offset, plen, 0) == -1) // perror("Error in sending!"); //int size; //char* rpacket = malloc(sizeof(plen)); //Buffer for client data //if ((size = recv(fs[i%of->stripe_width].fd, rpacket, sizeof(rpacket), 0)) == -1) //Wait for response -> WRITE project2_2 0 4 0 0 w END. -> 0 1 2 3 // perror("Error in receiving!"); //rpacket[size] = '\0'; //printf("Server: %s\n",rpacket); //strncpy(buf, rpacket, sizeof(rpacket)); //free(rpacket); save2cache(filedes,os,plen); os += plen; len -= plen; } strcpy(spacket,"RELEASE "); strcat(spacket, of->filename); strcat(spacket, " "); int2str(offset/ONEKB,Offset,10); int2str(nbyte/ONEKB,Length,10); strcat(spacket, Offset); strcat(spacket, " "); strcat(spacket, Length); strcat(spacket," END."); if (send(mmFD, spacket, sizeof(spacket), 0) == -1) //RELEASE pfs_file1 Offset Length END. perror("Error in sending!"); return nbyte; }
/** Tries to register the local game server on the master server. */ static INT32 AddToMasterServer(boolean firstadd) { #ifdef NONET (void)firstadd; #else static INT32 retry = 0; int i, res; socklen_t j; msg_t msg; msg_server_t *info = (msg_server_t *)msg.buffer; INT32 room = -1; fd_set tset; time_t timestamp = time(NULL); UINT32 signature, tmp; const char *insname; M_Memcpy(&tset, &wset, sizeof (tset)); res = select(255, NULL, &tset, NULL, &select_timeout); if (res != ERRSOCKET && !res) { if (retry++ > 30) // an about 30 second timeout { retry = 0; CONS_Printf("Timeout on masterserver\n"); MSLastPing = timestamp; return ConnectionFailed(); } return MS_CONNECT_ERROR; } retry = 0; if (res == ERRSOCKET) { if (MS_Connect(GetMasterServerIP(), GetMasterServerPort(), 0)) { CONS_Printf("Mastserver error on select #%u: %s\n", errno, strerror(errno)); MSLastPing = timestamp; return ConnectionFailed(); } } // so, the socket is writable, but what does that mean, that the connection is // ok, or bad... let see that! j = (socklen_t)sizeof (i); getsockopt(socket_fd, SOL_SOCKET, SO_ERROR, (char *)&i, &j); if (i) // it was bad { CONS_Printf("Masterserver getsockopt error #%u: %s\n", errno, strerror(errno)); MSLastPing = timestamp; return ConnectionFailed(); } if (dedicated && (M_CheckParm("-room") && M_IsNextParm())) { room = atoi(M_GetNextParm()); if(room == 0) room = -1; } else if(dedicated) room = -1; else room = cv_chooseroom.value; for(signature = 0, insname = cv_servername.string; *insname; signature += *insname++); tmp = (UINT32)(signature * (size_t)&MSLastPing); signature *= tmp; signature &= 0xAAAAAAAA; M_Memcpy(&info->header.signature, &signature, sizeof (UINT32)); strcpy(info->ip, ""); strcpy(info->port, int2str(current_port)); strcpy(info->name, cv_servername.string); M_Memcpy(&info->room, & room, sizeof (INT32)); sprintf(info->version, "%d.%d.%d", VERSION/100, VERSION%100, SUBVERSION); strcpy(registered_server.name, cv_servername.string); if(firstadd) msg.type = ADD_SERVER_MSG; else msg.type = PING_SERVER_MSG; msg.length = (UINT32)sizeof (msg_server_t); msg.room = 0; if (MS_Write(&msg) < 0) { MSLastPing = timestamp; return ConnectionFailed(); } if(con_state != MSCS_REGISTERED) CONS_Printf("Master Server Updated Successfully!\n"); MSLastPing = timestamp; con_state = MSCS_REGISTERED; CloseConnection(); #endif return MS_NO_ERROR; }
static inline int internal_mi_print_dlg(struct mi_node *rpl, struct dlg_cell *dlg, int with_context) { struct mi_node* node= NULL; struct mi_node* node1 = NULL; struct mi_node* node2 = NULL; struct mi_node* node3 = NULL; struct mi_attr* attr= NULL; struct dlg_profile_link *dl; struct dlg_val* dv; int len; char* p; int i, j; time_t _ts; struct tm* t; char date_buf[MI_DATE_BUF_LEN]; int date_buf_len; node = add_mi_node_child(rpl, 0, "dialog",6 , 0, 0 ); if (node==0) goto error; attr = addf_mi_attr( node, 0, "ID", 2, "%llu", (((long long unsigned)dlg->h_entry)<<(8*sizeof(int)))+dlg->h_id ); if (attr==0) goto error; p= int2str((unsigned long)dlg->state, &len); node1 = add_mi_node_child( node, MI_DUP_VALUE, "state", 5, p, len); if (node1==0) goto error; p= int2str((unsigned long)dlg->user_flags, &len); node1 = add_mi_node_child( node, MI_DUP_VALUE, "user_flags", 10, p, len); if (node1==0) goto error; _ts = (time_t)dlg->start_ts; p= int2str((unsigned long)_ts, &len); node1 = add_mi_node_child(node,MI_DUP_VALUE,"timestart",9, p, len); if (node1==0) goto error; if (_ts) { t = localtime(&_ts); date_buf_len = strftime(date_buf, MI_DATE_BUF_LEN - 1, "%Y-%m-%d %H:%M:%S", t); if (date_buf_len != 0) { node1 = add_mi_node_child(node,MI_DUP_VALUE, "datestart", 9, date_buf, date_buf_len); if (node1==0) goto error; } } _ts = (time_t)(dlg->tl.timeout?((unsigned int)time(0) + dlg->tl.timeout - get_ticks()):0); p= int2str((unsigned long)_ts, &len); node1 = add_mi_node_child(node,MI_DUP_VALUE, "timeout", 7, p, len); if (node1==0) goto error; if (_ts) { t = localtime(&_ts); date_buf_len = strftime(date_buf, MI_DATE_BUF_LEN - 1, "%Y-%m-%d %H:%M:%S", t); if (date_buf_len != 0) { node1 = add_mi_node_child(node,MI_DUP_VALUE, "dateout", 7, date_buf, date_buf_len); if (node1==0) goto error; } } node1 = add_mi_node_child(node, MI_DUP_VALUE, "callid", 6, dlg->callid.s, dlg->callid.len); if(node1 == 0) goto error; node1 = add_mi_node_child(node, MI_DUP_VALUE, "from_uri", 8, dlg->from_uri.s, dlg->from_uri.len); if(node1 == 0) goto error; node1 = add_mi_node_child(node, MI_DUP_VALUE, "to_uri", 6, dlg->to_uri.s, dlg->to_uri.len); if(node1 == 0) goto error; if (dlg->legs_no[DLG_LEGS_USED]>0) { node1 = add_mi_node_child(node, MI_DUP_VALUE, "caller_tag", 10, dlg->legs[DLG_CALLER_LEG].tag.s, dlg->legs[DLG_CALLER_LEG].tag.len); if(node1 == 0) goto error; node1 = add_mi_node_child(node, MI_DUP_VALUE, "caller_contact", 14, dlg->legs[DLG_CALLER_LEG].contact.s, dlg->legs[DLG_CALLER_LEG].contact.len); if(node1 == 0) goto error; node1 = add_mi_node_child(node, MI_DUP_VALUE, "callee_cseq", 11, dlg->legs[DLG_CALLER_LEG].r_cseq.s, dlg->legs[DLG_CALLER_LEG].r_cseq.len); if(node1 == 0) goto error; node1 = add_mi_node_child(node, MI_DUP_VALUE,"caller_route_set",16, dlg->legs[DLG_CALLER_LEG].route_set.s, dlg->legs[DLG_CALLER_LEG].route_set.len); if(node1 == 0) goto error; node1 = add_mi_node_child(node, 0,"caller_bind_addr",16, dlg->legs[DLG_CALLER_LEG].bind_addr->sock_str.s, dlg->legs[DLG_CALLER_LEG].bind_addr->sock_str.len); if(node1 == 0) goto error; node1 = add_mi_node_child(node, MI_DUP_VALUE,"caller_sdp",10, dlg->legs[DLG_CALLER_LEG].sdp.s, dlg->legs[DLG_CALLER_LEG].sdp.len); if(node1 == 0) goto error; } node1 = add_mi_node_child(node, MI_IS_ARRAY, "CALLEES", 7, NULL, 0); if(node1 == 0) goto error; for( i=1 ; i < dlg->legs_no[DLG_LEGS_USED] ; i++ ) { node2 = add_mi_node_child(node1, 0, "callee", 6, NULL, 0); if(node2 == 0) goto error; node3 = add_mi_node_child(node2, MI_DUP_VALUE, "callee_tag", 10, dlg->legs[i].tag.s, dlg->legs[i].tag.len); if(node3 == 0) goto error; node3 = add_mi_node_child(node2, MI_DUP_VALUE, "callee_contact", 14, dlg->legs[i].contact.s, dlg->legs[i].contact.len); if(node3 == 0) goto error; node3 = add_mi_node_child(node2, MI_DUP_VALUE, "caller_cseq", 11, dlg->legs[i].r_cseq.s, dlg->legs[i].r_cseq.len); if(node3 == 0) goto error; node3 = add_mi_node_child(node2, MI_DUP_VALUE,"callee_route_set",16, dlg->legs[i].route_set.s, dlg->legs[i].route_set.len); if(node3 == 0) goto error; if (dlg->legs[i].bind_addr) { node3 = add_mi_node_child(node2, 0, "callee_bind_addr",16, dlg->legs[i].bind_addr->sock_str.s, dlg->legs[i].bind_addr->sock_str.len); } else { node3 = add_mi_node_child(node2, 0, "callee_bind_addr",16,0,0); } if(node3 == 0) goto error; node3 = add_mi_node_child(node2, MI_DUP_VALUE,"callee_sdp",10, dlg->legs[i].sdp.s, dlg->legs[i].sdp.len); if(node3 == 0) goto error; } if (with_context) { node1 = add_mi_node_child(node, 0, "context", 7, 0, 0); if(node1 == 0) goto error; if (dlg->vals) { node2 = add_mi_node_child(node1, 0, "values", 6, 0, 0); if(node2 == 0) goto error; /* print dlg values -> iterate the list */ for( dv=dlg->vals ; dv ; dv=dv->next) { /* escape non-printable chars */ p = pkg_realloc(dlg_val_buf, 4 * dv->val.len + 1); if (!p) { LM_ERR("not enough mem to allocate: %d\n", dv->val.len); continue; } for (i = 0, j = 0; i < dv->val.len; i++) { if (dv->val.s[i] < 0x20 || dv->val.s[i] >= 0x7F) { p[j++] = '\\'; switch ((unsigned char)dv->val.s[i]) { case 0x8: p[j++] = 'b'; break; case 0x9: p[j++] = 't'; break; case 0xA: p[j++] = 'n'; break; case 0xC: p[j++] = 'f'; break; case 0xD: p[j++] = 'r'; break; default: p[j++] = 'x'; j += snprintf(&p[j], 3, "%02x", (unsigned char)dv->val.s[i]); break; } } else { p[j++] = dv->val.s[i]; } } add_mi_node_child(node2, MI_DUP_NAME|MI_DUP_VALUE,dv->name.s,dv->name.len, p,j); dlg_val_buf = p; } } /* print dlg profiles */ if (dlg->profile_links) { node3 = add_mi_node_child(node1, MI_IS_ARRAY, "profiles", 8, 0, 0); if(node3 == 0) goto error; for( dl=dlg->profile_links ; dl ; dl=dl->next) { add_mi_node_child(node3, MI_DUP_NAME|MI_DUP_VALUE, dl->profile->name.s,dl->profile->name.len, ZSW(dl->value.s),dl->value.len); } } /* print external context info */ run_dlg_callbacks( DLGCB_MI_CONTEXT, dlg, NULL, DLG_DIR_NONE, (void *)node1, 0); } return 0; error: LM_ERR("failed to add node\n"); return -1; }
void getHistosFromRE(const string& mhid, const string& filepath, const string& sre, vector<std::pair<string,wTH1*> >& v_wth1) { if (gl_verbose) cout<<"Searching for regexp "<<sre<<" in "<<filepath; // allow for multiple regexes in OR combination // vector<string> v_regexes; Tokenize(sre,v_regexes,"|"); if (!v_regexes.size()) v_regexes.push_back(sre); // Build validated TRegexp arguments in preparation for directory recursion // TObjArray *Args = new TObjArray(); for (size_t i=0; i<v_regexes.size(); i++) { TRegexp re(v_regexes[i].c_str(),kTRUE); if (re.Status() != TRegexp::kOK) { cerr << "The regexp " << v_regexes[i] << " is invalid, Status() = "; cerr << re.Status() << endl; exit(-1); } else { Args->AddLast(new TObjString(v_regexes[i].c_str())); } } // Get the root file // TFile *rootfile = openRootFile(filepath); if (!rootfile) { cerr << "File failed to open, " << filepath << endl; Args->Delete(); delete Args; return; } // Do the recursion, collect matches // TObjArray *Matches = new TObjArray(); recurseDirs(rootfile, ®exMatchHisto, Args, Matches); Args->Delete(); delete Args; // Returns two objects per match: // 1. the (string) path that was matched and // 2. the object whose path matched // int nx2matches = Matches->GetEntriesFast(); if (gl_verbose) cout << "... " << nx2matches/2 << " match(es) found."; // Add the matches to the global map of histos // int istart = v_wth1.size(); for (int i=0; i<nx2matches; i+=2) { TString fullspec = ((TObjString *)(*Matches)[i])->GetString(); wTH1 *wth1 = new wTH1((TH1 *)((*Matches)[i+1])); wth1->histo()->UseCurrentStyle(); wth1->histo()->SetLineColor(((i/2)%9)+1); wth1->histo()->SetLineStyle((i/18)+1); wth1->histo()->SetLineWidth(2); wth1->SetLegendEntry(wth1->histo()->GetName()); string hidi= mhid+"_"+int2str(istart+(i/2)); v_wth1.push_back(std::pair<string,wTH1 *>(hidi,wth1)); //glmap_objpath2id.insert(pair<string,string>(fullspec,hidi)); glmap_id2histo.insert(pair<string,wTH1 *>(hidi,wth1)); glmap_id2objpath.insert(pair<string,string>(hidi,string(fullspec.Data()))); } //Matches->Delete(); // need the histos! delete Matches; if (gl_verbose) cout << endl; } // getHistosFromRE
bool // returns true if success processMultiHistSection(FILE *fp, string& theline, bool& new_section) { vector<string> v_tokens; vector<std::pair<string, wTH1 *> > v_histos; string mhid; if (gl_verbose) cout << "Processing multihist section" << endl; new_section=false; while (getLine(fp,theline,"multihist")) { if (!theline.size()) continue; if (theline[0] == '#') continue; // comments are welcome if (theline[0] == '[') { new_section=true; return true; } string key, value; if (!getKeyValue(theline,key,value)) continue; //-------------------- if (key == "id") { //-------------------- if (mhid.size()) { cerr << "no more than one id per histo section allowed " << value << endl; break; } mhid = value; //------------------------------ } else if (key == "pathglob") { //------------------------------ glob_t globbuf; if (!mhid.size()) { cerr << "id key must be defined first in the section" << endl; continue; } Tokenize(value,v_tokens,":"); if ((v_tokens.size() != 2) || (!v_tokens[0].size()) || (!v_tokens[1].size()) ) { cerr << "malformed pathglob 'fileglob:regex' " << value << endl; exit(-1); } // File globbing pattern can select multiple files // regular expression pattern can select multiple histos within each file. // string fileglob = v_tokens[0]; string stregex = v_tokens[1]; int stat = glob (fileglob.c_str(), GLOB_MARK, NULL, &globbuf); if (stat) { switch (stat) { case GLOB_NOMATCH: cerr << "No file matching glob pattern "; break; case GLOB_NOSPACE: cerr << "glob ran out of memory "; break; case GLOB_ABORTED: cerr << "glob read error "; break; default: cerr << "unknown glob error stat=" << stat << " "; break; } cerr << fileglob << endl; exit(-1); } if (gl_verbose) cout<<globbuf.gl_pathc<<" files match the glob pattern"<<endl; for (size_t i=0; i<globbuf.gl_pathc; i++) { char *path = globbuf.gl_pathv[i]; if (!strncmp(&path[strlen(path)-6],".root",5)) { cerr << "non-root file found in glob, skipping: " << path << endl; } else { getHistosFromRE(mhid,string(path),stregex, v_histos); } } if (gl_verbose) cout << v_histos.size() << " total matches found." << endl; globfree(&globbuf); glmap_mobj2size.insert(pair<string,unsigned>(mhid,v_histos.size())); //------------------------------ } else if( key == "fillfromtree" ) { // converts tree array variables into a group of histos //------------------------------ if( !mhid.size() ) { cerr << "id key must be defined first in the section" << endl; continue; } // histo need not be pre-booked, since TTree::Draw can do that Tokenize(value,v_tokens,";"); string treedrawspec=v_tokens[0]; int ifirst=-1,ilast=-1; if (v_tokens.size() == 2) { string range=v_tokens[1]; Tokenize(range,v_tokens,"-"); if (v_tokens.size()==2) { ifirst=str2int(v_tokens[0]); ilast =str2int(v_tokens[1]); } } //cout << v_tokens.size() << " " << ifirst << " " << ilast << endl; if (ifirst<0 || ilast <0 || ilast<ifirst ) { cerr << "malformed filltree expression drawspec;X-Y, where X-Y is the array index range to plot"<<endl; exit(-1); } for (int i=ifirst; i<=ilast; i++) { wTH1 *wth1 = NULL; // defined in spTree.C void fillHistoFromTreeVar(std::string& drawspec,int index,wTH1 *&wth1); fillHistoFromTreeVar(treedrawspec,i,wth1); assert(wth1); string hidi= mhid+"_"+int2str(i-ifirst); v_histos.push_back(std::pair<string,wTH1 *>(hidi,wth1)); glmap_id2histo.insert(pair<string,wTH1 *>(hidi,wth1)); } glmap_mobj2size.insert(pair<string,unsigned>(mhid,v_histos.size())); //----------------------- } else if( key == "printf" ) { //----------------------- Tokenize(value,v_tokens,"\","); switch( v_tokens.size() ) { case 1: printf (v_tokens[0].c_str()); break; case 2: printf (v_tokens[0].c_str(),v_tokens[1].c_str()); break; case 3: printf (v_tokens[0].c_str(), v_tokens[1].c_str(), v_tokens[2].c_str()); break; case 4: printf (v_tokens[0].c_str(), v_tokens[1].c_str(), v_tokens[2].c_str(), v_tokens[3].c_str()); break; default: cerr << "Unsupported number of arguments, " << value << endl; exit(-1); } } else if( !v_histos.size() ) { // all other keys must have "path" defined cerr << "histo vector is empty" << endl; cerr << "key 'pathglob' or 'vartable' must define nonempty histo set before key " << key << endl; break; } else { processCommonHistoParams(key,value,v_histos); if( key == "printfstats" ) cout << endl; } } return (v_histos.size()); } // processMultiHistSection
void Perm::preGeneDrop() { // Note -- minor issue, this routine ignores // issue of linkage between sibs // Idea: to use standard case/control or QT test, but permute only // transmissions from founders, and to all offspring: to give a // within-family test. // Set up parent-offspring structure, but not related to // nuclear families // par::perm_genedrop // If true, perform gene-dropping permutation instead of label-swapping // par::perm_genedrop_founders // If true, non-founder parents always drop one of their gene-dropped alleles // If false, non-founder parents always drop one of their true alleles // par::perm_genedrop_parents // If true, we also perform a label-swapping permutation within all parents // par::perm_genedrop_sibships // If true, we also perform a label-swapping permutation within all full // sibships without parents map<string,Individual*> fnd; // Link up parents and offspring P.linkRelateds(idmap, fnd); P.printLOG("Allocated family structure for gene-dropping\n"); // Set initial permutation structure -- no label-swapping for (int i=0; i<P.sample.size(); i++) P.sample[i]->sol = -1; // Label-swapping cluster count int cc=0; int cc_par=0; map<string,int> parent; map<string,int> parent_pat; map<string,int> parent_mat; // Set up clusters for within-parent label-swapping permutation if (par::perm_genedrop_parents) { // Parents must be pairs for simple nuclear families // i.e. watch out for half-sib relations for (int i=0; i<P.n; i++) { Individual * person = P.sample[i]; // Only consider non-founders if ( fnd.find(person->fid+"_"+person->iid) == fnd.end() ) { string spat = person->pp->fid+"_"+person->pp->iid; string smat = person->pm->fid+"_"+person->pm->iid; string pair = spat+" x "+smat; // If this parent pair has not previously featured, // AND if neither parent has previously featured in // any other pairing, then make this parental set // a pair if ( parent.find(pair) == parent.end() && parent_pat.find(spat) == parent_pat.end() && parent_mat.find(smat) == parent_mat.end() ) { person->pp->sol = cc; person->pm->sol = cc; cc++; parent.insert(make_pair(pair,cc)); parent_pat.insert(make_pair(spat,cc)); parent_mat.insert(make_pair(smat,cc)); } } } P.printLOG("Allocated "+int2str(cc)+" clusters for within-parent permutation\n"); cc_par = cc; } // Set up clusters for within-sibship permutation if (par::perm_genedrop_sibships) { // i.e for individuals for whom pat and mat != 0 but the parent is // no longer in the dataset (i.e. removed for low genotyping, as it // was a dummy parent). map<string,int> sibs; for (int i=0; i<P.n; i++) { Individual * person = P.sample[i]; // Only consider true non-founders i.e. unlike the above // section, which considers only parents, but only those // for whom we do not have 2 parents if ( ! person->founder && fnd.find(person->fid+"_"+person->iid) != fnd.end() && parent_pat.find(person->fid+"_"+person->iid) == parent_pat.end() && parent_mat.find(person->fid+"_"+person->iid) == parent_mat.end() ) { string pair = person->fid+"_"+person->pat+"_"+person->mat; // If we haven't seen this sibship before, add a new cluster code map<string,int>::iterator sit = sibs.find(pair); if (sit == sibs.end()) { person->sol = cc; sibs.insert(make_pair(pair,cc)); cc++; } else { // ...otherwise, assign to existing one person->sol = sit->second; } } } P.printLOG("Allocated "+int2str(cc-cc_par)+" clusters for within-sibship permutation\n"); } // Label-swapping permutation of all unrelated individuals? // everybody else, who is a family size 1 // this means if (par::perm_genedrop_unrel) { map<string,int> unrel; for (int i=0; i<P.n; i++) { string f = P.sample[i]->fid; if ( unrel.find(f) == unrel.end() ) { unrel.insert(make_pair(f,1)); } else { (unrel.find(f)->second)++; } } for (int i=0; i<P.n; i++) cout << P.sample[i]->fid << "\t" << unrel.find(P.sample[i]->fid)->second << "\n"; // If no parents, assign unique cluster // if (fnd.find(person->fid+"_"+person->iid) != fnd.end()) // person->sol = cc; P.printLOG("Allocated cluster for between-founder permutation\n"); } }
/* * Read method * * Read in a VASP file referred to by <filename>. The state of the program * is changed according to which line is being read. First, the number * of atoms and the elements are read. Then the dimension of the unit cell * and finally the number of atoms and the energy of each of the states. All * information is collected and the VaspReader class can be accessed by the * Dataset class for data handling. */ bool VaspReader::read(const char* filename) { std::ifstream infile(filename); this->state |= (1 << VASP_OUTCAR_READ_STATE_ELEMENTS); this->state |= (1 << VASP_OUTCAR_READ_STATE_IONS_PER_ELEMENT); this->state |= (1 << VASP_OUTCAR_READ_STATE_OPEN); this->nr_atoms_total = 0; this->nr_states = 0; /* * For each type of regex pattern recognition, a new set of pcre variables * are constructed. */ pcre *regex_compiled_vasp_version; pcre_extra *pcre_extra_vasp_version; pcre *regex_compiled_element; pcre_extra *pcre_extra_element; pcre *regex_compiled_ions_per_element; pcre_extra *pcre_extra_ions_per_element; pcre *regex_compiled_lattice_vectors; pcre_extra *pcre_extra_lattice_vectors; pcre *regex_compiled_atoms; pcre_extra *pcre_extra_atoms; pcre *regex_compiled_grab_numbers; pcre_extra *pcre_extra_grab_numbers; pcre *regex_compiled_grab_energy; pcre_extra *pcre_extra_grab_energy; const char *pcre_error_string; const char *pcre_substring_match_string; int pcre_error_offset = 0; int pcre_exec_ret = 0; int pcre_substring_vec[30]; int pos = 2; /* * Define all the regex patterns */ const char *string_regex_vasp_version = "^\\s*vasp.([0-9]).[0-9]+.[0-9]+.*$"; const char *string_regex_element = "^\\s*(VRHFIN\\s+=)([A-Za-z]+)\\s*:.*$"; const char *string_regex_ions_per_element = "^\\s*(ions per type =\\s+)([0-9 ]+)$"; const char *string_regex_lattice_vectors = "^\\s*direct lattice vectors.*$"; const char *string_regex_atoms = "^\\s*POSITION.*$"; const char *string_regex_grab_numbers = "^\\s+([0-9.-]+)\\s+([0-9.-]+)\\s+([0-9.-]+)\\s+([0-9.-]+)\\s+([0-9.-]+)\\s+([0-9.-]+).*$"; const char *string_regex_grab_energy = "^\\s+energy without entropy=\\s+([0-9.-]+)\\s+energy\\(sigma->0\\) =\\s+([0-9.-]+).*$"; /* * Compile all the regex patterns */ regex_compiled_vasp_version = pcre_compile(string_regex_vasp_version, 0, &pcre_error_string, &pcre_error_offset, NULL); pcre_extra_vasp_version = pcre_study(regex_compiled_vasp_version, 0, &pcre_error_string); regex_compiled_element = pcre_compile(string_regex_element, 0, &pcre_error_string, &pcre_error_offset, NULL); pcre_extra_element = pcre_study(regex_compiled_element, 0, &pcre_error_string); regex_compiled_ions_per_element = pcre_compile(string_regex_ions_per_element, 0, &pcre_error_string, &pcre_error_offset, NULL); pcre_extra_ions_per_element = pcre_study(regex_compiled_ions_per_element, 0, &pcre_error_string); regex_compiled_lattice_vectors = pcre_compile(string_regex_lattice_vectors, 0, &pcre_error_string, &pcre_error_offset, NULL); pcre_extra_lattice_vectors = pcre_study(regex_compiled_lattice_vectors, 0, &pcre_error_string); regex_compiled_atoms = pcre_compile(string_regex_atoms, 0, &pcre_error_string, &pcre_error_offset, NULL); pcre_extra_atoms = pcre_study(regex_compiled_atoms, 0, &pcre_error_string); regex_compiled_grab_numbers = pcre_compile(string_regex_grab_numbers, 0, &pcre_error_string, &pcre_error_offset, NULL); pcre_extra_grab_numbers = pcre_study(regex_compiled_grab_numbers, 0, &pcre_error_string); regex_compiled_grab_energy = pcre_compile(string_regex_grab_energy, 0, &pcre_error_string, &pcre_error_offset, NULL); pcre_extra_grab_energy = pcre_study(regex_compiled_grab_energy, 0, &pcre_error_string); std::string line; while (std::getline(infile, line)) { // loop over all the lines in the file /* * Collect the vasp version (4 or 5) */ if(this->state & (1 << VASP_OUTCAR_READ_STATE_ELEMENTS) ) { // get the elements and put these in an array pos = 1; pcre_exec_ret = pcre_exec(regex_compiled_vasp_version, pcre_extra_vasp_version, line.c_str(), line.length(), 0, 0, pcre_substring_vec, 30); if(pcre_exec_ret > 0) { pcre_get_substring(line.c_str(), pcre_substring_vec, pcre_exec_ret, pos, &(pcre_substring_match_string)); this->vasp_version = atoi(pcre_substring_match_string); } } /* * Collect the elements */ if(this->state & (1 << VASP_OUTCAR_READ_STATE_ELEMENTS) ) { // get the elements and put these in an array pos = 2; pcre_exec_ret = pcre_exec(regex_compiled_element, pcre_extra_element, line.c_str(), line.length(), 0, 0, pcre_substring_vec, 30); if(pcre_exec_ret > 0) { pcre_get_substring(line.c_str(), pcre_substring_vec, pcre_exec_ret, pos, &(pcre_substring_match_string)); this->elements.push_back(pcre_substring_match_string); } } /* * Collect the number of ions of each element type */ if(this->state & (1 << VASP_OUTCAR_READ_STATE_IONS_PER_ELEMENT) ) { // get the number of ions per element (type) pos = 2; pcre_exec_ret = pcre_exec(regex_compiled_ions_per_element, pcre_extra_ions_per_element, line.c_str(), line.length(), 0, 0, pcre_substring_vec, 30); if(pcre_exec_ret > 0) { pcre_get_substring(line.c_str(), pcre_substring_vec, pcre_exec_ret, pos, &(pcre_substring_match_string)); std::vector<std::string> elements_vector = this->explode(pcre_substring_match_string, " "); for(unsigned int i=0; i<elements_vector.size(); i++) { if(elements_vector[i].empty() == false) { nr_atoms_per_elm.push_back(atoi(elements_vector[i].c_str() ) ); nr_atoms_total += atoi(elements_vector[i].c_str() ); } } // allocate element_uint vector for(unsigned int i=0; i<this->elements.size(); i++) { this->elements_uint.push_back(this->get_element_number_from_name(this->elements[i])); } // remove ions state and elements state this->state &= ~(1 << VASP_OUTCAR_READ_STATE_ELEMENTS); this->state &= ~(1 << VASP_OUTCAR_READ_STATE_IONS_PER_ELEMENT); this->state |= (1 << VASP_OUTCAR_READ_STATE_LATTICE_VECTORS); } } /* * Collect the dimensions of the unit cell. Note is an IBRION=3 calculation is * being run, this is not gathered by this class. It is assumed that each state * has the same unit cell. (that means, IBRION != 3 calculations) */ if(this->state & (1 << VASP_OUTCAR_READ_STATE_LATTICE_VECTORS) ) { // get the dimensionality of the unit cell pos = 0; pcre_exec_ret = pcre_exec(regex_compiled_lattice_vectors, pcre_extra_lattice_vectors, line.c_str(), line.length(), 0, 0, pcre_substring_vec, 30); if(pcre_exec_ret > 0) { pcre_get_substring(line.c_str(), pcre_substring_vec, pcre_exec_ret, pos, &(pcre_substring_match_string)); // grab three lines for(int i=0; i<3; i++) { std::getline(infile, line); pcre_exec_ret = pcre_exec(regex_compiled_grab_numbers, pcre_extra_grab_numbers, line.c_str(), line.length(), 0, 0, pcre_substring_vec, 30); if(pcre_exec_ret > 0) { pos = 1; pcre_get_substring(line.c_str(), pcre_substring_vec, pcre_exec_ret, pos, &(pcre_substring_match_string)); this->dimensions.push_back(atof(pcre_substring_match_string)); pos = 2; pcre_get_substring(line.c_str(), pcre_substring_vec, pcre_exec_ret, pos, &(pcre_substring_match_string)); this->dimensions.push_back(atof(pcre_substring_match_string)); pos = 3; pcre_get_substring(line.c_str(), pcre_substring_vec, pcre_exec_ret, pos, &(pcre_substring_match_string)); this->dimensions.push_back(atof(pcre_substring_match_string)); } } this->state &= ~(1 << VASP_OUTCAR_READ_STATE_LATTICE_VECTORS); this->state |= (1 << VASP_OUTCAR_READ_STATE_ATOMS); } } /* * Collect the energy of the state */ if(this->state & (1 << VASP_OUTCAR_READ_STATE_ATOMS) ) { pos = 2; pcre_exec_ret = pcre_exec(regex_compiled_grab_energy, pcre_extra_grab_energy, line.c_str(), line.length(), 0, 0, pcre_substring_vec, 30); if(pcre_exec_ret > 0) { pcre_get_substring(line.c_str(), pcre_substring_vec, pcre_exec_ret, pos, &(pcre_substring_match_string)); //std::cout << atof(pcre_substring_match_string) << std::endl; this->energies.push_back(atof(pcre_substring_match_string)); if(this->vasp_version == 5) { this->states.push_back(State(this->energies[this->nr_states - 1], this->dimensions, this->atoms, this->elements, this->elements_uint, this->nr_atoms_per_elm, filename, this->nr_states)); this->atoms.clear(); } } } /* * Collect the atomic positions and forces for this state */ if(this->state & (1 << VASP_OUTCAR_READ_STATE_ATOMS) ) { // get the atoms per state pos = 0; pcre_exec_ret = pcre_exec(regex_compiled_atoms, pcre_extra_atoms, line.c_str(), line.length(), 0, 0, pcre_substring_vec, 30); if(pcre_exec_ret > 0) { this->nr_states++; pcre_get_substring(line.c_str(), pcre_substring_vec, pcre_exec_ret, pos, &(pcre_substring_match_string)); //printf("'%s'\n", pcre_substring_match_string); std::getline(infile, line); // discard this line for(unsigned i=0; i<this->nr_atoms_per_elm.size(); i++) { for(unsigned int j=0; j<this->nr_atoms_per_elm[i]; j++) { std::getline(infile, line); pcre_exec_ret = pcre_exec(regex_compiled_grab_numbers, pcre_extra_grab_numbers, line.c_str(), line.length(), 0, 0, pcre_substring_vec, 30); if(pcre_exec_ret > 0) { //std::cout << "Atom #" << (i+1) << std::endl; float x, y, z, fx, fy, fz; pos = 1; pcre_get_substring(line.c_str(), pcre_substring_vec, pcre_exec_ret, pos, &(pcre_substring_match_string)); x = atof(pcre_substring_match_string); pos = 2; pcre_get_substring(line.c_str(), pcre_substring_vec, pcre_exec_ret, pos, &(pcre_substring_match_string)); y = atof(pcre_substring_match_string); pos = 3; pcre_get_substring(line.c_str(), pcre_substring_vec, pcre_exec_ret, pos, &(pcre_substring_match_string)); z = atof(pcre_substring_match_string); pos = 4; pcre_get_substring(line.c_str(), pcre_substring_vec, pcre_exec_ret, pos, &(pcre_substring_match_string)); fx = atof(pcre_substring_match_string); pos = 5; pcre_get_substring(line.c_str(), pcre_substring_vec, pcre_exec_ret, pos, &(pcre_substring_match_string)); fy = atof(pcre_substring_match_string); pos = 6; pcre_get_substring(line.c_str(), pcre_substring_vec, pcre_exec_ret, pos, &(pcre_substring_match_string)); fz = atof(pcre_substring_match_string); this->atoms.push_back(Atom( this->get_element_number_from_name(this->elements[i]), x, y, z, fx, fy, fz )); } } } if(this->vasp_version == 4) { this->states.push_back(State(this->energies[this->nr_states - 1], this->dimensions, this->atoms, this->elements, this->elements_uint, this->nr_atoms_per_elm, filename, this->nr_states)); this->atoms.clear(); } } } } this->state = (1 << VASP_OUTCAR_READ_STATE_FINISHED); // output all information std::string elements_string; for(unsigned int i=0; i < this->elements.size(); i++) { elements_string.append(elements[i]); elements_string.append("("); elements_string.append(int2str(nr_atoms_per_elm[i]) ); elements_string.append(")"); elements_string.append(" "); } return true; }
/*! * \brief Helper method that output a dialog via the MI interface * \see mi_print_dlg * \param rpl MI node that should be filled * \param dlg printed dialog * \param with_context if 1 then the dialog context will be also printed * \return 0 on success, -1 on failure */ static inline int internal_mi_print_dlg(struct mi_node *rpl, struct dlg_cell *dlg, int with_context) { struct mi_node* node= NULL; struct mi_node* node1 = NULL; struct mi_attr* attr= NULL; int len; char* p; node = add_mi_node_child(rpl, 0, "dialog",6 , 0, 0 ); if (node==0) goto error; attr = addf_mi_attr( node, 0, "hash", 4, "%u:%u", dlg->h_entry, dlg->h_id ); if (attr==0) goto error; p= int2str((unsigned long)dlg->state, &len); node1 = add_mi_node_child( node, MI_DUP_VALUE, "state", 5, p, len); if (node1==0) goto error; p= int2str((unsigned long)dlg->ref, &len); node1 = add_mi_node_child( node, MI_DUP_VALUE, "ref_count", 9, p, len); if (node1==0) goto error; p= int2str((unsigned long)dlg->start_ts, &len); node1 = add_mi_node_child(node,MI_DUP_VALUE,"timestart",9, p, len); if (node1==0) goto error; p= int2str((unsigned long)dlg->tl.timeout, &len); node1 = add_mi_node_child(node,MI_DUP_VALUE, "timeout", 7, p, len); if (node1==0) goto error; node1 = add_mi_node_child(node, MI_DUP_VALUE, "callid", 6, dlg->callid.s, dlg->callid.len); if(node1 == 0) goto error; node1 = add_mi_node_child(node, MI_DUP_VALUE, "from_uri", 8, dlg->from_uri.s, dlg->from_uri.len); if(node1 == 0) goto error; node1 = add_mi_node_child(node, MI_DUP_VALUE, "from_tag", 8, dlg->tag[DLG_CALLER_LEG].s, dlg->tag[DLG_CALLER_LEG].len); if(node1 == 0) goto error; node1 = add_mi_node_child(node, MI_DUP_VALUE, "caller_contact", 14, dlg->contact[DLG_CALLER_LEG].s, dlg->contact[DLG_CALLER_LEG].len); if(node1 == 0) goto error; node1 = add_mi_node_child(node, MI_DUP_VALUE, "caller_cseq", 11, dlg->cseq[DLG_CALLER_LEG].s, dlg->cseq[DLG_CALLER_LEG].len); if(node1 == 0) goto error; node1 = add_mi_node_child(node, MI_DUP_VALUE,"caller_route_set",16, dlg->route_set[DLG_CALLER_LEG].s, dlg->route_set[DLG_CALLER_LEG].len); if(node1 == 0) goto error; if (dlg->bind_addr[DLG_CALLER_LEG]) { node1 = add_mi_node_child(node, 0, "caller_bind_addr",16, dlg->bind_addr[DLG_CALLER_LEG]->sock_str.s, dlg->bind_addr[DLG_CALLER_LEG]->sock_str.len); } else { node1 = add_mi_node_child(node, 0, "caller_bind_addr",16,0,0); } if (dlg->bind_addr[DLG_CALLEE_LEG]) { node1 = add_mi_node_child(node, 0, "callee_bind_addr",16, dlg->bind_addr[DLG_CALLEE_LEG]->sock_str.s, dlg->bind_addr[DLG_CALLEE_LEG]->sock_str.len); } else { node1 = add_mi_node_child(node, 0, "callee_bind_addr",16,0,0); } node1 = add_mi_node_child(node, MI_DUP_VALUE, "to_uri", 6, dlg->to_uri.s, dlg->to_uri.len); if(node1 == 0) goto error; node1 = add_mi_node_child(node, MI_DUP_VALUE, "to_tag", 6, dlg->tag[DLG_CALLEE_LEG].s, dlg->tag[DLG_CALLEE_LEG].len); if(node1 == 0) goto error; node1 = add_mi_node_child(node, MI_DUP_VALUE, "callee_contact", 14, dlg->contact[DLG_CALLEE_LEG].s, dlg->contact[DLG_CALLEE_LEG].len); if(node1 == 0) goto error; node1 = add_mi_node_child(node, MI_DUP_VALUE, "callee_cseq", 11, dlg->cseq[DLG_CALLEE_LEG].s, dlg->cseq[DLG_CALLEE_LEG].len); if(node1 == 0) goto error; node1 = add_mi_node_child(node, MI_DUP_VALUE,"callee_route_set",16, dlg->route_set[DLG_CALLEE_LEG].s, dlg->route_set[DLG_CALLEE_LEG].len); if(node1 == 0) goto error; if (with_context) { node1 = add_mi_node_child(node, 0, "context", 7, 0, 0); if(node1 == 0) goto error; run_dlg_callbacks( DLGCB_MI_CONTEXT, dlg, NULL, NULL, DLG_DIR_NONE, (void *)node1); } return 0; error: LM_ERR("failed to add node\n"); return -1; }
static struct mi_root* mi_print_blacklists(struct mi_root *cmd, void *param) { struct mi_root *rpl_tree; struct mi_node *rpl; struct mi_node *node; struct mi_node *node1; struct mi_node *node2; struct mi_attr *attr; unsigned int i; struct bl_rule *blr; char *p; int len; rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN); if (rpl_tree==NULL) return 0; rpl = &rpl_tree->node; for ( i=0 ; i<used_heads ; i++ ) { if( !(blst_heads[i].flags&BL_READONLY_LIST) ) { /* get list for read */ lock_get( blst_heads[i].lock ); while(blst_heads[i].count_write) { lock_release( blst_heads[i].lock ); sleep_us(5); lock_get( blst_heads[i].lock ); } blst_heads[i].count_read++; lock_release(blst_heads[i].lock); } /* add a list node */ node = add_mi_node_child( rpl, 0, "List", 4, blst_heads[i].name.s, blst_heads[i].name.len ); if (node==0) goto error; /* add some attributes to the list node */ p= int2str((unsigned long)blst_heads[i].owner, &len); attr = add_mi_attr( node, MI_DUP_VALUE, "owner", 5, p, len); if (attr==0) goto error; p= int2str((unsigned long)blst_heads[i].flags, &len); attr = add_mi_attr( node, MI_DUP_VALUE, "flags", 5, p, len); if (attr==0) goto error; for( blr = blst_heads[i].first ; blr ; blr = blr->next) { /* add a rule node */ node1 = add_mi_node_child( node, 0, "Rule", 4, 0, 0 ); if (node1==0) goto error; /* add attributes to the rule node */ p= int2str((unsigned long)blr->flags, &len); attr = add_mi_attr( node1, MI_DUP_VALUE, "flags", 5, p, len); if (attr==0) goto error; /* add to rule node */ p = ip_addr2a(&blr->ip_net.ip); len = p?strlen(p):0; node2 = add_mi_node_child( node1, MI_DUP_VALUE, "IP", 2, p, len); if (node2==0) goto error; p = ip_addr2a(&blr->ip_net.mask); len = p?strlen(p):0; node2 = add_mi_node_child( node1, MI_DUP_VALUE, "Mask", 4, p, len); if (node2==0) goto error; p= int2str((unsigned long)blr->proto, &len); node2 = add_mi_node_child( node1, MI_DUP_VALUE, "Proto", 5, p,len); if (node2==0) goto error; p= int2str((unsigned long)blr->port, &len); node2 = add_mi_node_child( node1, MI_DUP_VALUE, "Port", 4, p,len); if (node2==0) goto error; if (blr->body.s) { node2 = add_mi_node_child( node1, MI_DUP_VALUE, "Match", 5, blr->body.s, blr->body.len); if (node2==0) goto error; } if (blst_heads[i].flags&BL_DO_EXPIRE) { p= int2str((unsigned long)blr->expire_end, &len); node2 = add_mi_node_child( node1, MI_DUP_VALUE, "Expire", 6, p, len); if (node2==0) goto error; } } if( !(blst_heads[i].flags&BL_READONLY_LIST) ) { lock_get( blst_heads[i].lock ); blst_heads[i].count_read--; lock_release(blst_heads[i].lock); } } return rpl_tree; error: if( !(blst_heads[i].flags&BL_READONLY_LIST) ) { lock_get( blst_heads[i].lock ); blst_heads[i].count_read--; lock_release(blst_heads[i].lock); } free_mi_tree(rpl_tree); return 0; }
doublereal GibbsExcessVPSSTP::err(std::string msg) const { throw CanteraError("GibbsExcessVPSSTP","Base class method " +msg+" called. Equation of state type: "+int2str(eosType())); return 0; }
/* * * @param file Pointer to the file * @param debug Turn on debug printing * * @ingroup inputfiles */ void ct2ctml(const char* file, const int debug) { #ifdef HAS_NO_PYTHON /* * Section to bomb out if python is not * present in the computation environment. */ string ppath = file; throw CanteraError("ct2ctml", "python cti to ctml conversion requested for file, " + ppath + ", but not available in this computational environment"); #endif time_t aclock; time( &aclock ); int ia = static_cast<int>(aclock); string path = tmpDir()+"/.cttmp"+int2str(ia)+".pyw"; ofstream f(path.c_str()); if (!f) { throw CanteraError("ct2ctml","cannot open "+path+" for writing."); } f << "from ctml_writer import *\n" << "import sys, os, os.path\n" << "file = \"" << file << "\"\n" << "base = os.path.basename(file)\n" << "root, ext = os.path.splitext(base)\n" << "dataset(root)\n" << "execfile(file)\n" << "write()\n"; f.close(); string logfile = tmpDir()+"/ct2ctml.log"; #ifdef _WIN32 string cmd = pypath() + " " + "\"" + path + "\"" + "> " + logfile + " 2>&1"; #else string cmd = "sleep " + sleep() + "; " + "\"" + pypath() + "\"" + " " + "\"" + path + "\"" + " &> " + logfile; #endif #ifdef DEBUG_PATHS writelog("ct2ctml: executing the command " + cmd + "\n"); #endif if (debug > 0) { writelog("ct2ctml: executing the command " + cmd + "\n"); writelog("ct2ctml: the Python command is: " + pypath() + "\n"); } int ierr = 0; try { ierr = system(cmd.c_str()); } catch (...) { ierr = -10; if (debug > 0) { writelog("ct2ctml: command execution failed.\n"); } } /* * This next section may seem a bit weird. However, it is in * response to an issue that arises when running cantera with * cygwin, using cygwin's python intepreter. Basically, the * xml file is written to the local directory by the last * system command. Then, the xml file is read immediately * after by an ifstream() c++ command. Unfortunately, it seems * that the directory info is not being synched fast enough so * that the ifstream() read fails, even though the file is * actually there. Putting in a sleep system call here fixes * this problem. Also, having the xml file pre-existing fixes * the problem as well. There may be more direct ways to fix * this bug; however, I am not aware of them. * HKM -> During the solaris port, I found the same thing. * It probably has to do with NFS syncing problems. * 3/3/06 */ #ifndef _WIN32 string sss = sleep(); if (debug > 0) { writelog("sleeping for " + sss + " secs+\n"); } cmd = "sleep " + sss; try { ierr = system(cmd.c_str()); } catch (...) { ierr = -10; writelog("ct2ctml: command execution failed.\n"); } #else // This command works on windows machines if Windows.h and Winbase.h are included // Sleep(5000); #endif // show the contents of the log file on the screen try { char ch=0; string s = ""; ifstream ferr("ct2ctml.log"); if (ferr) { while (!ferr.eof()) { ferr.get(ch); s += ch; if (ch == '\n') { writelog(s); s = ""; } } ferr.close(); } else { if (debug > 0) { writelog("cannot open ct2ctml.log for reading.\n"); } } } catch (...) { writelog("ct2ctml: caught something \n");; } if (ierr != 0) { string msg = cmd; writelog("ct2ctml: throw cantera error \n");; throw CanteraError("ct2ctml", "could not convert input file to CTML.\n " "Command line was: \n" + msg); } // if the conversion succeeded and DEBUG_PATHS is not defined, // then clean up by deleting the temporary Python file. #ifndef DEBUG_PATHS //#ifdef _WIN32 //cmd = "cmd /C rm " + path; if (debug == 0) remove(path.c_str()); else { writelog("ct2ctml: retaining temporary file "+path+"\n"); } #else if (debug > 0) { writelog("ct2ctml: retaining temporary file "+path+"\n"); } #endif }
/** * Find the solution to F(X) = 0 by damped Newton iteration. On * entry, x0 contains an initial estimate of the solution. On * successful return, x1 contains the converged solution. */ int MultiNewton::solve(doublereal* x0, doublereal* x1, OneDim& r, MultiJac& jac, int loglevel) { clock_t t0 = clock(); int m = 0; bool forceNewJac = false; doublereal s1=1.e30; doublereal* x = getWorkArray(); doublereal* stp = getWorkArray(); doublereal* stp1 = getWorkArray(); copy(x0, x0 + m_n, x); bool frst = true; doublereal rdt = r.rdt(); int j0 = jac.nEvals(); while (1 > 0) { // Check whether the Jacobian should be re-evaluated. if (jac.age() > m_maxAge) { if (loglevel > 0) writelog("\nMaximum Jacobian age reached ("+int2str(m_maxAge)+")\n"); forceNewJac = true; } if (forceNewJac) { r.eval(-1, x, stp, 0.0, 0); jac.eval(x, stp, 0.0); jac.updateTransient(rdt, DATA_PTR(r.transientMask())); forceNewJac = false; } // compute the undamped Newton step step(x, stp, r, jac, loglevel-1); // increment the Jacobian age jac.incrementAge(); // damp the Newton step m = dampStep(x, stp, x1, stp1, s1, r, jac, loglevel-1, frst); if (loglevel == 1 && m >= 0) { if (frst) { sprintf(m_buf,"\n\n %10s %10s %5s ", "log10(ss)","log10(s1)","N_jac"); writelog(m_buf); sprintf(m_buf,"\n ------------------------------------"); writelog(m_buf); } doublereal ss = r.ssnorm(x, stp); sprintf(m_buf,"\n %10.4f %10.4f %d ", log10(ss),log10(s1),jac.nEvals()); writelog(m_buf); } frst = false; // Successful step, but not converged yet. Take the damped // step, and try again. if (m == 0) { copy(x1, x1 + m_n, x); } // convergence else if (m == 1) goto done; // If dampStep fails, first try a new Jacobian if an old // one was being used. If it was a new Jacobian, then // return -1 to signify failure. else if (m < 0) { if (jac.age() > 1) { forceNewJac = true; if (loglevel > 0) writelog("\nRe-evaluating Jacobian, since no damping " "coefficient\ncould be found with this Jacobian.\n"); } else goto done; } } done: if (m < 0) { copy(x, x + m_n, x1); } if (m > 0 && jac.nEvals() == j0) m = 100; releaseWorkArray(x); releaseWorkArray(stp); releaseWorkArray(stp1); m_elapsed += (clock() - t0)/(1.0*CLOCKS_PER_SEC); return m; }
void AmB2BSession::onSipReply(const AmSipRequest& req, const AmSipReply& reply, AmBasicSipDialog::Status old_dlg_status) { TransMap::iterator t = relayed_req.find(reply.cseq); bool fwd = (t != relayed_req.end()) && (reply.code != 100); DBG("onSipReply: %s -> %i %s (fwd=%s), c-t=%s\n", reply.cseq_method.c_str(), reply.code,reply.reason.c_str(), fwd?"true":"false",reply.body.getCTStr().c_str()); if(!dlg->getRemoteTag().empty() && dlg->getRemoteTag() != reply.to_tag) { DBG("sess %p received %i reply with != to-tag: %s (remote-tag:%s)", this, reply.code, reply.to_tag.c_str(),dlg->getRemoteTag().c_str()); return; // drop packet } if( ((reply.cseq_method == SIP_METH_SUBSCRIBE) || (reply.cseq_method == SIP_METH_NOTIFY) || (reply.cseq_method == SIP_METH_REFER)) && !subs->onReplyIn(req,reply) ) { DBG("subs.onReplyIn returned false\n"); return; } if(fwd) { updateRefreshMethod(reply.hdrs); AmSipReply n_reply = reply; n_reply.cseq = t->second.cseq; DBG("relaying B2B SIP reply %u %s\n", n_reply.code, n_reply.reason.c_str()); relayEvent(new B2BSipReplyEvent(n_reply, true, t->second.method, getLocalTag())); if(reply.code >= 200) { if ((reply.code < 300) && (t->second.method == SIP_METH_INVITE)) { DBG("not removing relayed INVITE transaction yet...\n"); } else { //grab cseq-mqpping in case of REFER if((reply.code < 300) && (reply.cseq_method == SIP_METH_REFER)) { if(subs->subscriptionExists(SingleSubscription::Subscriber, "refer",int2str(reply.cseq))) { // remember mapping for refer event package event-id insertMappedReferID(reply.cseq,t->second.cseq); } } relayed_req.erase(t); } } } else { AmSession::onSipReply(req, reply, old_dlg_status); AmSipReply n_reply = reply; if(est_invite_cseq == reply.cseq){ n_reply.cseq = est_invite_other_cseq; } else { // correct CSeq for 100 on relayed request (FIXME: why not relayed above?) if (t != relayed_req.end()) n_reply.cseq = t->second.cseq; else { // the reply here will not have the proper cseq for the other side. // We should avoid collisions of CSeqs - painful in comparsions with // est_invite_cseq where are compared CSeq numbers in different // directions. Under presumption that 0 is not used we can use it // as 'unspecified cseq' (according to RFC 3261 this seems to be valid // value so it need not to work always) n_reply.cseq = 0; } } DBG("relaying B2B SIP reply %u %s\n", n_reply.code, n_reply.reason.c_str()); relayEvent(new B2BSipReplyEvent(n_reply, false, reply.cseq_method, getLocalTag())); } }
int AmB2BSession::relaySip(const AmSipRequest& req) { AmMimeBody body(req.body); if ((req.method == SIP_METH_INVITE || req.method == SIP_METH_UPDATE || req.method == SIP_METH_ACK || req.method == SIP_METH_PRACK)) { updateLocalBody(body); } if (req.method != "ACK") { relayed_req[dlg->cseq] = req; const string* hdrs = &req.hdrs; string m_hdrs; // translate RAck for PRACK if (req.method == SIP_METH_PRACK && req.rseq) { TransMap::iterator t; for (t=relayed_req.begin(); t != relayed_req.end(); t++) { if (t->second.cseq == req.rack_cseq) { m_hdrs = req.hdrs + SIP_HDR_COLSP(SIP_HDR_RACK) + int2str(req.rseq) + " " + int2str(t->first) + " " + req.rack_method + CRLF; hdrs = &m_hdrs; break; } } if (t==relayed_req.end()) { WARN("Transaction with CSeq %d not found for translating RAck cseq\n", req.rack_cseq); } } DBG("relaying SIP request %s %s\n", req.method.c_str(), req.r_uri.c_str()); int err = dlg->sendRequest(req.method, &body, *hdrs, SIP_FLAGS_VERBATIM); if(err < 0){ ERROR("dlg->sendRequest() failed\n"); return err; } if ((req.method == SIP_METH_INVITE || req.method == SIP_METH_UPDATE) && !req.body.empty()) { saveSessionDescription(req.body); } } else { //its a (200) ACK TransMap::iterator t = relayed_req.begin(); while (t != relayed_req.end()) { if (t->second.cseq == req.cseq) break; t++; } if (t == relayed_req.end()) { ERROR("transaction for ACK not found in relayed requests\n"); // FIXME: local body (if updated) should be discarded here return -1; } DBG("sending relayed 200 ACK\n"); int err = dlg->send_200_ack(t->first, &body, req.hdrs, SIP_FLAGS_VERBATIM); if(err < 0) { ERROR("dlg->send_200_ack() failed\n"); return err; } if (!req.body.empty() && (t->second.method == SIP_METH_INVITE)) { // delayed SDP negotiation - save SDP saveSessionDescription(req.body); } relayed_req.erase(t); } return 0; }
void AmB2BSession::onSipRequest(const AmSipRequest& req) { bool fwd = sip_relay_only && (req.method != SIP_METH_CANCEL); if( ((req.method == SIP_METH_SUBSCRIBE) || (req.method == SIP_METH_NOTIFY) || (req.method == SIP_METH_REFER)) && !subs->onRequestIn(req) ) { return; } if(!fwd) AmSession::onSipRequest(req); else { updateRefreshMethod(req.hdrs); if(req.method == SIP_METH_BYE) onBye(req); } B2BSipRequestEvent* r_ev = new B2BSipRequestEvent(req,fwd); if (fwd) { DBG("relaying B2B SIP request (fwd) %s %s\n", r_ev->req.method.c_str(), r_ev->req.r_uri.c_str()); if(r_ev->req.method == SIP_METH_NOTIFY) { string event = getHeader(r_ev->req.hdrs,SIP_HDR_EVENT,true); string id = get_header_param(event,"id"); event = strip_header_params(event); if(event == "refer" && !id.empty()) { int id_int=0; if(str2int(id,id_int)) { unsigned int mapped_id=0; if(getMappedReferID(id_int,mapped_id)) { removeHeader(r_ev->req.hdrs,SIP_HDR_EVENT); r_ev->req.hdrs += SIP_HDR_COLSP(SIP_HDR_EVENT) "refer;id=" + int2str(mapped_id) + CRLF; } } } } int res = relayEvent(r_ev); if (res == 0) { // successfuly relayed, store the request if(req.method != SIP_METH_ACK) recvd_req.insert(std::make_pair(req.cseq,req)); } else { // relay failed, generate error reply DBG("relay failed, replying error\n"); AmSipReply n_reply; errCode2RelayedReply(n_reply, res, 500); dlg->reply(req, n_reply.code, n_reply.reason); } return; } DBG("relaying B2B SIP request %s %s\n", r_ev->req.method.c_str(), r_ev->req.r_uri.c_str()); relayEvent(r_ev); }
/* return the selected group instance */ int cfg_selected_inst(str *res, select_t *s, struct sip_msg *msg) { cfg_group_t *group; cfg_group_inst_t *inst; if (msg == NULL) { /* fixup call */ /* one parameter is mandatory: group name */ if (s->n != 2) { LOG(L_ERR, "ERROR: selected_inst(): One parameter is expected\n"); return -1; } if (s->params[1].type != SEL_PARAM_STR) { LOG(L_ERR, "ERROR: selected_inst(): string parameter is expected\n"); return -1; } /* look-up the group and the variable */ if (!(group = cfg_lookup_group(s->params[1].v.s.s, s->params[1].v.s.len))) { if (cfg_shmized) { LOG(L_ERR, "ERROR: selected_inst(): unknown configuration group: %.*s\n", s->params[1].v.s.len, s->params[1].v.s.s); return -1; } /* The group was not found, add it to the non-fixed select list. * So we act as if the fixup was successful, and we retry it later */ if (cfg_new_select(&s->params[1].v.s, NULL, &s->params[1].v.p, NULL)) return -1; LOG(L_DBG, "DEBUG: selected_inst(): select fixup is postponed: %.*s\n", s->params[1].v.s.len, s->params[1].v.s.s); s->params[1].type = SEL_PARAM_PTR; s->params[1].v.p = NULL; return 0; } s->params[1].type = SEL_PARAM_PTR; s->params[1].v.p = (void *)group; return 1; } group = (cfg_group_t *)s->params[1].v.p; if (!group) return -1; /* Get the current group instance from the group handle. */ inst = CFG_HANDLE_TO_GINST(*(group->handle)); if (inst) { res->s = int2str(inst->id, &res->len); } else { res->s = ""; res->len = 0; } return 0; }
/*! \brief * Allocate a memory buffer and print Contact * header fields into it */ int build_contact(sip_msg_t *msg, ucontact_t* c, str *host) { char *p, *cp; char *a; int fl, len; str user; str inst; unsigned int ahash; unsigned short digit; int mode; sr_xavp_t **xavp=NULL; sr_xavp_t *list=NULL; sr_xavp_t *new_xavp=NULL; str xname = {"ruid", 4}; str ename = {"expires", 7}; sr_xval_t xval; if(msg!=NULL && parse_supported(msg)==0 && (get_supported(msg) & F_OPTION_TAG_GRUU)) mode = 1; else mode = 0; contact.data_len = calc_buf_len(c, host, mode); if (!contact.data_len) return 0; if (!contact.buf || (contact.buf_len < contact.data_len)) { if (contact.buf) pkg_free(contact.buf); contact.buf = (char*)pkg_malloc(contact.data_len); if (!contact.buf) { contact.data_len = 0; contact.buf_len = 0; LM_ERR("no pkg memory left\n"); return -1; } else { contact.buf_len = contact.data_len; } } p = contact.buf; memcpy(p, CONTACT_BEGIN, CONTACT_BEGIN_LEN); p += CONTACT_BEGIN_LEN; /* add xavp with details of the record (ruid, ...) */ if(reg_xavp_rcd.s!=NULL) { list = xavp_get(®_xavp_rcd, NULL); xavp = list ? &list->val.v.xavp : &new_xavp; } fl = 0; while(c) { if (VALID_CONTACT(c, act_time)) { if (fl) { memcpy(p, CONTACT_SEP, CONTACT_SEP_LEN); p += CONTACT_SEP_LEN; } else { fl = 1; } *p++ = '<'; memcpy(p, c->c.s, c->c.len); p += c->c.len; *p++ = '>'; len = len_q(c->q); if (len) { memcpy(p, Q_PARAM, Q_PARAM_LEN); p += Q_PARAM_LEN; memcpy(p, q2str(c->q, 0), len); p += len; } memcpy(p, EXPIRES_PARAM, EXPIRES_PARAM_LEN); p += EXPIRES_PARAM_LEN; cp = int2str((int)(c->expires - act_time), &len); memcpy(p, cp, len); p += len; if (rcv_param.len>0 && c->received.s) { *p++ = ';'; memcpy(p, rcv_param.s, rcv_param.len); p += rcv_param.len; *p++ = '='; *p++ = '\"'; memcpy(p, c->received.s, c->received.len); p += c->received.len; *p++ = '\"'; } if (reg_gruu_enabled==1 && c->instance.len>0 && mode==1) { user.s = c->aor->s; a = memchr(c->aor->s, '@', c->aor->len); if(a!=NULL) { user.len = a - user.s; } else { user.len = c->aor->len; } /* pub-gruu */ memcpy(p, PUB_GRUU_PARAM, PUB_GRUU_PARAM_LEN); p += PUB_GRUU_PARAM_LEN; *p++ = '\"'; memcpy(p, "sip:", 4); p += 4; if(a!=NULL) { memcpy(p, c->aor->s, c->aor->len); p += c->aor->len; } else { memcpy(p, user.s, user.len); p += user.len; *p++ = '@'; memcpy(p, host->s, host->len); p += host->len; } memcpy(p, GR_PARAM, GR_PARAM_LEN); p += GR_PARAM_LEN; inst = c->instance; if(inst.s[0]=='<' && inst.s[inst.len-1]=='>') { inst.s++; inst.len -= 2; } memcpy(p, inst.s, inst.len); p += inst.len; *p++ = '\"'; /* temp-gruu */ memcpy(p, TMP_GRUU_PARAM, TMP_GRUU_PARAM_LEN); p += TMP_GRUU_PARAM_LEN; *p++ = '\"'; memcpy(p, "sip:", 4); p += 4; memcpy(p, c->ruid.s, c->ruid.len); p += c->ruid.len; *p++ = '-'; ahash = ul.get_aorhash(c->aor); while(ahash!=0) { digit = ahash & 0x0f; *p++ = (digit >= 10) ? digit + 'a' - 10 : digit + '0'; ahash >>= 4; } *p++ = '@'; memcpy(p, host->s, host->len); p += host->len; memcpy(p, GR_PARAM, GR_PARAM_LEN); p += GR_PARAM_LEN - 1; *p++ = '\"'; } if (c->instance.len>0) { /* +sip-instance */ memcpy(p, SIP_INSTANCE_PARAM, SIP_INSTANCE_PARAM_LEN); p += SIP_INSTANCE_PARAM_LEN; *p++ = '\"'; memcpy(p, c->instance.s, c->instance.len); p += c->instance.len; *p++ = '\"'; } if (c->reg_id>0) { /* reg-id */ memcpy(p, REG_ID_PARAM, REG_ID_PARAM_LEN); p += REG_ID_PARAM_LEN; cp = int2str(c->reg_id, &len); memcpy(p, cp, len); p += len; } if(reg_xavp_rcd.s!=NULL) { memset(&xval, 0, sizeof(sr_xval_t)); xval.type = SR_XTYPE_STR; xval.v.s = c->ruid; if(xavp_add_value(&xname, &xval, xavp)==NULL) { LM_ERR("cannot add ruid value to xavp\n"); } /* Add contact expiry */ memset(&xval, 0, sizeof(sr_xval_t)); xval.type = SR_XTYPE_INT; xval.v.i = (int)(c->expires - act_time); if(xavp_add_value(&ename, &xval, xavp)==NULL) { LM_ERR("cannot add expires value to xavp\n"); } } } c = c->next; }
void CEMQtyAtExam::OnExportSelect(){ _debug(_T("%s"), CString(typeid(this).name())); CHMSMainFrame *pMF = (CHMSMainFrame*) AfxGetMainWnd(); UpdateData(true); CRecord rs(&pMF->m_db); CString szSQL, szTemp, tmpStr; CExcel xls; BeginWaitCursor(); szSQL = GetQueryString(); rs.ExecSQL(szSQL); _fmsg(_T("%s"), szSQL); xls.CreateSheet(1); xls.SetWorksheet(0); xls.SetColumnWidth(0, 7); xls.SetColumnWidth(1, 30); xls.SetColumnWidth(2, 15 ); xls.SetColumnWidth(3, 15); xls.SetColumnWidth(4, 15); xls.SetColumnWidth(5, 15); int nRow = 0, nCol = 0; xls.SetCellMergedColumns(nCol, nRow, 4); xls.SetCellMergedColumns(nCol, nRow + 1, 4); xls.SetCellText(nCol, nRow, pMF->m_CompanyInfo.sc_pname, FMT_TEXT | FMT_CENTER, true, 10); xls.SetCellText(nCol, nRow + 1, pMF->m_CompanyInfo.sc_name, FMT_TEXT | FMT_CENTER, true, 10); xls.SetCellMergedColumns(nCol, nRow + 2, 4); xls.SetCellMergedColumns(nCol, nRow + 3, 4); xls.SetCellText(nCol, nRow + 2, _T("KH\xC1M T\x1EA0I \x43\xC1\x43 PH\xD2NG TH\x45O \x42\xC1\x43 S\x1EF8"), FMT_TEXT | FMT_CENTER, true, 13); tmpStr.Format(_T("T\x1EEB ng\xE0y: %s \x110\x1EBFn ng\xE0y: %s"), CDateTime::Convert(m_szFromDate, yyyymmdd|hhmmss, ddmmyyyy|hhmmss), CDateTime::Convert(m_szToDate, yyyymmdd|hhmmss, ddmmyyyy|hhmmss)); xls.SetCellText(nCol, nRow + 3, tmpStr, FMT_TEXT | FMT_CENTER, true, 11); xls.SetCellText(nCol, nRow + 4, _T("STT"), FMT_TEXT | FMT_CENTER, true, 11); xls.SetCellText(nCol + 1, nRow + 4, _T("\x42\xE1\x63 s\x1EF9"), FMT_TEXT | FMT_CENTER, true, 11); xls.SetCellText(nCol + 2, nRow + 4, _T("Ph\xF2ng kh\xE1m"), FMT_TEXT | FMT_CENTER, true, 11); xls.SetCellText(nCol + 3, nRow + 4, _T("Qu\xE2n"), FMT_TEXT | FMT_CENTER, true, 11); xls.SetCellText(nCol + 4, nRow + 4, _T("H\x1B0u"), FMT_TEXT | FMT_CENTER, true, 11); xls.SetCellText(nCol + 5, nRow + 4, _T("T\x1ED5ng"), FMT_TEXT | FMT_CENTER, true, 11); nRow += 5; int nIndex = 1; int nTotal1 = 0,nTotal2 = 0, nTotal3 = 0 ; while (!rs.IsEOF()) { szTemp.Format(_T("%d"), nIndex); xls.SetCellText(nCol, nRow, szTemp, FMT_INTEGER); szTemp = rs.GetValue(_T("doctorname")); xls.SetCellText(nCol + 1, nRow, szTemp, FMT_TEXT); szTemp = rs.GetValue(_T("bhquan")); nTotal1 += ToInt(szTemp); xls.SetCellText(nCol + 3, nRow, szTemp, FMT_NUMBER1); szTemp = rs.GetValue(_T("bhhuu")); nTotal2 += ToInt(szTemp); xls.SetCellText(nCol + 4, nRow, szTemp, FMT_NUMBER1); szTemp = rs.GetValue(_T("tongso")); nTotal3 += ToInt(szTemp); xls.SetCellText(nCol + 5, nRow, szTemp, FMT_NUMBER1); nIndex++; nRow++; rs.MoveNext(); } xls.SetCellMergedColumns(nCol, nRow, 2); xls.SetCellText(nCol, nRow, _T("T\x1ED5ng \x63\x1ED9ng"), FMT_TEXT | FMT_CENTER, true, 12); xls.SetCellText(nCol + 3, nRow, int2str(nTotal1), FMT_NUMBER1, true, 12 ); xls.SetCellText(nCol + 4, nRow, int2str(nTotal2), FMT_NUMBER1, true, 12 ); xls.SetCellText(nCol + 5, nRow, int2str(nTotal3), FMT_NUMBER1, true, 12 ); EndWaitCursor(); xls.Save(_T("Exports\\Tinh hinh kham benh theo bac sy.xls")); }
ssize_t pfs_read(int filedes, void *buf, ssize_t nbyte, off_t offset, int *cache_hit) {//READ filename w offset length END. *cache_hit = readcache(filedes, offset, nbyte);//what's the usage of filedes here???? if(*cache_hit) return nbyte;//cachehit int ofI = 0; while((ofI < ofnum)&&(openfiles[ofI]->fd != filedes)) ofI++; if(ofI == ofnum) return -1; OpenFile* of = openfiles[ofI]; char spacket[BUFFER_SIZE]; //Buffer for client data /* char Offset[7]; char Length[7]; strcat(spacket,"READ "); strcat(spacket, of->filename); int2str(offset/ONEKB,Offset,10); int2str(nbyte/ONEKB,Length,10); strcat(spacket, Offset); strcat(spacket, " "); strcat(spacket, Length); strcat(spacket, " "); strcat(spacket," END."); if (send(mmFD, spacket, sizeof(spacket), 0) == -1) //READ pfs_file1 offset length END. perror("Error in sending!"); char rpacket[BUFFER_SIZE] = ""; //Buffer for client data int size = MMR(rpacket, BUFFER_SIZE);//READ filename offset length END. */ //offset ... nbyte //start = fsoffset + offset/(size*ONEKB), offset -> fsoffset + (offset+length)/(size*ONEKB) //first: offset % (size*ONEKB) -> min(offset+length, size*ONEKB) //intermediates: //last: 0 -> (offset+length)%(size*ONEKB) unsigned fsstart, from, to, plen; unsigned os = offset; unsigned len = nbyte; int i; for(i= of->fsoffset + (offset/(STRIP_SIZE*ONEKB)); (i-of->fsoffset)*(STRIP_SIZE*ONEKB) < (offset+nbyte); i++) {//Send for each FSs -> READ pfs_file1 w from to(plen) END. //if (!fork()) //{ // this is the child process // close(myTFD); // child doesn't need the listener strcpy(spacket,"READ "); strcat(spacket, of->filename); strcat(spacket, " "); strcat(spacket, of->mode); strcat(spacket, " "); //0 ,1 ,2 ,3 + 4 ,5 ,6 ,7 + 8 ,9 ,10,11 //12,13,14,15 + 16,17,18,19 + 20,21,22,23 //24,25,26,27 + 28,29,30,31 + 32,33,34,35 //os=19->32 -> l=13, i=4, sw=3, fsstart = (i/of->stripe_width)*(STRIP_SIZE*ONEKB); from = fsstart + os%(STRIP_SIZE*ONEKB); to = fsstart + min(os%(STRIP_SIZE*ONEKB)+len, STRIP_SIZE*ONEKB); plen = to - from; char From[10]; char PLen[10]; int2str(from, From, 10); int2str(plen, PLen, 10); strcat(spacket, From); strcat(spacket, " "); strcat(spacket, PLen); strcat(spacket, " END."); if (send(fs[i%of->stripe_width].fd, spacket, sizeof(spacket), 0) == -1) perror("Error in sending!"); // close(newfd); // exit(0); //} int size; char rpacket[plen]; //Buffer for client data if ((size = recv(fs[i%of->stripe_width].fd, rpacket, sizeof(rpacket), 0)) == -1) perror("Error in receiving!"); rpacket[size] = '\0'; printf("Server: %s\n",rpacket); strncat(buf, rpacket, plen); save2cache(filedes,os,plen); os += plen; len -= plen; } return nbyte; }