int select_sys_unique(str* res, select_t* s, struct sip_msg* msg) { #define UNIQUE_ID_PID_LEN 4 #define UNIQUE_ID_TIME_LEN 8 #define UNIQUE_ID_FIX_LEN (UNIQUE_ID_PID_LEN+1+UNIQUE_ID_TIME_LEN+1) #define UNIQUE_ID_RAND_LEN 8 static char uniq_id[UNIQUE_ID_FIX_LEN+UNIQUE_ID_RAND_LEN]; static int uniq_for_pid = -1; int i; if (uniq_for_pid != getpid()) { /* first call for this process */ int cb, rb, x, l; char *c; /* init gloabally uniq part */ c = int2str_base_0pad(getpid(), &l, 16, UNIQUE_ID_PID_LEN); memcpy(uniq_id, c, UNIQUE_ID_PID_LEN); uniq_id[UNIQUE_ID_PID_LEN] = '-'; c = int2str_base_0pad(time(NULL), &l, 16, UNIQUE_ID_TIME_LEN); memcpy(uniq_id+UNIQUE_ID_PID_LEN+1, c, UNIQUE_ID_TIME_LEN); uniq_id[UNIQUE_ID_PID_LEN+1+UNIQUE_ID_TIME_LEN] = '-'; /* init random part */ for (i = KAM_RAND_MAX, rb=0; i; rb++, i>>=1); for (i = UNIQUE_ID_FIX_LEN, cb = 0, x = 0; i < UNIQUE_ID_FIX_LEN+UNIQUE_ID_RAND_LEN; i++) { if (!cb) { cb = rb; x = kam_rand(); } uniq_id[i] = fourbits2char[x & 0x0F]; x >>= rb; cb -= rb; } uniq_for_pid = getpid(); }
int uint_to_static_buffer_ex(str* res, unsigned int val, int base, int pad) { char *c; c = int2str_base_0pad(val, &res->len, base, pad); res->s = get_static_buffer(res->len); if (!res->s) return -1; memcpy(res->s, c, res->len); return 0; }
static int xl_get_msgid(struct sip_msg *msg, str *res, str *hp, int hi, int hf) { int l = 0; char *ch = NULL; if(msg==NULL || res==NULL) return -1; ch = int2str_base_0pad(msg->id, &l, hi, hi==10?0:8); res->s = ch; res->len = l; return 0; }
static int xl_get_times(struct sip_msg *msg, str *res, str *hp, int hi, int hf) { int l = 0; char *ch = NULL; if(msg==NULL || res==NULL) return -1; if(msg_id != msg->id || msg_tm==0) { msg_tm = time(NULL); msg_id = msg->id; } ch = int2str_base_0pad(msg_tm, &l, hi, hi==10?0:8); res->s = ch; res->len = l; return 0; }