Kannel: Open Source WAP and SMS gateway  svn-r5335
wap_push_ppg_pushuser.c File Reference
#include "wap_push_ppg_pushuser.h"
#include "numhash.h"
#include "gwlib/gw-regex.h"

Go to the source code of this file.

Data Structures

struct  WAPPushUser
 
struct  WAPPushUserList
 

Macros

#define ADDITION   0.1
 

Typedefs

typedef struct WAPPushUser WAPPushUser
 
typedef struct WAPPushUserList WAPPushUserList
 

Enumerations

enum  { NO_USERNAME = -1, NO_PASSWORD = 0, HEADER_AUTHENTICATION = 1 }
 

Functions

static void destroy_users_list (void *l)
 
static WAPPushUserListpushusers_create (long number_of_users)
 
static WAPPushUsercreate_oneuser (CfgGroup *grp)
 
static void destroy_oneuser (void *p)
 
static int oneuser_add (CfgGroup *cfg)
 
static void oneuser_dump (WAPPushUser *u)
 
static WAPPushUseruser_find_by_username (Octstr *username)
 
static int password_matches (WAPPushUser *u, Octstr *password)
 
static int ip_allowed_by_user (WAPPushUser *u, Octstr *ip)
 
static int prefix_allowed (WAPPushUser *u, Octstr *number)
 
static int whitelisted (WAPPushUser *u, Octstr *number)
 
static int blacklisted (WAPPushUser *u, Octstr *number)
 
static int wildcarded_ip_found (Octstr *ip, Octstr *needle, Octstr *ip_sep)
 
static int response (List *push_headers, Octstr **username, Octstr **password)
 
static void challenge (HTTPClient *c, List *push_headers)
 
static void reply (HTTPClient *c, List *push_headers)
 
static int parse_cgivars_for_username (List *cgivars, Octstr **username)
 
static int parse_cgivars_for_password (List *cgivars, Octstr **password)
 
static int compare_octstr_sequence (Octstr *os1, Octstr *os2, long start)
 
static Octstrforced_smsc (WAPPushUser *u)
 
static Octstrdefault_smsc (WAPPushUser *u)
 
int wap_push_ppg_pushuser_list_add (List *list, long number_of_pushes, long number_of_users)
 
void wap_push_ppg_pushuser_list_destroy (void)
 
int wap_push_ppg_pushuser_authenticate (HTTPClient *c, List *cgivars, Octstr *ip, List *push_headers, Octstr **username)
 
int wap_push_ppg_pushuser_client_phone_number_acceptable (Octstr *username, Octstr *number)
 
int wap_push_ppg_pushuser_search_ip_from_wildcarded_list (Octstr *haystack, Octstr *needle, Octstr *gwlist_sep, Octstr *ip_sep)
 
Octstrwap_push_ppg_pushuser_smsc_id_get (Octstr *username)
 
Octstrwap_push_ppg_pushuser_dlr_url_get (Octstr *username)
 
Octstrwap_push_ppg_pushuser_smsbox_id_get (Octstr *username)
 

Variables

static WAPPushUserListusers = NULL
 
static Dictnext_try = NULL
 

Macro Definition Documentation

◆ ADDITION

#define ADDITION   0.1

Definition at line 192 of file wap_push_ppg_pushuser.c.

Referenced by wap_push_ppg_pushuser_authenticate().

Typedef Documentation

◆ WAPPushUser

typedef struct WAPPushUser WAPPushUser

Definition at line 101 of file wap_push_ppg_pushuser.c.

◆ WAPPushUserList

Definition at line 112 of file wap_push_ppg_pushuser.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
NO_USERNAME 
NO_PASSWORD 
HEADER_AUTHENTICATION 

Definition at line 186 of file wap_push_ppg_pushuser.c.

Function Documentation

◆ blacklisted()

static int blacklisted ( WAPPushUser u,
Octstr number 
)
static

Definition at line 977 of file wap_push_ppg_pushuser.c.

References WAPPushUser::black_list, WAPPushUser::black_list_regex, number, and numhash_find_number().

Referenced by wap_push_ppg_pushuser_client_phone_number_acceptable().

978 {
979  int result = 0;
980 
981  if (u->black_list != NULL)
982  result = numhash_find_number(u->black_list, number);
983 
984  if ((result == 0) && (u->black_list_regex != NULL))
985  result = gw_regex_match_pre(u->black_list_regex, number);
986 
987  return result;
988 }
int number
Definition: smsc_cimd2.c:213
regex_t * black_list_regex
int numhash_find_number(Numhash *table, Octstr *nro)
Definition: numhash.c:218

◆ challenge()

static void challenge ( HTTPClient c,
List push_headers 
)
static

Definition at line 839 of file wap_push_ppg_pushuser.c.

References get_official_name(), http_create_empty_headers(), http_destroy_headers(), http_header_add(), http_send_reply(), HTTP_UNAUTHORIZED, octstr_append(), octstr_destroy(), octstr_format(), octstr_format_append(), octstr_get_cstr, and octstr_imm().

Referenced by wap_push_ppg_pushuser_authenticate().

840 {
841  Octstr *challenge,
842  *realm;
843  int http_status;
844  List *reply_headers;
845 
846  realm = octstr_format("%s", "Basic realm=");
848  octstr_format_append(realm, "%s", "\"wappush\"");
849  reply_headers = http_create_empty_headers();
850  http_header_add(reply_headers, "WWW-Authenticate", octstr_get_cstr(realm));
851  http_status = HTTP_UNAUTHORIZED;
852  challenge = octstr_imm("You must show your credentials.\n");
853 
854  http_send_reply(c, http_status, reply_headers, challenge);
855 
856  octstr_destroy(realm);
857  http_destroy_headers(reply_headers);
858 }
void http_header_add(List *headers, char *name, char *contents)
Definition: http.c:2886
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:1504
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
void http_destroy_headers(List *headers)
Definition: http.c:2879
void http_send_reply(HTTPClient *client, int status, List *headers, Octstr *body)
Definition: http.c:2695
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
List * http_create_empty_headers(void)
Definition: http.c:2872
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2464
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
Octstr * get_official_name(void)
Definition: socket.c:627
Definition: octstr.c:118
void octstr_format_append(Octstr *os, const char *fmt,...)
Definition: octstr.c:2507
static void challenge(HTTPClient *c, List *push_headers)
Definition: list.c:102

◆ compare_octstr_sequence()

