📄 ul_fifo.c
字号:
int static ul_rm( FILE *pipe, char *response_file ){ char table[MAX_TABLE]; char user[MAX_USER]; udomain_t* d; str aor, t; char* at; if (!read_line(table, MAX_TABLE, pipe, &t.len) || t.len ==0) { fifo_reply(response_file, "400 ul_rm: table name expected\n"); LOG(L_ERR, "ERROR: ul_rm: table name expected\n"); return 1; } if (!read_line(user, MAX_USER, pipe, &aor.len) || aor.len==0) { fifo_reply(response_file, "400 ul_rm: user name expected\n"); LOG(L_ERR, "ERROR: ul_rm: user name expected\n"); return 1; } at = memchr(user, '@', aor.len); if (use_domain) { if (!at) { fifo_reply(response_file, "400 ul_rm: username@domain expected\n"); LOG(L_ERR, "ERROR: ul_rm: Domain missing\n"); return 1; } } else { if (at) { aor.len = at - user; } } aor.s = user; strlower(&aor); t.s = table; fifo_find_domain(&t, &d); LOG(L_INFO, "INFO: deleting user-loc (%s,%s)\n", table, user ); if (d) { lock_udomain(d); if (delete_urecord(d, &aor) < 0) { LOG(L_ERR, "ul_rm(): Error while deleting user %s\n", user); unlock_udomain(d); fifo_reply(response_file, "500 Error while deleting user %s\n", user); return 1; } unlock_udomain(d); fifo_reply(response_file, "200 user (%s, %s) deleted\n", table, user); return 1; } else { fifo_reply(response_file, "400 table (%s) not found\n", table); return 1; }}static int ul_rm_contact(FILE* pipe, char* response_file){ char table[MAX_TABLE]; char user[MAX_USER]; char contact[MAX_CONTACT_LEN]; udomain_t* d; urecord_t* r; ucontact_t* con; str aor, t, c; int res; char* at; if (!read_line(table, MAX_TABLE, pipe, &t.len) || t.len ==0) { fifo_reply(response_file, "400 ul_rm_contact: table name expected\n"); LOG(L_ERR, "ERROR: ul_rm_contact: table name expected\n"); return 1; } if (!read_line(user, MAX_USER, pipe, &aor.len) || aor.len==0) { fifo_reply(response_file, "400 ul_rm_contact: user name expected\n"); LOG(L_ERR, "ERROR: ul_rm_contact: user name expected\n"); return 1; } at = memchr(user, '@', aor.len); if (use_domain) { if (!at) { fifo_reply(response_file, "400 ul_rm_contact: user@domain expected\n"); LOG(L_ERR, "ERROR: ul_rm_contact: Domain missing\n"); return 1; } } else { if (at) { aor.len = at - user; } } if (!read_line(contact, MAX_CONTACT_LEN, pipe, &c.len) || c.len == 0) { fifo_reply(response_file, "400 ul_rm_contact: contact expected\n"); LOG(L_ERR, "ERROR: ul_rm_contact: contact expected\n"); return 1; } aor.s = user; strlower(&aor); t.s = table; c.s = contact; fifo_find_domain(&t, &d); LOG(L_INFO, "INFO: deleting user-loc contact (%s,%s,%s)\n", table, user, contact ); if (d) { lock_udomain(d); res = get_urecord(d, &aor, &r); if (res < 0) { fifo_reply(response_file, "500 Error while looking for username %s in table %s\n", user, table); LOG(L_ERR, "ERROR: ul_rm_contact: Error while looking for username %s in table %s\n", user, table); unlock_udomain(d); return 1; } if (res > 0) { fifo_reply(response_file, "404 Username %s in table %s not found\n", user, table); unlock_udomain(d); return 1; } res = get_ucontact(r, &c, &con); if (res < 0) { fifo_reply(response_file, "500 Error while looking for contact %s\n", contact); LOG(L_ERR, "ERROR: ul_rm_contact: Error while looking for contact %s\n", contact); unlock_udomain(d); return 1; } if (res > 0) { fifo_reply(response_file, "404 Contact %s in table %s not found\n", contact, table); unlock_udomain(d); return 1; } if (delete_ucontact(r, con) < 0) { fifo_reply(response_file, "500 ul_rm_contact: Error while deleting contact %s\n", contact); unlock_udomain(d); return 1; } release_urecord(r); unlock_udomain(d); fifo_reply(response_file, "200 Contact (%s, %s) deleted from table %s\n", user, contact, table); return 1; } else { fifo_reply(response_file, "400 table (%s) not found\n", table); return 1; }}/* * Build Contact HF for reply */static inline int print_contacts(FILE* _o, ucontact_t* _c){ int cnt = 0; while(_c) { if (VALID_CONTACT(_c, act_time)) { cnt++; if (cnt==1) { fputs( "200 OK\n", _o); } fprintf(_o, "<%.*s>;q=%s;expires=%d\n", _c->c.len, ZSW(_c->c.s), q2str(_c->q, 0), (int)(_c->expires - act_time)); } _c = _c->next; } return cnt;}static inline int ul_show_contact(FILE* pipe, char* response_file){ char table[MAX_TABLE]; char user[MAX_USER]; FILE* reply_file; udomain_t* d; urecord_t* r; int res; str t, aor; char* at; if (!read_line(table, MAX_TABLE, pipe, &t.len) || t.len ==0) { fifo_reply(response_file, "400 ul_show_contact: table name expected\n"); LOG(L_ERR, "ERROR: ul_show_contact: table name expected\n"); return 1; } if (!read_line(user, MAX_USER, pipe, &aor.len) || aor.len==0) { fifo_reply(response_file, "400 ul_show_contact: user name expected\n"); LOG(L_ERR, "ERROR: ul_show_contact: user name expected\n"); return 1; } at = memchr(user, '@', aor.len); if (use_domain) { if (!at) { fifo_reply(response_file, "400 ul_show_contact: user@domain expected\n"); LOG(L_ERR, "ERROR: ul_show_contact: Domain missing\n"); return 1; } } else { if (at) { aor.len = at - user; } } aor.s = user; strlower(&aor); t.s = table; fifo_find_domain(&t, &d); if (d) { lock_udomain(d); res = get_urecord(d, &aor, &r); if (res < 0) { fifo_reply(response_file, "500 Error while looking for username %s in table %s\n", user, table); LOG(L_ERR, "ERROR: ul_show_contact: Error while looking for username %s in table %s\n", user, table); unlock_udomain(d); return 1; } if (res > 0) { fifo_reply(response_file, "404 Username %s in table %s not found\n", user, table); unlock_udomain(d); return 1; } get_act_time(); reply_file=open_reply_pipe(response_file); if (reply_file==0) { LOG(L_ERR, "ERROR: ul_show_contact: file not opened\n"); unlock_udomain(d); return 1; } if (!print_contacts(reply_file, r->contacts)) { unlock_udomain(d); fprintf(reply_file, "404 No registered contacts found\n"); fclose(reply_file); return 1; } fclose(reply_file); unlock_udomain(d); return 1; } else { fifo_reply(response_file, "400 table (%s) not found\n", table); return 1; }}int init_ul_fifo( void ) { if (register_fifo_cmd(ul_stats_cmd, UL_STATS, 0) < 0) { LOG(L_CRIT, "cannot register ul_stats\n"); return -1; } if (register_fifo_cmd(ul_rm, UL_RM, 0) < 0) { LOG(L_CRIT, "cannot register ul_rm\n"); return -1; } if (register_fifo_cmd(ul_rm_contact, UL_RM_CONTACT, 0) < 0) { LOG(L_CRIT, "cannot register ul_rm_contact\n"); return -1; } if (register_fifo_cmd(ul_dump, UL_DUMP, 0) < 0) { LOG(L_CRIT, "cannot register ul_dump\n"); return -1; } if (register_fifo_cmd(ul_flush, UL_FLUSH, 0) < 0) { LOG(L_CRIT, "cannot register ul_flush\n"); return -1; } if (register_fifo_cmd(ul_add, UL_ADD, 0) < 0) { LOG(L_CRIT, "cannot register ul_add\n"); return -1; } if (register_fifo_cmd(ul_show_contact, UL_SHOW_CONTACT, 0) < 0) { LOG(L_CRIT, "cannot register ul_show_contact\n"); return -1; } return 1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -