static int pwd_cmd( FILE *stream, char *response_file ) { char *cwd_buf; int max_len; if (!response_file) { LOG(L_ERR, "ERROR: no file for %s\n", "pwd_cmd" ); return 1; } max_len=pathmax(); cwd_buf=pkg_malloc(max_len); if (!cwd_buf) { LOG(L_ERR, "ERROR: pwd_cmd: no cwd pkg mem\n"); fifo_reply(response_file, "500 no memory\n"); return 1; } if (getcwd(cwd_buf, max_len)) { fifo_reply(response_file, "200 ok\n%s\n", cwd_buf ); } else { fifo_reply(response_file, "500 getcwd failed\n" ); } pkg_free(cwd_buf); return 1; }
static int print_version_cmd( FILE *stream, char *response_file ) { if (response_file) { - fifo_reply(response_file, "200 ok\n" SERVER_HDR CRLF ); + fifo_reply(response_file, "200 ok\n" SERVER_HDR "%s" CRLF, server_name ? server_name : UA_NAME ); } else { LOG(L_ERR, "ERROR: no file for %s\n", "print_version_cmd" ); }
/* * Fifo function to reload lcr table(s) */ static int lcr_reload ( FILE* pipe, char* response_file ) { if (reload_gws () == 1) { fifo_reply (response_file, "200 OK\n"); return 1; } else { fifo_reply (response_file, "400 Reload of gateways failed\n"); return -1; } }
int fifo_pa_watcherinfo(FILE *fifo, char *response_file) { char pdomain_s[MAX_P_URI]; char p_uri_s[MAX_P_URI]; pdomain_t *pdomain = NULL; presentity_t *presentity = NULL; str pdomain_name, p_uri; if (!read_line(pdomain_s, MAX_PDOMAIN, fifo, &pdomain_name.len) || pdomain_name.len == 0) { fifo_reply(response_file, "400 pa_watcherinfo: pdomain expected\n"); LOG(L_ERR, "ERROR: pa_watcherinfo: pdomain expected\n"); return 1; } pdomain_name.s = pdomain_s; if (!read_line(p_uri_s, MAX_P_URI, fifo, &p_uri.len) || p_uri.len == 0) { fifo_reply(response_file, "400 pa_watcherinfo: p_uri expected\n"); LOG(L_ERR, "ERROR: pa_watcherinfo: p_uri expected\n"); return 1; } p_uri.s = p_uri_s; register_pdomain(pdomain_s, &pdomain); if (!pdomain) { fifo_reply(response_file, "400 could not register pdomain\n"); LOG(L_ERR, "ERROR: pa_watcherinfo: could not register pdomain %.*s\n", pdomain_name.len, pdomain_name.s); return 1; } lock_pdomain(pdomain); find_presentity(pdomain, &p_uri, &presentity); if (presentity) { db_read_watcherinfo(presentity); } unlock_pdomain(pdomain); fifo_reply(response_file, "200 watcherinfo updated\n", "(%.*s)\n", p_uri.len, ZSW(p_uri.s)); return 1; }
static int print_version_cmd( FILE *stream, char *response_file ) { if (response_file) { fifo_reply(response_file, "200 ok\n" SERVER_HDR CRLF ); } else { LOG(L_ERR, "ERROR: no file for %s\n", "print_version_cmd" ); } return 1; }
static int kill_fifo_cmd( FILE *stream, char *response_file ) { if (response_file==0 || *response_file==0 ) { LOG(L_ERR, "ERROR: uptime_fifo_cmd: null file\n"); return -1; } fifo_reply(response_file, "200 killing now..." ); kill(0, SIGTERM); return 1; }
static unsigned int read_flag(FILE *pipe, char *response_file) { char flag_str[MAX_FLAG_LEN]; int flag_len; unsigned int flag_nr; str fs; if (!read_line(flag_str, MAX_FLAG_LEN, pipe, &flag_len) || flag_len == 0) { fifo_reply(response_file, "400: gflags: invalid flag number\n"); LOG(L_ERR, "ERROR: read_flag: invalid flag number\n"); return 0; } fs.s=flag_str;fs.len=flag_len; if (str2int(&fs, &flag_nr) < 0) { fifo_reply(response_file, "400: gflags: invalid flag format\n"); LOG(L_ERR, "ERROR: read_flag: invalid flag format\n"); return 0; } return flag_nr; }
/* diagnostic and hello-world FIFO command */ static int print_fifo_cmd( FILE *stream, char *response_file ) { char text[MAX_PRINT_TEXT]; int text_len; /* expect one line which will be printed out */ if (response_file==0 || *response_file==0 ) { LOG(L_ERR, "ERROR: print_fifo_cmd: null file\n"); return -1; } if (!read_line(text, MAX_PRINT_TEXT, stream, &text_len)) { fifo_reply(response_file, "500 print_fifo_cmd: too big text"); return -1; } /* now the work begins */ if (response_file) { fifo_reply(response_file, "200 ok\n%s\n", text ); } else { LOG(L_INFO, "INFO: print_fifo_cmd: %.*s\n", text_len, text ); } return 1; }
static int fifo_is_gflag( FILE* pipe, char* response_file ) { unsigned int flag; flag=read_flag(pipe, response_file); if (!flag) { LOG(L_ERR, "ERROR: fifo_reset_gflag: failed in read_flag\n"); return 1; } fifo_reply (response_file, "200 OK\n%s\n", ((*gflags) & (1<<flag)) ? "TRUE" : "FALSE" ); return 1; }
static int fifo_reset_gflag( FILE* pipe, char* response_file ) { unsigned int flag; flag=read_flag(pipe, response_file); if (!flag) { LOG(L_ERR, "ERROR: fifo_reset_gflag: failed in read_flag\n"); return 1; } (*gflags) &= ~ (1 << flag); fifo_reply (response_file, "200 OK\n"); return 1; }
static int uptime_fifo_cmd( FILE *stream, char *response_file ) { time_t now; if (response_file==0 || *response_file==0 ) { LOG(L_ERR, "ERROR: uptime_fifo_cmd: null file\n"); return -1; } time(&now); fifo_reply( response_file, "200 ok\n" "Now: %sUp Since: %sUp time: %.0f [sec]\n", ctime(&now), up_since_ctime, difftime(now, up_since) ); return 1; }
int fifo_pa_location(FILE *fifo, char *response_file) { char pdomain_s[MAX_P_URI]; char p_uri_s[MAX_P_URI]; char location_s[MAX_LOCATION]; pdomain_t *pdomain = NULL; presentity_t *presentity = NULL; presence_tuple_t *tuple = NULL; str pdomain_name, p_uri, location; int changed = 0; if (!read_line(pdomain_s, MAX_PDOMAIN, fifo, &pdomain_name.len) || pdomain_name.len == 0) { fifo_reply(response_file, "400 pa_location: pdomain expected\n"); LOG(L_ERR, "ERROR: pa_location: pdomain expected\n"); return 1; } pdomain_name.s = pdomain_s; if (!read_line(p_uri_s, MAX_P_URI, fifo, &p_uri.len) || p_uri.len == 0) { fifo_reply(response_file, "400 pa_location: p_uri expected\n"); LOG(L_ERR, "ERROR: pa_location: p_uri expected\n"); return 1; } p_uri.s = p_uri_s; if (!read_line(location_s, MAX_LOCATION, fifo, &location.len) || location.len == 0) { fifo_reply(response_file, "400 pa_location: location expected\n"); LOG(L_ERR, "ERROR: pa_location: location expected\n"); return 1; } location.s = location_s; register_pdomain(pdomain_s, &pdomain); if (!pdomain) { fifo_reply(response_file, "400 could not register pdomain\n"); LOG(L_ERR, "ERROR: pa_location: could not register pdomain %.*s\n", pdomain_name.len, pdomain_name.s); return 1; } lock_pdomain(pdomain); find_presentity(pdomain, &p_uri, &presentity); if (!presentity) { new_presentity(pdomain, &p_uri, &presentity); add_presentity(pdomain, presentity); changed = 1; } if (!presentity) { unlock_pdomain(pdomain); fifo_reply(response_file, "400 could not find presentity\n"); LOG(L_ERR, "ERROR: pa_location: could not find presentity %.*s\n", p_uri.len, p_uri.s); return 1; } changed = 1; for (tuple = presentity->tuples; tuple; tuple = tuple->next) { if (tuple->location.loc.len && str_strcasecmp(&tuple->location.room, &location) != 0) changed = 1; LOG(L_ERR, "Setting room of contact=%.*s to %.*s\n", tuple->contact.len, tuple->contact.s, tuple->location.room.len, tuple->location.room.s); strncpy(tuple->location.room.s, location.s, location.len); tuple->location.room.len = location.len; strncpy(tuple->location.loc.s, location.s, location.len); tuple->location.loc.len = location.len; } if (changed) { presentity->flags |= PFLAG_PRESENCE_CHANGED; } db_update_presentity(presentity); unlock_pdomain(pdomain); fifo_reply(response_file, "200 published\n", "(%.*s %.*s)\n", p_uri.len, ZSW(p_uri.s), location.len, ZSW(location.s)); return 1; }
int fifo_pa_presence(FILE *fifo, char *response_file) { char pdomain_s[MAX_P_URI]; char p_uri_s[MAX_P_URI]; char presence_s[MAX_PRESENCE]; // pdomain_t *pdomain = NULL; // presentity_t *presentity = NULL; str pdomain_name, p_uri, presence; // int origstate, newstate; // int allocated_presentity = 0; if (!read_line(pdomain_s, MAX_PDOMAIN, fifo, &pdomain_name.len) || pdomain_name.len == 0) { fifo_reply(response_file, "400 ul_add: pdomain expected\n"); LOG(L_ERR, "ERROR: ul_add: pdomain expected\n"); return 1; } pdomain_name.s = pdomain_s; if (!read_line(p_uri_s, MAX_P_URI, fifo, &p_uri.len) || p_uri.len == 0) { fifo_reply(response_file, "400 ul_add: p_uri expected\n"); LOG(L_ERR, "ERROR: ul_add: p_uri expected\n"); return 1; } p_uri.s = p_uri_s; if (!read_line(presence_s, MAX_PRESENCE, fifo, &presence.len) || presence.len == 0) { fifo_reply(response_file, "400 ul_add: presence expected\n"); LOG(L_ERR, "ERROR: ul_add: presence expected\n"); return 1; } presence.s = presence_s; #if 0 register_pdomain(pdomain_s, &pdomain); if (!pdomain) { fifo_reply(response_file, "400 could not register pdomain\n"); LOG(L_ERR, "ERROR: pa_location: could not register pdomain %.*s\n", pdomain_name.len, pdomain_name.s); return 1; } find_presentity(pdomain, &p_uri, &presentity); if (!presentity) { new_presentity(pdomain, &p_uri, &presentity); add_presentity(pdomain, presentity); allocated_presentity = 1; } if (!presentity) { fifo_reply(response_file, "400 could not find presentity %s\n", p_uri_s); LOG(L_ERR, "ERROR: pa_location: could not find presentity %.*s\n", p_uri.len, p_uri.s); return 1; } origstate = presentity->state; presentity->state = newstate = (strcasecmp(presence_s, "online") == 0) ? PS_ONLINE : PS_OFFLINE; if (origstate != newstate || allocated_presentity) { presentity->flags |= PFLAG_PRESENCE_CHANGED; } db_update_presentity(presentity); #endif fifo_reply(response_file, "200 published\n", "(%.*s %.*s)\n", p_uri.len, ZSW(p_uri.s), presence.len, ZSW(presence.s)); return 1; }
/* Fifo command example: ":get_domaincode:[response_file]\n domain_name\n authorization_to_register_domains\n \n " */ int get_domainprefix(FILE *stream, char *response_file) { db_key_t db_keys[NR_KEYS]; db_val_t db_vals[NR_KEYS]; db_op_t db_ops[NR_KEYS] = {OP_EQ, OP_EQ}; code_t code; dc_t* cell; char domain_name[256]; str sdomain; char authorization[10]; str sauth; int authorized=0; /* read a line -the domain name parameter- from the fifo */ sdomain.s = domain_name; if(!read_line(sdomain.s, 255, stream, &sdomain.len) || sdomain.len==0) { LOG(L_ERR, "PDT: get_domaincode: could not read from fifo\n"); fifo_reply(response_file, "400 |get_domaincode: could not " "read from fifo\n"); return 1; } domain_name[sdomain.len] = '\0'; /* read a line -the authorization to register new domains- from the fifo */ sauth.s = authorization; if(!read_line(sauth.s, 3, stream, &sauth.len) || sauth.len==0) { LOG(L_ERR, "PDT: get_domaincode: could not read from fifo\n"); fifo_reply(response_file, "400 |get_domaincode: could not " "read from fifo\n"); return 1; } /* see what kind of user we have */ authorized = sauth.s[0]-'0'; lock_get(&l); /* search the domain in the hashtable */ cell = get_code_from_hash(hash->dhash, hash->hash_size, domain_name); /* the domain is registered */ if(cell) { lock_release(&l); /* domain already in the database */ fifo_reply(response_file, "201 |Domain name= %.*s" "Domain code= %d%d\n", sdomain.len, sdomain.s, cell->code, code_terminator); return 0; } /* domain not registered yet */ /* user not authorized to register new domains */ if(!authorized) { lock_release(&l); fifo_reply(response_file, "203 |Domain name not registered yet\n"); return 0; } code = *next_code; *next_code = apply_correction(code+1); /* prepare for insertion into database */ db_keys[0] = DB_KEY_CODE; db_keys[1] = DB_KEY_NAME; db_vals[0].type = DB_INT; db_vals[0].nul = 0; db_vals[0].val.int_val = code; db_vals[1].type = DB_STR; db_vals[1].nul = 0; db_vals[1].val.str_val.s = sdomain.s; db_vals[1].val.str_val.len = sdomain.len; DBG("%d %.*s\n", code, sdomain.len, sdomain.s); /* insert a new domain into database */ if(db_insert(db_con, db_keys, db_vals, NR_KEYS)<0) { /* next available code is still code */ *next_code = code; lock_release(&l); LOG(L_ERR, "PDT: get_domaincode: error storing a" " new domain\n"); fifo_reply(response_file, "204 |Cannot register the new domain in a" " consistent way\n"); return -1; } /* insert the new domain into hashtables, too */ cell = new_cell(sdomain.s, code); if(add_to_double_hash(hash, cell)<0) goto error; lock_release(&l); /* user authorized to register new domains */ fifo_reply(response_file, "202 |Domain name= %.*s" " New domain code= %d%d\n", sdomain.len, sdomain.s, code, code_terminator); return 0; error: /* next available code is still code */ *next_code = code; /* delete from database */ if(db_delete(db_con, db_keys, db_ops, db_vals, NR_KEYS)<0) LOG(L_ERR,"PDT: get_domaincode: database/share-memory are inconsistent\n"); lock_release(&l); 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; } }
static int ul_add(FILE* pipe, char* response_file) { char table_s[MAX_TABLE]; char user_s[MAX_USER]; char contact_s[MAX_CONTACT_LEN]; char expires_s[MAX_EXPIRES_LEN]; char q_s[MAX_Q_LEN]; char rep_s[MAX_REPLICATE_LEN]; char flags_s[MAX_FLAGS_LEN]; udomain_t* d; int exp_i, flags_i; char* at; qvalue_t qval; str table, user, contact, expires, q, rep, flags; if (!read_line(table_s, MAX_TABLE, pipe, &table.len) || table.len == 0) { fifo_reply(response_file, "400 ul_add: table name expected\n"); LOG(L_ERR, "ERROR: ul_add: table name expected\n"); return 1; } if (!read_line(user_s, MAX_USER, pipe, &user.len) || user.len == 0) { fifo_reply(response_file, "400 ul_add: aor name expected\n"); LOG(L_ERR, "ERROR: ul_add: aor expected\n"); return 1; } at = memchr(user_s, '@', user.len); if (use_domain) { if (!at) { fifo_reply(response_file, "400 ul_add: username@domain expected\n"); LOG(L_ERR, "ERROR: ul_add: Domain missing\n"); return 1; } } else { if (at) { user.len = at - user_s; } } if (!read_line(contact_s, MAX_CONTACT_LEN, pipe, &contact.len) || contact.len == 0) { fifo_reply(response_file, "400 ul_add: contact expected\n"); LOG(L_ERR, "ERROR: ul_add: contact expected\n"); return 1; } if (!read_line(expires_s, MAX_EXPIRES_LEN, pipe, &expires.len) || expires.len == 0) { fifo_reply(response_file, "400 ul_add: expires expected\n"); LOG(L_ERR, "ERROR: ul_add: expires expected\n"); return 1; } if (!read_line(q_s, MAX_Q, pipe, &q.len) || q.len == 0) { fifo_reply(response_file, "400 ul_add: q expected\n"); LOG(L_ERR, "ERROR: ul_add: q expected\n"); return 1; } /* Kept for backwards compatibility */ if (!read_line(rep_s, MAX_REPLICATE_LEN, pipe, &rep.len) || rep.len == 0) { fifo_reply(response_file, "400 ul_add: replicate expected\n"); LOG(L_ERR, "ERROR: ul_add: replicate expected\n"); return 1; } if (!read_line(flags_s, MAX_FLAGS_LEN, pipe, &flags.len) || flags.len == 0) { fifo_reply(response_file, "400 ul_add: flags expected\n"); LOG(L_ERR, "ERROR: ul_add: flags expected\n"); return 1; } table.s = table_s; user.s = user_s; strlower(&user); contact.s = contact_s; expires.s = expires_s; q.s = q_s; flags.s = flags_s; fifo_find_domain(&table, &d); if (d) { if (str2int(&expires, (unsigned int*)&exp_i) < 0) { fifo_reply(response_file, "400 Invalid expires format\n"); return 1; } if (str2q(&qval, q.s, q.len) < 0) { fifo_reply(response_file, "400 Invalid q value\n"); return 1; } if (str2int(&flags, (unsigned int*)&flags_i) < 0) { fifo_reply(response_file, "400 Invalid flags format\n"); return 1; } lock_udomain(d); if (add_contact(d, &user, &contact, exp_i, qval, flags_i) < 0) { unlock_udomain(d); LOG(L_ERR, "ul_add(): Error while adding contact ('%.*s','%.*s') in table '%.*s'\n", user.len, ZSW(user.s), contact.len, ZSW(contact.s), table.len, ZSW(table.s)); fifo_reply(response_file, "500 Error while adding contact\n" " ('%.*s','%.*s') in table '%.*s'\n", user.len, ZSW(user.s), contact.len, ZSW(contact.s), table.len, ZSW(table.s)); return 1; } unlock_udomain(d); fifo_reply(response_file, "200 Added to table\n" "('%.*s','%.*s') to '%.*s'\n", user.len, ZSW(user.s), contact.len, ZSW(contact.s), table.len, ZSW(table.s)); return 1; } else { fifo_reply(response_file, "400 Table '%.*s' not found in memory, use save(\"%.*s\") or lookup(\"%.*s\") in the configuration script first\n", table.len, ZSW(table.s), table.len, ZSW(table.s), table.len, ZSW(table.s)); return 1; } }
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 fifo_pa_location_contact(FILE *fifo, char *response_file) { char pdomain_s[MAX_P_URI]; char p_uri_s[MAX_P_URI]; char p_contact_s[MAX_P_URI]; char location_s[MAX_LOCATION]; char priority_s[MAX_LOCATION]; char expires_s[MAX_LOCATION]; pdomain_t *pdomain = NULL; presentity_t *presentity = NULL; presence_tuple_t *tuple = NULL; str pdomain_name, p_uri, p_contact, location, priority_str, expires_str; time_t expires; double priority; int changed = 0; char *msg = "no error"; if (!read_line(pdomain_s, MAX_PDOMAIN, fifo, &pdomain_name.len) || pdomain_name.len == 0) { fifo_reply(response_file, "400 pa_location_contact: pdomain expected\n"); LOG(L_ERR, "ERROR: pa_location_contact: pdomain expected\n"); return 1; } pdomain_name.s = pdomain_s; if (!read_line(p_uri_s, MAX_P_URI, fifo, &p_uri.len) || p_uri.len == 0) { fifo_reply(response_file, "400 pa_location_contact: p_uri expected\n"); LOG(L_ERR, "ERROR: pa_location_contact: p_uri expected\n"); return 1; } p_uri.s = p_uri_s; if (!read_line(p_contact_s, MAX_P_URI, fifo, &p_contact.len) || p_contact.len == 0) { fifo_reply(response_file, "400 pa_location_contact: p_contact expected\n"); LOG(L_ERR, "ERROR: pa_location_contact: p_contact expected\n"); return 1; } p_contact.s = p_contact_s; if (!read_line(location_s, MAX_LOCATION, fifo, &location.len) || location.len == 0) { fifo_reply(response_file, "400 pa_location_contact: location expected\n"); LOG(L_ERR, "ERROR: pa_location_contact: location expected\n"); return 1; } location.s = location_s; if (!read_line(priority_s, MAX_LOCATION, fifo, &priority_str.len) || priority_str.len == 0) { fifo_reply(response_file, "400 pa_location_contact: priority expected\n"); LOG(L_ERR, "ERROR: pa_location_contact: priority expected\n"); return 1; } priority = strtod(priority_s, NULL); if (!read_line(expires_s, MAX_LOCATION, fifo, &expires_str.len) || expires_str.len == 0) { fifo_reply(response_file, "400 pa_location_contact: expires expected\n"); LOG(L_ERR, "ERROR: pa_location_contact: expires expected\n"); return 1; } expires = strtoul(expires_s, NULL, 0); register_pdomain(pdomain_s, &pdomain); if (!pdomain) { fifo_reply(response_file, "400 could not register pdomain\n"); LOG(L_ERR, "ERROR: pa_location_contact: could not register pdomain %.*s\n", pdomain_name.len, pdomain_name.s); return 1; } lock_pdomain(pdomain); find_presentity(pdomain, &p_uri, &presentity); if (!presentity) { new_presentity(pdomain, &p_uri, &presentity); add_presentity(pdomain, presentity); changed = 1; } if (!presentity) { msg = "400 could not find presentity\n"; LOG(L_ERR, "ERROR: pa_location_contact: could not find presentity %.*s\n", p_uri.len, p_uri.s); return 1; } find_presence_tuple(&p_contact, presentity, &tuple); if (!tuple && new_tuple_on_publish) { new_presence_tuple(&p_contact, expires, presentity, &tuple); add_presence_tuple(presentity, tuple); tuple->state = PS_ONLINE; changed = 1; } if (!tuple) { LOG(L_ERR, "publish_presentity: no tuple for %.*s\n", presentity->uri.len, presentity->uri.s); msg = "400 could not find presence tuple\n"; goto error; } changed = 1; if (1 || (tuple->location.loc.len && str_strcasecmp(&tuple->location.room, &location) != 0)) { changed = 1; LOG(L_ERR, "Setting room of contact=%.*s to %.*s\n", tuple->contact.len, tuple->contact.s, tuple->location.room.len, tuple->location.room.s); strncpy(tuple->location.room.s, location.s, location.len); tuple->location.room.len = location.len; strncpy(tuple->location.loc.s, location.s, location.len); tuple->location.loc.len = location.len; } if (tuple->priority != priority) { tuple->priority = priority; changed = 1; } if (expires < 7*24*3600) { /* must be seconds */ get_act_time(); expires = act_time + expires; } if (tuple->expires != expires) { tuple->expires = expires; changed = 1; } if (changed) { presentity->flags |= PFLAG_PRESENCE_CHANGED; } db_update_presentity(presentity); unlock_pdomain(pdomain); fifo_reply(response_file, "200 published\n", "(%.*s %.*s)\n", p_uri.len, ZSW(p_uri.s), location.len, ZSW(location.s)); return 1; error: unlock_pdomain(pdomain); fifo_reply(response_file, msg); return 1; }
int static ul_flush(FILE* pipe, char* response_file) { synchronize_all_udomains(); fifo_reply(response_file, "200 ul_flush completed" ); return 1; }
static void fifo_server(FILE *fifo_stream) { char buf[MAX_FIFO_COMMAND]; int line_len; char *file_sep, *command, *file; struct fifo_command *f; file_sep=command=file=0; while(1) { /* commands must look this way ':<command>:[filename]' */ if (!read_line(buf, MAX_FIFO_COMMAND, fifo_stream, &line_len)) { /* line breaking must have failed -- consume the rest and proceed to a new request */ LOG(L_ERR, "ERROR: fifo_server: command expected\n"); goto consume; } if (line_len==0) { LOG(L_DBG, "INFO: fifo_server: command empty\n"); continue; } if (line_len<3) { LOG(L_ERR, "ERROR: fifo_server: command must have at least 3 chars\n"); goto consume; } if (*buf!=CMD_SEPARATOR) { LOG(L_ERR, "ERROR: fifo_server: command must begin with %c: %.*s\n", CMD_SEPARATOR, line_len, buf ); goto consume; } command=buf+1; file_sep=strchr(command, CMD_SEPARATOR ); if (file_sep==NULL) { LOG(L_ERR, "ERROR: fifo_server: file separator missing\n"); goto consume; } if (file_sep==command) { LOG(L_ERR, "ERROR: fifo_server: empty command\n"); goto consume; } if (*(file_sep+1)==0) file=NULL; else { file=file_sep+1; file=trim_filename(file); if (file==0) { LOG(L_ERR, "ERROR: fifo_server: trimming filename\n"); goto consume; } } /* make command zero-terminated */ *file_sep=0; f=lookup_fifo_cmd( command ); if (f==0) { LOG(L_ERR, "ERROR: fifo_server: command %s is not available\n", command); fifo_reply(file, "500 command '%s' not available\n", command); goto consume; } if (f->f(fifo_stream, file)<0) { LOG(L_ERR, "ERROR: fifo_server: command (%s) " "processing failed\n", command ); goto consume; } consume: if (file) { pkg_free(file); file=0;} consume_request(fifo_stream); } }
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; } }