static int compare_octstr_sequence ( Octstr os1,
Octstr os2,
long  start 
)
static

Definition at line 1022 of file wap_push_ppg_pushuser.c.

References octstr_delete(), octstr_get_many_chars(), octstr_insert_data(), octstr_len(), octstr_ncompare(), and start.

Referenced by prefix_allowed().

1023 {
1024  int ret;
1025  unsigned char *prefix;
1026  long end;
1027 
1028  if (octstr_len(os2) == 0)
1029  return 1;
1030 
1031  if (octstr_len(os1) == 0)
1032  return -1;
1033 
1034  prefix = NULL;
1035  if (start != 0) {
1036  prefix = gw_malloc(start);
1037  octstr_get_many_chars((char *)prefix, os1, 0, start);
1038  octstr_delete(os1, 0, start);
1039  }
1040 
1041  end = start + octstr_len(os2);
1042  ret = octstr_ncompare(os1, os2, end - start);
1043 
1044  if (start != 0) {
1045  octstr_insert_data(os1, 0, (char *)prefix, start);
1046  gw_free(prefix);
1047  }
1048 
1049  return ret;
1050 }
void octstr_insert_data(Octstr *ostr, long pos, const char *data, long len)
Definition: octstr.c:1461
void octstr_delete(Octstr *ostr1, long pos, long len)
Definition: octstr.c:1527
int octstr_ncompare(const Octstr *ostr1, const Octstr *ostr2, long n)
Definition: octstr.c:952
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
void octstr_get_many_chars(char *buf, Octstr *ostr, long pos, long len)
Definition: octstr.c:425
static int start

◆ create_oneuser()

static WAPPushUser * create_oneuser ( CfgGroup grp)
static

Definition at line 451 of file wap_push_ppg_pushuser.c.

References WAPPushUser::allowed_prefix, WAPPushUser::allowed_prefix_regex, WAPPushUser::black_list, WAPPushUser::black_list_regex, cfg_get, WAPPushUser::country_prefix, WAPPushUser::default_smsc_id, WAPPushUser::denied_prefix, WAPPushUser::denied_prefix_regex, destroy_oneuser(), WAPPushUser::dlr_url, error(), WAPPushUser::name, numhash_create(), octstr_destroy(), octstr_get_cstr, octstr_imm(), oneuser_dump(), panic, WAPPushUser::password, WAPPushUser::smsbox_id, WAPPushUser::smsc_id, WAPPushUser::user_allow_ip, WAPPushUser::user_deny_ip, WAPPushUser::username, warning(), WAPPushUser::white_list, and WAPPushUser::white_list_regex.

Referenced by oneuser_add().

452 {
453  WAPPushUser *u;
454  Octstr *grpname,
455  *os;
456 
457  grpname = cfg_get(grp, octstr_imm("wap-push-user"));
458  if (grpname == NULL) {
459  error(0, "all users group (wap-push-user) are missing");
460  goto no_grpname;
461  }
462 
463  u = gw_malloc(sizeof(WAPPushUser));
464  u->name = NULL;
465  u->username = NULL;
466  u->allowed_prefix = NULL;
467  u->allowed_prefix_regex = NULL;
468  u->denied_prefix = NULL;
469  u->denied_prefix_regex = NULL;
470  u->white_list = NULL;
471  u->white_list_regex = NULL;
472  u->black_list = NULL;
473  u->black_list_regex = NULL;
474  u->user_deny_ip = NULL;
475  u->user_allow_ip = NULL;
476  u->smsc_id = NULL;
477  u->default_smsc_id = NULL;
478 
479  u->name = cfg_get(grp, octstr_imm("wap-push-user"));
480 
481  if (u->name == NULL) {
482  warning(0, "user name missing, dump follows");
483  oneuser_dump(u);
484  goto error;
485  }
486 
487  u->username = cfg_get(grp, octstr_imm("ppg-username"));
488  u->password = cfg_get(grp, octstr_imm("ppg-password"));
489 
490  if (u->username == NULL) {
491  warning(0, "login name for user %s missing, dump follows",
492  octstr_get_cstr(u->name));
493  oneuser_dump(u);
494  goto error;
495  }
496 
497  if (u->password == NULL) {
498  warning(0, "password for user %s missing, dump follows",
499  octstr_get_cstr(u->name));
500  oneuser_dump(u);
501  goto error;
502  }
503 
504  u->user_deny_ip = cfg_get(grp, octstr_imm("deny-ip"));
505  u->user_allow_ip = cfg_get(grp, octstr_imm("allow-ip"));
506  u->country_prefix = cfg_get(grp, octstr_imm("country-prefix"));
507  u->allowed_prefix = cfg_get(grp, octstr_imm("allowed-prefix"));
508  u->denied_prefix = cfg_get(grp, octstr_imm("denied-prefix"));
509  u->smsc_id = cfg_get(grp, octstr_imm("forced-smsc"));
510  u->default_smsc_id = cfg_get(grp, octstr_imm("default-smsc"));
511  u->dlr_url = cfg_get(grp, octstr_imm("dlr-url"));
512  u->smsbox_id = cfg_get(grp, octstr_imm("smsbox-id"));
513 
514  os = cfg_get(grp, octstr_imm("white-list"));
515  if (os != NULL) {
517  octstr_destroy(os);
518  }
519  os = cfg_get(grp, octstr_imm("black-list"));
520  if (os != NULL) {
522  octstr_destroy(os);
523  }
524 
525  if ((os = cfg_get(grp, octstr_imm("allowed-prefix-regex"))) != NULL) {
526  if ((u->allowed_prefix_regex = gw_regex_comp(os, REG_EXTENDED)) == NULL)
527  panic(0, "Could not compile pattern '%s'", octstr_get_cstr(os));
528  octstr_destroy(os);
529  };
530  if ((os = cfg_get(grp, octstr_imm("denied-prefix-regex"))) != NULL) {
531  if ((u->denied_prefix_regex = gw_regex_comp(os, REG_EXTENDED)) == NULL)
532  panic(0, "Could not compile pattern '%s'", octstr_get_cstr(os));
533  octstr_destroy(os);
534  };
535  if ((os = cfg_get(grp, octstr_imm("white-list-regex"))) != NULL) {
536  if ((u->white_list_regex = gw_regex_comp(os, REG_EXTENDED)) == NULL)
537  panic(0, "Could not compile pattern '%s'", octstr_get_cstr(os));
538  octstr_destroy(os);
539  };
540  if ((os = cfg_get(grp, octstr_imm("black-list-regex"))) != NULL) {
541  if ((u->black_list_regex = gw_regex_comp(os, REG_EXTENDED)) == NULL)
542  panic(0, "Could not compile pattern '%s'", octstr_get_cstr(os));
543  octstr_destroy(os);
544  };
545 
546  octstr_destroy(grpname);
547  return u;
548 
549 no_grpname:
550  octstr_destroy(grpname);
551  return NULL;
552 
553 error:
554  octstr_destroy(grpname);
555  destroy_oneuser(u);
556  return NULL;
557 }
regex_t * allowed_prefix_regex
void error(int err, const char *fmt,...)
Definition: log.c:648
regex_t * black_list_regex
static void oneuser_dump(WAPPushUser *u)
Octstr * default_smsc_id
#define cfg_get(grp, varname)
Definition: cfg.h:86
regex_t * white_list_regex
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
Numhash * numhash_create(const char *seek_url)
Definition: numhash.c:313
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
static void destroy_oneuser(void *p)
void warning(int err, const char *fmt,...)
Definition: log.c:660
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
regex_t * denied_prefix_regex
Definition: octstr.c:118
#define panic
Definition: log.h:87

