/* ** sortcmp:: qsort callback */ static int CDECL sortcmp( const void * e1, const void * e2 ) { MWM_PATTERN_STRUCT *r1= (MWM_PATTERN_STRUCT*)e1; MWM_PATTERN_STRUCT *r2= (MWM_PATTERN_STRUCT*)e2; return bcompare( r1->psPat, r1->psLen, r2->psPat, r2->psLen ); }
int findHlr(unsigned char *hlr,int *ofs,char *sid,char *did) { unsigned int record_length; int match=0; int records_searched=0; int pid_len=0; unsigned char packed_id[40]; if ((*ofs)>=hlr_size) return 0; if (debug>1) fprintf(stderr,"Searching for HLR record sid=[%s]/did=[%s]\n",sid?sid:"NULL",did?did:"NULL"); if (did&&did[0]) { /* Make packed version of DID so that we can compare faster with the DIDs in the HLR */ if (stowDid(packed_id,&pid_len,did)) return setReason("DID appears to be invalid"); /* Find significant length of packed DID */ for(pid_len=0;pid_len<DID_MAXSIZE;pid_len++) if ((packed_id[pid_len]&0x0f)==0x0f) { pid_len++; break; } if (debug>1) dump("Searching for DID records that match",packed_id,pid_len); } if (sid&&sid[0]) { /* Make packed version of SID for fast comparison */ if (stowSid(packed_id,pid_len,sid)) return setReason("SID appears to be invalid"); pid_len=SID_SIZE; } while(!match) { /* Get length of this record */ record_length =hlr[(*ofs)+3]<<0; record_length|=hlr[(*ofs)+2]<<8; record_length|=hlr[(*ofs)+1]<<16; record_length|=hlr[(*ofs)+0]<<24; if (!record_length) return 0; if (debug>1) fprintf(stderr,"Considering HLR entry @ 0x%x\n",*ofs); records_searched++; if (sid&&sid[0]) { /* Lookup by SID, so just see if it matches */ if (!bcompare(packed_id,&hlr[(*ofs)+4],SID_SIZE)) { if (debug>1) fprintf(stderr,"Found requested SID at address 0x%x.\n",*ofs); match=1; } } if (did&&did[0]) { /* Lookup by did, so see if there are any matching DID entries for this subscriber */ int rofs=(*ofs); struct hlrentry_handle *h=openhlrentry(hlr,rofs); while(h) { /* Search through variables for matching DIDs */ if (debug>2) { fprintf(stderr,"Considering variable 0x%02x, instance %d.\n", h->var_id,h->var_instance); dump("variable value",h->value,h->value_len); } if (h->var_id==VAR_DIDS) { /* DID entry */ if (debug>2) fprintf(stderr,"Checking DID against record DID\n"); if (!bcompare(packed_id,h->value,pid_len)) { if (debug>1) fprintf(stderr,"Found matching DID in HLR record #%d\n",records_searched); match=1; break; } } else { if (debug>2) fprintf(stderr,"Skipping non-DID variable while searching for DID.\n"); } h=hlrentrygetent(h); } } /* For each match ... */ if (match) { if (debug>1) fprintf(stderr,"Returning HLR entry @ 0x%x\n",*ofs); return 1; } /* Consider next record */ (*ofs)+=record_length; if ((*ofs)>=hlr_size) return 0; } return 0; }