Skip to content

Commit

Permalink
usrloc: support filter by server_id at get_all_ucontacts
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxmaniac committed Jul 4, 2015
1 parent fa33cd0 commit 039231a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
33 changes: 25 additions & 8 deletions modules/usrloc/dlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ static inline int find_dlist(str* _n, dlist_t** _d)
* \param flags contact flags
* \param part_idx part index
* \param part_max maximal part
* \param GAU options
* \return 0 on success, positive if buffer size was not sufficient, negative on failure
*/
static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags,
unsigned int part_idx, unsigned int part_max)
unsigned int part_idx, unsigned int part_max,
int options)
{
struct socket_info *sock;
unsigned int dbflags;
Expand All @@ -108,9 +110,9 @@ static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags,
int i;
void *cp;
int shortage, needed;
db_key_t keys1[3]; /* where */
db_val_t vals1[3];
db_op_t ops1[3];
db_key_t keys1[4]; /* where */
db_val_t vals1[4];
db_op_t ops1[4];
db_key_t keys2[6]; /* select */
int n[2] = {2,6}; /* number of dynamic values used on key1/key2 */

Expand Down Expand Up @@ -160,6 +162,14 @@ static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags,
vals1[n[0]].val.int_val = 1;
n[0]++;
}
if(options&GAU_OPT_SERVER_ID) {
keys1[n[0]] = &srv_id_col;
ops1[n[0]] = OP_EQ;
vals1[n[0]].type = DB1_INT;
vals1[n[0]].nul = 0;
vals1[n[0]].val.int_val = server_id;
n[0]++;
}

/* TODO: use part_idx and part_max on keys1 */

Expand Down Expand Up @@ -323,10 +333,12 @@ static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags,
* \param flags contact flags
* \param part_idx part index
* \param part_max maximal part
* \param GAU options
* \return 0 on success, positive if buffer size was not sufficient, negative on failure
*/
static inline int get_all_mem_ucontacts(void *buf, int len, unsigned int flags,
unsigned int part_idx, unsigned int part_max)
unsigned int part_idx, unsigned int part_max,
int options)
{
dlist_t *p;
urecord_t *r;
Expand Down Expand Up @@ -370,6 +382,9 @@ static inline int get_all_mem_ucontacts(void *buf, int len, unsigned int flags,
if ((c->cflags & flags) != flags)
continue;

if(options&GAU_OPT_SERVER_ID && server_id!=c->server_id)
continue;

if(ul_keepalive_timeout>0 && c->last_keepalive>0)
{
if(c->sock!=NULL && c->sock->proto==PROTO_UDP)
Expand Down Expand Up @@ -468,15 +483,17 @@ static inline int get_all_mem_ucontacts(void *buf, int len, unsigned int flags,
* \param flags contact flags
* \param part_idx part index
* \param part_max maximal part
* \param GAU options
* \return 0 on success, positive if buffer size was not sufficient, negative on failure
*/
int get_all_ucontacts(void *buf, int len, unsigned int flags,
unsigned int part_idx, unsigned int part_max)
unsigned int part_idx, unsigned int part_max,
int options)
{
if (db_mode==DB_ONLY)
return get_all_db_ucontacts( buf, len, flags, part_idx, part_max);
return get_all_db_ucontacts( buf, len, flags, part_idx, part_max, options);
else
return get_all_mem_ucontacts( buf, len, flags, part_idx, part_max);
return get_all_mem_ucontacts( buf, len, flags, part_idx, part_max, options);
}


Expand Down
3 changes: 2 additions & 1 deletion modules/usrloc/dlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@ int synchronize_all_udomains(int istart, int istep);
* \param flags contact flags
* \param part_idx part index
* \param part_max maximal part
* \param GAU options
* \return 0 on success, positive if buffer size was not sufficient, negative on failure
*/
int get_all_ucontacts(void *buf, int len, unsigned int flags,
unsigned int part_idx, unsigned int part_max);
unsigned int part_idx, unsigned int part_max, int options);


/*!
Expand Down
4 changes: 3 additions & 1 deletion modules/usrloc/usrloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#define DB_ONLY 3
#define DB_READONLY 4

#define GAU_OPT_SERVER_ID (1<<0) /* filter query by server_id */

/*forward declaration necessary for udomain*/

struct udomain;
Expand Down Expand Up @@ -181,7 +183,7 @@ typedef void (*unlock_udomain_t)(struct udomain* _d, str *_aor);
typedef int (*register_udomain_t)(const char* _n, struct udomain** _d);

typedef int (*get_all_ucontacts_t) (void* buf, int len, unsigned int flags,
unsigned int part_idx, unsigned int part_max);
unsigned int part_idx, unsigned int part_max, int options);

typedef int (*get_udomain_t)(const char* _n, udomain_t** _d);

Expand Down

0 comments on commit 039231a

Please sign in to comment.