◆ default_smsc()

static Octstr * default_smsc ( WAPPushUser u)
static

Definition at line 1057 of file wap_push_ppg_pushuser.c.

References WAPPushUser::default_smsc_id.

Referenced by create_onetrans(), and wap_push_ppg_pushuser_smsc_id_get().

1058 {
1059  return u->default_smsc_id;
1060 }
Octstr * default_smsc_id

◆ destroy_oneuser()

static void destroy_oneuser ( void *  p)
static

Definition at line 559 of file wap_push_ppg_pushuser.c.

References WAPPushUser::allowed_prefix, WAPPushUser::allowed_prefix_regex, WAPPushUser::black_list, WAPPushUser::black_list_regex, WAPPushUser::country_prefix, WAPPushUser::default_smsc_id, WAPPushUser::denied_prefix, WAPPushUser::denied_prefix_regex, WAPPushUser::name, numhash_destroy(), octstr_destroy(), WAPPushUser::password, WAPPushUser::smsc_id, WAPPushUser::user_allow_ip, WAPPushUser::user_deny_ip, WAPPushUser::username, WAPPushUser::white_list, and WAPPushUser::white_list_regex.

Referenced by create_oneuser(), and wap_push_ppg_pushuser_list_destroy().

560 {
561  WAPPushUser *u;
562 
563  u = p;
564  if (u == NULL)
565  return;
566 
567  octstr_destroy(u->name);
579 
580  if (u->black_list_regex != NULL) gw_regex_destroy(u->black_list_regex);
581  if (u->white_list_regex != NULL) gw_regex_destroy(u->white_list_regex);
582  if (u->denied_prefix_regex != NULL) gw_regex_destroy(u->denied_prefix_regex);
583  if (u->allowed_prefix_regex != NULL) gw_regex_destroy(u->allowed_prefix_regex);
584  gw_free(u);
585 }
regex_t * allowed_prefix_regex
regex_t * black_list_regex
Octstr * default_smsc_id
regex_t * white_list_regex
void numhash_destroy(Numhash *table)
Definition: numhash.c:275
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
regex_t * denied_prefix_regex

◆ destroy_users_list()

static void destroy_users_list ( void *  l)
static

Definition at line 431 of file wap_push_ppg_pushuser.c.

References gwlist_destroy().

Referenced by pushusers_create().

432 {
433  gwlist_destroy(l, NULL);
434 }
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

◆ forced_smsc()

static Octstr * forced_smsc ( WAPPushUser u)
static

Definition at line 1052 of file wap_push_ppg_pushuser.c.

References WAPPushUser::smsc_id.

Referenced by create_onetrans(), and wap_push_ppg_pushuser_smsc_id_get().

1053 {
1054  return u->smsc_id;
1055 }

◆ ip_allowed_by_user()

static int ip_allowed_by_user ( WAPPushUser u,
Octstr ip 
)
static

Definition at line 702 of file wap_push_ppg_pushuser.c.

References octstr_compare(), octstr_destroy(), octstr_duplicate, octstr_get_cstr, octstr_imm(), WAPPushUser::user_allow_ip, WAPPushUser::user_deny_ip, WAPPushUser::username, wap_push_ppg_pushuser_search_ip_from_wildcarded_list(), and warning().

Referenced by wap_push_ppg_pushuser_authenticate().

703 {
704  Octstr *copy,
705  *ip_copy;
706 
707  if (u == NULL) {
708  warning(0, "user not found from the users list");
709  goto no_user;
710  }
711 
712  copy = octstr_duplicate(u->username);
713 
714  if (u->user_deny_ip == NULL && u->user_allow_ip == NULL)
715  goto allowed;
716 
717  if (u->user_deny_ip) {
718  if (octstr_compare(u->user_deny_ip, octstr_imm("*.*.*.*")) == 0) {
719  warning(0, "no ips allowed for %s", octstr_get_cstr(copy));
720  goto denied;
721  }
722  }
723 
724  if (u->user_allow_ip)
725  if (octstr_compare(u->user_allow_ip, octstr_imm("*.*.*.*")) == 0)
726  goto allowed;
727 
728  if (u->user_deny_ip) {
730  ip, octstr_imm(";"), octstr_imm("."))) {
731  goto denied;
732  }
733  }
734 
735  if (u->user_allow_ip) {
737  ip, octstr_imm(";"), octstr_imm("."))) {
738  goto allowed;
739  }
740  }
741 
742  octstr_destroy(copy);
743  warning(0, "ip not found from either ip list, deny it");
744  return 0;
745 
746 allowed:
747  octstr_destroy(copy);
748  return 1;
749 
750 denied:
751  ip_copy = octstr_duplicate(ip);
752  warning(0, "%s denied by user %s", octstr_get_cstr(ip_copy),
753  octstr_get_cstr(copy));
754  octstr_destroy(copy);
755  octstr_destroy(ip_copy);
756  return 0;
757 
758 no_user:
759  return 0;
760 }
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
int wap_push_ppg_pushuser_search_ip_from_wildcarded_list(Octstr *haystack, Octstr *needle, Octstr *gwlist_sep, Octstr *ip_sep)
#define octstr_duplicate(ostr)
Definition: octstr.h:187
void warning(int err, const char *fmt,...)
Definition: log.c:660
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
Definition: octstr.c:118
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:871

◆ oneuser_add()

static int oneuser_add ( CfgGroup cfg)
static

Definition at line 619 of file wap_push_ppg_pushuser.c.

References create_oneuser(), dict_get(), dict_put(), gwlist_append(), gwlist_create, WAPPushUserList::list, WAPPushUserList::names, WAPPushUser::username, and users.

Referenced by wap_push_ppg_pushuser_list_add().

620 {
621  WAPPushUser *u;
622  List *list;
623 
624  u = create_oneuser(grp);
625  if (u == NULL)
626  return -1;
627 
628  gwlist_append(users->list, u);
629 
630  list = dict_get(users->names, u->username);
631  if (list == NULL) {
632  list = gwlist_create();
633  dict_put(users->names, u->username, list);
634  }
635 
636  return 0;
637 }
void dict_put(Dict *dict, Octstr *key, void *value)
Definition: dict.c:240
void gwlist_append(List *list, void *item)
Definition: list.c:179
void * dict_get(Dict *dict, Octstr *key)
Definition: dict.c:286
static WAPPushUserList * users
static WAPPushUser * create_oneuser(CfgGroup *grp)
#define gwlist_create()
Definition: list.h:136
Definition: list.c:102

◆ oneuser_dump()

static void oneuser_dump ( WAPPushUser u)
static

Definition at line 587 of file wap_push_ppg_pushuser.c.

References WAPPushUser::allowed_prefix, WAPPushUser::country_prefix, debug(), WAPPushUser::default_smsc_id, WAPPushUser::denied_prefix, WAPPushUser::name, octstr_dump, WAPPushUser::smsc_id, WAPPushUser::user_allow_ip, WAPPushUser::user_deny_ip, and WAPPushUser::username.

Referenced by create_oneuser().

588 {
589  if (u == NULL) {
590  debug("wap.push.ppg.pushuser", 0, "no user found");
591  return;
592  }
593 
594  debug("wap.push.ppg.pushuser", 0, "Dumping user data: Name of the user:");
595  octstr_dump(u->name, 0);
596  debug("wap.push.ppg.pushuser", 0, "username:");
597  octstr_dump(u->username, 0);
598  debug("wap.push.ppg.pushuser", 0, "omitting password");
599  debug("wap-push.ppg.pushuser", 0, "country prefix");
600  octstr_dump(u->country_prefix, 0);
601  debug("wap.push.ppg.pushuser", 0, "allowed prefix list:");
602  octstr_dump(u->allowed_prefix, 0);
603  debug("wap.push.ppg.pushuser", 0, "denied prefix list:");
604  octstr_dump(u->denied_prefix, 0);
605  debug("wap.push.ppg.pushuser", 0, "denied ip list:");
606  octstr_dump(u->user_deny_ip, 0);
607  debug("wap.push.ppg.pushuser", 0, "allowed ip list:");
608  octstr_dump(u->user_allow_ip, 0);
609  debug("wap.push.ppg.pushuser", 0, "send via smsc-id:");
610  octstr_dump(u->smsc_id, 0);
611  debug("wap.push.ppg.pushuser", 0, "use default smsc:");
613  debug("wap.push.ppg.pushuser", 0, "end of the dump");
614 }
Octstr * default_smsc_id
#define octstr_dump(ostr, level,...)
Definition: octstr.h:564
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726

◆ parse_cgivars_for_password()

static int parse_cgivars_for_password ( List cgivars,
Octstr **  password 
)
static

Definition at line 1006 of file wap_push_ppg_pushuser.c.

References http_cgi_variable(), octstr_duplicate, and password.

Referenced by wap_push_ppg_pushuser_authenticate().

1007 {
1008  *password = NULL;
1009  *password = octstr_duplicate(http_cgi_variable(cgivars, "password"));
1010 
1011  if (*password == NULL) {
1012  return 0;
1013  }
1014 
1015  return 1;
1016 }
Octstr * http_cgi_variable(List *list, char *name)
Definition: http.c:2836
unsigned char * password
Definition: test_cimd2.c:100
#define octstr_duplicate(ostr)
Definition: octstr.h:187

◆ parse_cgivars_for_username()

static int parse_cgivars_for_username ( List cgivars,
Octstr **  username 
)
static

Definition at line 994 of file wap_push_ppg_pushuser.c.

References http_cgi_variable(), octstr_duplicate, and username.

Referenced by wap_push_ppg_pushuser_authenticate().

995 {
996  *username = NULL;
997  *username = octstr_duplicate(http_cgi_variable(cgivars, "username"));
998 
999  if (*username == NULL) {
1000  return 0;
1001  }
1002 
1003  return 1;
1004 }
unsigned char * username
Definition: test_cimd2.c:99
Octstr * http_cgi_variable(List *list, char *name)
Definition: http.c:2836
#define octstr_duplicate(ostr)
Definition: octstr.h:187

◆ password_matches()

static int password_matches ( WAPPushUser u,
Octstr password 
)
static

Definition at line 660 of file wap_push_ppg_pushuser.c.

References octstr_compare(), WAPPushUser::password, and password.

Referenced by wap_push_ppg_pushuser_authenticate().

661 {
662  if (password == NULL)
663  return 0;
664 
665  return octstr_compare(u->password, password) == 0;
666 }
unsigned char * password
Definition: test_cimd2.c:100
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:871

◆ prefix_allowed()

static int prefix_allowed ( WAPPushUser u,
Octstr number 
)
static

Definition at line 883 of file wap_push_ppg_pushuser.c.

References WAPPushUser::allowed_prefix, WAPPushUser::allowed_prefix_regex, compare_octstr_sequence(), WAPPushUser::country_prefix, WAPPushUser::denied_prefix, WAPPushUser::denied_prefix_regex, gwlist_destroy(), gwlist_get(), gwlist_len(), number, octstr_destroy_item(), octstr_imm(), octstr_insert(), and octstr_split().

Referenced by wap_push_ppg_pushuser_client_phone_number_acceptable().

884 {
885  List *allowed,
886  *denied;
887  long i;
888  Octstr *listed_prefix;
889 
890  allowed = NULL;
891  denied = NULL;
892 
893  if (u == NULL)
894  goto no_user;
895 
896  if ( u->allowed_prefix == NULL && u->denied_prefix == NULL
897  && u->allowed_prefix_regex == NULL && u->denied_prefix_regex == NULL)
898  goto no_configuration;
899 
900  if (u->denied_prefix != NULL) {
901  denied = octstr_split(u->denied_prefix, octstr_imm(";"));
902  for (i = 0; i < gwlist_len(denied); ++i) {
903  listed_prefix = gwlist_get(denied, i);
904  if (u->country_prefix != NULL)
905  octstr_insert(listed_prefix, u->country_prefix, 0);
906  if (compare_octstr_sequence(number, listed_prefix,
907  0) == 0) {
908  goto denied;
909  }
910  }
911  }
912 
913  /* note: country-prefix _must_be included in the pattern */
914  if (u->denied_prefix_regex != NULL)
915  if (gw_regex_match_pre(u->denied_prefix_regex, number) == 1)
916  goto denied;
917 
918  if (u->allowed_prefix_regex == NULL && u->allowed_prefix == NULL)
919  goto no_allowed_config;
920 
921  if (u->allowed_prefix != NULL) {
922  allowed = octstr_split(u->allowed_prefix, octstr_imm(";"));
923  for (i = 0; i < gwlist_len(allowed); ++i) {
924  listed_prefix = gwlist_get(allowed, i);
925  if (u->country_prefix != NULL)
926  octstr_insert(listed_prefix, u->country_prefix, 0);
927  if (compare_octstr_sequence(number, listed_prefix,
928  0) == 0) {
929  goto allowed;
930  }
931  }
932  }
933 
934  /* note: country-prefix _must_ be included in the pattern */
935  if (u->allowed_prefix_regex != NULL)
936  if (gw_regex_match_pre(u->allowed_prefix_regex, number) == 1)
937  goto allowed;
938 
939 /*
940  * Here we have an intentional fall-through. It will removed when memory cleaning
941  * functions are implemented.
942  */
943 denied:
946  return 0;
947 
948 allowed:
951  return 1;
952 
953 no_configuration:
954  return 1;
955 
956 no_user:
957  return 0;
958 
959 no_allowed_config:
961  return 1;
962 }
regex_t * allowed_prefix_regex
int number
Definition: smsc_cimd2.c:213
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
static int compare_octstr_sequence(Octstr *os1, Octstr *os2, long start)
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
void octstr_insert(Octstr *ostr1, const Octstr *ostr2, long pos)
Definition: octstr.c:1303
void octstr_destroy_item(void *os)
Definition: octstr.c:336
regex_t * denied_prefix_regex
Definition: octstr.c:118
List * octstr_split(const Octstr *os, const Octstr *sep)
Definition: octstr.c:1640
Definition: list.c:102
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

◆ pushusers_create()

static WAPPushUserList * pushusers_create ( long  number_of_users)
static

Definition at line 436 of file wap_push_ppg_pushuser.c.

References destroy_users_list(), dict_create(), gwlist_create, WAPPushUserList::list, WAPPushUserList::names, number_of_users, and users.

Referenced by wap_push_ppg_pushuser_list_add().

437 {
438  users = gw_malloc(sizeof(WAPPushUserList));
439  users->list = gwlist_create();
441 
442  return users;
443 }
Dict * dict_create(long size_hint, void(*destroy_value)(void *))
Definition: dict.c:192
static void destroy_users_list(void *l)
static long number_of_users
Definition: wap_push_ppg.c:193
static WAPPushUserList * users
#define gwlist_create()
Definition: list.h:136

◆ reply()

static void reply ( HTTPClient c,
List push_headers 
)
static

Definition at line 863 of file wap_push_ppg_pushuser.c.

References http_create_empty_headers(), http_destroy_headers(), HTTP_FORBIDDEN, http_send_reply(), and octstr_imm().

Referenced by bb_smscconn_send_failed(), bb_smscconn_sent(), cgw_handle_op(), cimd2_request(), create_dlr_from_msg(), emi2_handle_smscreq(), handle_operation(), handle_reply(), handle_split(), httpd_add_smsc(), httpd_flush_dlr(), httpd_graceful_restart(), httpd_isolate(), httpd_loglevel(), httpd_reload_lists(), httpd_remove_message(), httpd_remove_smsc(), httpd_restart(), httpd_restart_smsc(), httpd_resume(), httpd_serve(), httpd_shutdown(), httpd_status(), httpd_stop_smsc(), httpd_store_status(), httpd_suspend(), obey_request_thread(), oisd_request(), and wap_push_ppg_pushuser_authenticate().

864 {
865  int http_status;
866  Octstr *denied;
867  List *reply_headers;
868 
869  reply_headers = http_create_empty_headers();
870  http_status = HTTP_FORBIDDEN;
871  denied = octstr_imm("You are not allowed to use this service. Do not retry.\n");
872 
873  http_send_reply(c, http_status, push_headers, denied);
874 
875  http_destroy_headers(reply_headers);
876 }
void http_destroy_headers(List *headers)
Definition: http.c:2879
void http_send_reply(HTTPClient *client, int status, List *headers, Octstr *body)
Definition: http.c:2695
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
List * http_create_empty_headers(void)
Definition: http.c:2872
Definition: octstr.c:118
Definition: list.c:102

◆ response()

static int response ( List push_headers,
Octstr **  username,
Octstr **  password 
)
static

Definition at line 769 of file wap_push_ppg_pushuser.c.

References debug(), gwlist_destroy(), gwlist_get(), gwlist_len(), HEADER_AUTHENTICATION, http_header_find_first, http_header_remove_all(), NO_PASSWORD, NO_USERNAME, octstr_base64_to_binary(), octstr_delete(), octstr_destroy(), octstr_destroy_item(), octstr_duplicate, octstr_imm(), octstr_len(), octstr_ncompare(), octstr_split(), octstr_strip_blanks(), password, and username.

Referenced by build_response(), cimd2_send_response(), http_send_reply(), oisd_send_response(), soap_parse_dlr(), soap_parse_mo(), wap_push_ppg_pushuser_authenticate(), xmlrpc_doc_create_faultresponse(), xmlrpc_is_fault(), xmlrpc_response_add_param(), xmlrpc_response_destroy(), xmlrpc_response_is_fault(), and xmlrpc_response_print().

770 {
771  Octstr *header_value,
772  *basic;
773  size_t basic_len;
774  List *auth_list;
775 
776  *username = NULL;
777  *password = NULL;
778 
779  if ((header_value = http_header_find_first(push_headers,
780  "Authorization")) == NULL)
781  goto no_response3;
782 
783  octstr_strip_blanks(header_value);
784  basic = octstr_imm("Basic");
785  basic_len = octstr_len(basic);
786 
787  if (octstr_ncompare(header_value, basic, basic_len) != 0)
788  goto no_response1;
789 
790  octstr_delete(header_value, 0, basic_len);
791  octstr_strip_blanks(header_value);
792  octstr_base64_to_binary(header_value);
793  auth_list = octstr_split(header_value, octstr_imm(":"));
794 
795  if (gwlist_len(auth_list) != 2)
796  goto no_response2;
797 
798  *username = octstr_duplicate(gwlist_get(auth_list, 0));
799  *password = octstr_duplicate(gwlist_get(auth_list, 1));
800 
801  if (username == NULL) {
802  goto no_response2;
803  }
804 
805  if (password == NULL) {
806  goto no_response4;
807  }
808 
809  debug("wap.push.ppg.pushuser", 0, "we have an username and a password in"
810  " authorization header");
812  octstr_destroy(header_value);
813  http_header_remove_all(push_headers, "Authorization");
814  return HEADER_AUTHENTICATION;
815 
816 no_response1:
817  octstr_destroy(header_value);
818  return NO_USERNAME;
819 
820 no_response2:
822  octstr_destroy(header_value);
823  return NO_USERNAME;
824 
825 no_response3:
826  return NO_USERNAME;
827 
828 no_response4:
830  octstr_destroy(header_value);
831  return NO_PASSWORD;
832 }
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
void octstr_strip_blanks(Octstr *text)
Definition: octstr.c:1346
unsigned char * username
Definition: test_cimd2.c:99
unsigned char * password
Definition: test_cimd2.c:100
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
void octstr_delete(Octstr *ostr1, long pos, long len)
Definition: octstr.c:1527
int octstr_ncompare(const Octstr *ostr1, const Octstr *ostr2, long n)
Definition: octstr.c:952
#define octstr_duplicate(ostr)
Definition: octstr.h:187
#define http_header_find_first(headers, name)
Definition: http.h:603
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
void octstr_destroy_item(void *os)
Definition: octstr.c:336
void octstr_base64_to_binary(Octstr *ostr)
Definition: octstr.c:663
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
Definition: octstr.c:118
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
long http_header_remove_all(List *headers, char *name)
Definition: http.c:3135
List * octstr_split(const Octstr *os, const Octstr *sep)
Definition: octstr.c:1640
Definition: list.c:102
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

◆ user_find_by_username()

static WAPPushUser * user_find_by_username ( Octstr username)
static

Definition at line 639 of file wap_push_ppg_pushuser.c.

References dict_get(), gwlist_get(), gwlist_len(), WAPPushUserList::list, WAPPushUserList::names, octstr_compare(), WAPPushUser::username, username, and users.

Referenced by wap_push_ppg_pushuser_authenticate(), wap_push_ppg_pushuser_client_phone_number_acceptable(), wap_push_ppg_pushuser_dlr_url_get(), wap_push_ppg_pushuser_smsbox_id_get(), and wap_push_ppg_pushuser_smsc_id_get().

640 {
641  WAPPushUser *u;
642  long i;
643  List *list;
644 
645  if (username == NULL)
646  return NULL;
647 
648  if ((list = dict_get(users->names, username)) == NULL)
649  return NULL;
650 
651  for (i = 0; i < gwlist_len(users->list); ++i) {
652  u = gwlist_get(users->list, i);
653  if (octstr_compare(u->username, username) == 0)
654  return u;
655  }
656 
657  return NULL;
658 }
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
unsigned char * username
Definition: test_cimd2.c:99
void * dict_get(Dict *dict, Octstr *key)
Definition: dict.c:286
static WAPPushUserList * users
Definition: list.c:102
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:871

◆ wap_push_ppg_pushuser_authenticate()

int wap_push_ppg_pushuser_authenticate ( HTTPClient c,
List cgivars,
Octstr ip,
List push_headers,
Octstr **  username 
)

Definition at line 223 of file wap_push_ppg_pushuser.c.

References ADDITION, challenge(), dict_get(), dict_put(), dict_remove(), error(), ip_allowed_by_user(), next_try, NO_USERNAME, octstr_destroy(), octstr_duplicate, octstr_format(), octstr_get_cstr, octstr_parse_long(), parse_cgivars_for_password(), parse_cgivars_for_username(), password, password_matches(), reply(), response(), user_find_by_username(), and username.

Referenced by pap_request_thread().

224  {
225  time_t now;
226  static long next = 0L; /* used only in this thread (and this
227  function) */
228  long next_time;
229  Octstr *next_time_os;
230  static long multiplier = 1L; /* ditto */
231  WAPPushUser *u;
232  Octstr *copy,
233  *password;
234  int ret;
235 
236  copy = octstr_duplicate(ip);
237  time(&now);
238  next_time_os = NULL;
239 
240  if ((ret = response(push_headers, username, &password)) == NO_USERNAME) {
241  if (!parse_cgivars_for_username(cgivars, username)) {
242  error(0, "no user specified, challenging regardless");
243  goto listed;
244  }
245  }
246 
247  if (password == NULL)
249 
251  if (!ip_allowed_by_user(u, ip)) {
252  goto not_listed;
253  }
254 
255  next = 0;
256 
257  if ((next_time_os = dict_get(next_try, ip)) != NULL) {
258  octstr_parse_long(&next_time, next_time_os, 0, 10);
259  if (difftime(now, (time_t) next_time) < 0) {
260  error(0, "another try from %s, not much time used",
261  octstr_get_cstr(copy));
262  goto listed;
263  }
264  }
265 
266  if (u == NULL) {
267  error(0, "user %s is not allowed by users list, challenging",
269  goto listed;
270  }
271 
272  if (!password_matches(u, password)) {
273  error(0, "wrong or missing password in request from %s, challenging" ,
274  octstr_get_cstr(copy));
275  goto listed;
276  }
277 
278  dict_remove(next_try, ip); /* no restrictions after authentica-
279  tion */
281  octstr_destroy(copy);
282  octstr_destroy(next_time_os);
283  return 1;
284 
285 not_listed:
287  octstr_destroy(copy);
288  reply(c, push_headers);
289  octstr_destroy(next_time_os);
290  return 0;
291 
292 listed:
293  challenge(c, push_headers);
294 
295  multiplier <<= 1;
296  next = next + multiplier * ADDITION;
297  next += now;
298  next_time_os = octstr_format("%ld", next);
299  dict_put(next_try, ip, next_time_os);
300 
301  octstr_destroy(copy);
303 
304  return 0;
305 }
void error(int err, const char *fmt,...)
Definition: log.c:648
static Dict * next_try
void dict_put(Dict *dict, Octstr *key, void *value)
Definition: dict.c:240
static int password_matches(WAPPushUser *u, Octstr *password)
static int parse_cgivars_for_password(List *cgivars, Octstr **password)
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
unsigned char * username
Definition: test_cimd2.c:99
unsigned char * password
Definition: test_cimd2.c:100
void * dict_remove(Dict *dict, Octstr *key)
Definition: dict.c:307
void * dict_get(Dict *dict, Octstr *key)
Definition: dict.c:286
#define octstr_duplicate(ostr)
Definition: octstr.h:187
static int ip_allowed_by_user(WAPPushUser *u, Octstr *ip)
#define ADDITION
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2464
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
Definition: octstr.c:118
long octstr_parse_long(long *nump, Octstr *ostr, long pos, int base)
Definition: octstr.c:749
static int parse_cgivars_for_username(List *cgivars, Octstr **username)
static int response(List *push_headers, Octstr **username, Octstr **password)
static void challenge(HTTPClient *c, List *push_headers)
static void reply(HTTPClient *c, List *push_headers)
static WAPPushUser * user_find_by_username(Octstr *username)

◆ wap_push_ppg_pushuser_client_phone_number_acceptable()

int wap_push_ppg_pushuser_client_phone_number_acceptable ( Octstr username,
Octstr number 
)

Definition at line 312 of file wap_push_ppg_pushuser.c.

References blacklisted(), error(), number, octstr_get_cstr, prefix_allowed(), user_find_by_username(), username, and whitelisted().

Referenced by pap_request_thread().

314 {
315  WAPPushUser *u;
316 
318  if (!prefix_allowed(u, number)) {
319  error(0, "Number %s not allowed by user %s (wrong prefix)",
321  return 0;
322  }
323 
324  if (blacklisted(u, number)) {
325  error(0, "Number %s not allowed by user %s (blacklisted)",
327  return 0;
328  }
329 
330  if (!whitelisted(u, number)) {
331  error(0, "Number %s not allowed by user %s (not whitelisted)",
333  return 0;
334  }
335 
336  return 1;
337 }
void error(int err, const char *fmt,...)
Definition: log.c:648
int number
Definition: smsc_cimd2.c:213
static int whitelisted(WAPPushUser *u, Octstr *number)
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
static int blacklisted(WAPPushUser *u, Octstr *number)
unsigned char * username
Definition: test_cimd2.c:99
static int prefix_allowed(WAPPushUser *u, Octstr *number)
static WAPPushUser * user_find_by_username(Octstr *username)

◆ wap_push_ppg_pushuser_dlr_url_get()

Octstr* wap_push_ppg_pushuser_dlr_url_get ( Octstr username)

Definition at line 400 of file wap_push_ppg_pushuser.c.

References WAPPushUser::dlr_url, dlr_url, octstr_duplicate, user_find_by_username(), and username.

Referenced by set_dlr_url().

401 {
402  WAPPushUser *u;
403  Octstr *dlr_url;
404 
406  dlr_url = u->dlr_url;
407 
408  return octstr_duplicate(dlr_url);
409 }
unsigned char * username
Definition: test_cimd2.c:99
static Octstr * dlr_url
Definition: test_ppg.c:107
#define octstr_duplicate(ostr)
Definition: octstr.h:187
Definition: octstr.c:118
static WAPPushUser * user_find_by_username(Octstr *username)

◆ wap_push_ppg_pushuser_list_add()

int wap_push_ppg_pushuser_list_add ( List list,
long  number_of_pushes,
long  number_of_users 
)

Definition at line 156 of file wap_push_ppg_pushuser.c.

References dict_create(), gw_assert(), gwlist_destroy(), gwlist_extract_first(), WAPPushUserList::list, next_try, number_of_pushes, number_of_users, octstr_destroy_item(), oneuser_add(), pushusers_create(), and users.

Referenced by read_ppg_config().

158 {
159  CfgGroup *grp;
160 
163  gw_assert(list);
164  while (list && (grp = gwlist_extract_first(list))) {
165  if (oneuser_add(grp) == -1) {
166  gwlist_destroy(list, NULL);
167  return 0;
168  }
169  }
170  gwlist_destroy(list, NULL);
171 
172  return 1;
173 }
Dict * dict_create(long size_hint, void(*destroy_value)(void *))
Definition: dict.c:192
static Dict * next_try
gw_assert(wtls_machine->packet_to_send !=NULL)
static int oneuser_add(CfgGroup *cfg)
static long number_of_users
Definition: wap_push_ppg.c:193
void * gwlist_extract_first(List *list)
Definition: list.c:305
static WAPPushUserList * pushusers_create(long number_of_users)
static WAPPushUserList * users
void octstr_destroy_item(void *os)
Definition: octstr.c:336
static long number_of_pushes
Definition: wap_push_ppg.c:191
Definition: cfg.c:73
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

◆ wap_push_ppg_pushuser_list_destroy()

void wap_push_ppg_pushuser_list_destroy ( void  )

Definition at line 175 of file wap_push_ppg_pushuser.c.

References destroy_oneuser(), dict_destroy(), gwlist_destroy(), WAPPushUserList::list, WAPPushUserList::names, next_try, and users.

Referenced by wap_push_ppg_shutdown().

176 {
178  if (users == NULL)
179  return;
180 
183  gw_free(users);
184 }
static Dict * next_try
static void destroy_oneuser(void *p)
static WAPPushUserList * users
void dict_destroy(Dict *dict)
Definition: dict.c:215
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

◆ wap_push_ppg_pushuser_search_ip_from_wildcarded_list()

int wap_push_ppg_pushuser_search_ip_from_wildcarded_list ( Octstr haystack,
Octstr needle,
Octstr gwlist_sep,
Octstr ip_sep 
)

Definition at line 339 of file wap_push_ppg_pushuser.c.

References found, gw_assert(), gwlist_destroy(), gwlist_get(), gwlist_len(), octstr_destroy_item(), octstr_search(), octstr_search_char(), octstr_split(), and wildcarded_ip_found().

Referenced by ip_allowed_by_ppg(), and ip_allowed_by_user().

341 {
342  List *ips;
343  long i;
344  Octstr *configured_ip;
345 
346  gw_assert(haystack);
347  gw_assert(gwlist_sep);
348  gw_assert(ip_sep);
349 
350  /*There are no wildcards in the list*/
351  if (octstr_search_char(haystack, '*', 0) < 0) {
352  if (octstr_search(haystack, needle, 0) >= 0) {
353  return 1;
354  } else {
355  return 0;
356  }
357  }
358 
359  /*There are wildcards in the list*/
360  configured_ip = NULL;
361  ips = octstr_split(haystack, gwlist_sep);
362  for (i = 0; i < gwlist_len(ips); ++i) {
363  configured_ip = gwlist_get(ips, i);
364  if (wildcarded_ip_found(configured_ip, needle, ip_sep))
365  goto found;
366  }
367 
369  return 0;
370 
371 found:
373  return 1;
374 }
gw_assert(wtls_machine->packet_to_send !=NULL)
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
long octstr_search(const Octstr *haystack, const Octstr *needle, long pos)
Definition: octstr.c:1070
long octstr_search_char(const Octstr *ostr, int ch, long pos)
Definition: octstr.c:1012
static struct pid_list * found
static int wildcarded_ip_found(Octstr *ip, Octstr *needle, Octstr *ip_sep)
void octstr_destroy_item(void *os)
Definition: octstr.c:336
Definition: octstr.c:118
List * octstr_split(const Octstr *os, const Octstr *sep)
Definition: octstr.c:1640
Definition: list.c:102
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

◆ wap_push_ppg_pushuser_smsbox_id_get()

Octstr* wap_push_ppg_pushuser_smsbox_id_get ( Octstr username)

Definition at line 414 of file wap_push_ppg_pushuser.c.

References octstr_duplicate, WAPPushUser::smsbox_id, smsbox_id, user_find_by_username(), and username.

Referenced by set_smsbox_id().

415 {
416  WAPPushUser *u;
417  Octstr *smsbox_id;
418 
420  smsbox_id = u->smsbox_id;
421 
422  return octstr_duplicate(smsbox_id);
423 }
static Octstr * smsbox_id
Definition: smsbox.c:120
unsigned char * username
Definition: test_cimd2.c:99
#define octstr_duplicate(ostr)
Definition: octstr.h:187
Definition: octstr.c:118
static WAPPushUser * user_find_by_username(Octstr *username)

◆ wap_push_ppg_pushuser_smsc_id_get()

Octstr* wap_push_ppg_pushuser_smsc_id_get ( Octstr username)

Definition at line 380 of file wap_push_ppg_pushuser.c.

References default_smsc(), forced_smsc(), octstr_duplicate, smsc_id, user_find_by_username(), and username.

Referenced by set_smsc_id().

381 {
382  WAPPushUser *u;
383  Octstr *smsc_id;
384 
385  if ((u = user_find_by_username(username)) == NULL) {
386  /* no user found with this username */
387  return NULL;
388  }
389 
390  if ((smsc_id = forced_smsc(u)) != NULL)
391  return octstr_duplicate(smsc_id);
392 
393  smsc_id = default_smsc(u);
394  return octstr_duplicate(smsc_id);
395 }
static Octstr * default_smsc(WAPPushUser *u)
unsigned char * username
Definition: test_cimd2.c:99
#define octstr_duplicate(ostr)
Definition: octstr.h:187
static Octstr * smsc_id
Definition: mtbatch.c:98
Definition: octstr.c:118
static Octstr * forced_smsc(WAPPushUser *u)
static WAPPushUser * user_find_by_username(Octstr *username)

◆ whitelisted()

static int whitelisted ( WAPPushUser u,
Octstr number 
)
static

Definition at line 964 of file wap_push_ppg_pushuser.c.

References number, numhash_find_number(), WAPPushUser::white_list, and WAPPushUser::white_list_regex.

Referenced by wap_push_ppg_pushuser_client_phone_number_acceptable().

965 {
966  int result = 1;
967 
968  if (u->white_list != NULL)
969  result = numhash_find_number(u->white_list, number);
970 
971  if ((result == 0) && (u->white_list_regex != NULL))
972  result = gw_regex_match_pre(u->white_list_regex, number);
973 
974  return result;
975 }
int number
Definition: smsc_cimd2.c:213
regex_t * white_list_regex
int numhash_find_number(Numhash *table, Octstr *nro)
Definition: numhash.c:218

◆ wildcarded_ip_found()

static int wildcarded_ip_found ( Octstr ip,
Octstr needle,
Octstr ip_sep 
)
static

Definition at line 668 of file wap_push_ppg_pushuser.c.

References gw_assert(), gwlist_destroy(), gwlist_get(), gwlist_len(), octstr_compare(), octstr_destroy_item(), octstr_imm(), and octstr_split().

Referenced by wap_push_ppg_pushuser_search_ip_from_wildcarded_list().

669 {
670  List *ip_fragments,
671  *needle_fragments;
672  long i;
673  Octstr *ip_fragment,
674  *needle_fragment;
675 
676  ip_fragments = octstr_split(ip, ip_sep);
677  needle_fragments = octstr_split(needle, ip_sep);
678 
679  gw_assert(gwlist_len(ip_fragments) == gwlist_len(needle_fragments));
680  for (i = 0; i < gwlist_len(ip_fragments); ++i) {
681  ip_fragment = gwlist_get(ip_fragments, i);
682  needle_fragment = gwlist_get(needle_fragments, i);
683  if (octstr_compare(ip_fragment, needle_fragment) != 0 &&
684  octstr_compare(ip_fragment, octstr_imm("*")) != 0)
685  goto not_found;
686  }
687 
688  gwlist_destroy(ip_fragments, octstr_destroy_item);
689  gwlist_destroy(needle_fragments, octstr_destroy_item);
690  return 1;
691 
692 not_found:
693  gwlist_destroy(ip_fragments, octstr_destroy_item);
694  gwlist_destroy(needle_fragments, octstr_destroy_item);
695  return 0;
696 }
gw_assert(wtls_machine->packet_to_send !=NULL)
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
void octstr_destroy_item(void *os)
Definition: octstr.c:336
Definition: octstr.c:118
List * octstr_split(const Octstr *os, const Octstr *sep)
Definition: octstr.c:1640
Definition: list.c:102
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:871
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

Variable Documentation

◆ next_try

◆ users

See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.