⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wap_push_ppg_pushuser.c

📁 The Kannel Open Source WAP and SMS gateway works as both an SMS gateway, for implementing keyword b
💻 C
📖 第 1 页 / 共 3 页
字号:
    /*There are wildcards in the list*/    configured_ip = NULL;    ips = octstr_split(haystack, list_sep);    for (i = 0; i < list_len(ips); ++i) {        configured_ip = list_get(ips, i);        if (wildcarded_ip_found(configured_ip, needle, ip_sep))	        goto found;    }    list_destroy(ips, octstr_destroy_item);    return 0;found:    list_destroy(ips, octstr_destroy_item);    return 1;}/* * Returns smsc-id that pushes by this user must use,  * NULL when there was an error. */Octstr *wap_push_ppg_pushuser_smsc_id_get(Octstr *username){    WAPPushUser *u;    Octstr *smsc_id;    if ((u = user_find_by_username(username)) == NULL) {        /* no user found with this username */        return NULL;    }    if ((smsc_id = forced_smsc(u)) != NULL)        return octstr_duplicate(smsc_id);    smsc_id = default_smsc(u);    return octstr_duplicate(smsc_id);}/* * Returns default dlr url for this user. */Octstr *wap_push_ppg_pushuser_dlr_url_get(Octstr *username){    WAPPushUser *u;    Octstr *dlr_url;    u = user_find_by_username(username);    dlr_url = u->dlr_url;         return octstr_duplicate(dlr_url);}/* * Returns default dlr smsbox id for this user. */Octstr *wap_push_ppg_pushuser_smsbox_id_get(Octstr *username){    WAPPushUser *u;    Octstr *smsbox_id;    u = user_find_by_username(username);    smsbox_id = u->smsbox_id;    return octstr_duplicate(smsbox_id);}/*************************************************************************** * * Implementation of internal functions */static void destroy_users_list(void *l){    list_destroy(l, NULL);}static WAPPushUserList *pushusers_create(long number_of_users) {    users = gw_malloc(sizeof(WAPPushUserList));    users->list = list_create();    users->names = dict_create(number_of_users, destroy_users_list);    return users;}/* * Allocate memory for one push user and read configuration data to it. We initial- * ize all fields to NULL, because the value NULL means that the configuration did * not have this variable.  * Return NULL when failure, a pointer to the data structure otherwise. */static WAPPushUser *create_oneuser(CfgGroup *grp){    WAPPushUser *u;    Octstr *grpname,           *os;    grpname = cfg_get(grp, octstr_imm("wap-push-user"));    if (grpname == NULL) {        error(0, "all users group (wap-push-user) are missing");        goto no_grpname;    }       u = gw_malloc(sizeof(WAPPushUser));    u->name = NULL;    u->username = NULL;                      u->allowed_prefix = NULL;               u->allowed_prefix_regex = NULL;               u->denied_prefix = NULL;                 u->denied_prefix_regex = NULL;                 u->white_list = NULL;                   u->white_list_regex = NULL;                   u->black_list = NULL;                  u->black_list_regex = NULL;                  u->user_deny_ip = NULL;                  u->user_allow_ip = NULL;    u->smsc_id = NULL;    u->default_smsc_id = NULL;    u->name = cfg_get(grp, octstr_imm("wap-push-user"));    if (u->name == NULL) {        warning(0, "user name missing, dump follows");        oneuser_dump(u);        goto error;    }    u->username = cfg_get(grp, octstr_imm("ppg-username"));    u->password = cfg_get(grp, octstr_imm("ppg-password"));    if (u->username == NULL) {        warning(0, "login name for user %s missing, dump follows",               octstr_get_cstr(u->name));        oneuser_dump(u);        goto error;    }    if (u->password == NULL) {        warning(0, "password for user %s missing, dump follows",               octstr_get_cstr(u->name));        oneuser_dump(u);        goto error;    }    u->user_deny_ip = cfg_get(grp, octstr_imm("deny-ip"));    u->user_allow_ip = cfg_get(grp, octstr_imm("allow-ip"));    u->country_prefix = cfg_get(grp, octstr_imm("country-prefix"));    u->allowed_prefix = cfg_get(grp, octstr_imm("allowed-prefix"));    u->denied_prefix = cfg_get(grp, octstr_imm("denied-prefix"));    u->smsc_id = cfg_get(grp, octstr_imm("forced-smsc"));    u->default_smsc_id = cfg_get(grp, octstr_imm("default-smsc"));    u->dlr_url = cfg_get(grp, octstr_imm("dlr-url"));    u->smsbox_id = cfg_get(grp, octstr_imm("smsbox-id"));    os = cfg_get(grp, octstr_imm("white-list"));    if (os != NULL) {	    u->white_list = numhash_create(octstr_get_cstr(os));	    octstr_destroy(os);    }    os = cfg_get(grp, octstr_imm("black-list"));    if (os != NULL) {	    u->black_list = numhash_create(octstr_get_cstr(os));	    octstr_destroy(os);    }    if ((os = cfg_get(grp, octstr_imm("allowed-prefix-regex"))) != NULL) {        if ((u->allowed_prefix_regex = gw_regex_comp(os, REG_EXTENDED)) == NULL)            panic(0, "Could not compile pattern '%s'", octstr_get_cstr(os));        octstr_destroy(os);    };    if ((os = cfg_get(grp, octstr_imm("denied-prefix-regex"))) != NULL) {        if ((u->denied_prefix_regex = gw_regex_comp(os, REG_EXTENDED)) == NULL)            panic(0, "Could not compile pattern '%s'", octstr_get_cstr(os));        octstr_destroy(os);    };    if ((os = cfg_get(grp, octstr_imm("white-list-regex"))) != NULL) {        if ((u->white_list_regex = gw_regex_comp(os, REG_EXTENDED)) == NULL)            panic(0, "Could not compile pattern '%s'", octstr_get_cstr(os));        octstr_destroy(os);    };    if ((os = cfg_get(grp, octstr_imm("black-list-regex"))) != NULL) {        if ((u->black_list_regex = gw_regex_comp(os, REG_EXTENDED)) == NULL)            panic(0, "Could not compile pattern '%s'", octstr_get_cstr(os));        octstr_destroy(os);    };    octstr_destroy(grpname);    return u;no_grpname:    octstr_destroy(grpname);    return NULL;error:    octstr_destroy(grpname);    destroy_oneuser(u);    return NULL;}static void destroy_oneuser(void *p) {     WAPPushUser *u;     u = p;     if (u == NULL)         return;     octstr_destroy(u->name);     octstr_destroy(u->username);       octstr_destroy(u->password);       octstr_destroy(u->country_prefix);                   octstr_destroy(u->allowed_prefix);                octstr_destroy(u->denied_prefix);                  numhash_destroy(u->white_list);                    numhash_destroy(u->black_list);                   octstr_destroy(u->user_deny_ip);                   octstr_destroy(u->user_allow_ip);     octstr_destroy(u->smsc_id);     octstr_destroy(u->default_smsc_id);     if (u->black_list_regex != NULL) gw_regex_destroy(u->black_list_regex);     if (u->white_list_regex != NULL) gw_regex_destroy(u->white_list_regex);     if (u->denied_prefix_regex != NULL) gw_regex_destroy(u->denied_prefix_regex);     if (u->allowed_prefix_regex != NULL) gw_regex_destroy(u->allowed_prefix_regex);     gw_free(u);             }static void oneuser_dump(WAPPushUser *u){    if (u == NULL) {        debug("wap.push.ppg.pushuser", 0, "no user found");        return;    }    debug("wap.push.ppg.pushuser", 0, "Dumping user data: Name of the user:");    octstr_dump(u->name, 0);    debug("wap.push.ppg.pushuser", 0, "username:");    octstr_dump(u->username, 0);      debug("wap.push.ppg.pushuser", 0, "omitting password");    debug("wap-push.ppg.pushuser", 0, "country prefix");    octstr_dump(u->country_prefix, 0);       debug("wap.push.ppg.pushuser", 0, "allowed prefix list:");                octstr_dump(u->allowed_prefix, 0);      debug("wap.push.ppg.pushuser", 0, "denied prefix list:");             octstr_dump(u->denied_prefix, 0);       debug("wap.push.ppg.pushuser", 0, "denied ip list:");                             octstr_dump(u->user_deny_ip, 0);        debug("wap.push.ppg.pushuser", 0, "allowed ip list:");                       octstr_dump(u->user_allow_ip, 0);    debug("wap.push.ppg.pushuser", 0, "send via smsc-id:");                       octstr_dump(u->smsc_id, 0);    debug("wap.push.ppg.pushuser", 0, "use default smsc:");    octstr_dump(u->default_smsc_id, 0);    debug("wap.push.ppg.pushuser", 0, "end of the dump");}/* * Add an user to the push users list */static int oneuser_add(CfgGroup *grp){    WAPPushUser *u;    List *list;    u = create_oneuser(grp);    if (u == NULL)        return -1;    list_append(users->list, u);    list = dict_get(users->names, u->username);    if (list == NULL) {        list = list_create();        dict_put(users->names, u->username, list);    }    return 0;}static WAPPushUser *user_find_by_username(Octstr *username){    WAPPushUser *u;    long i;    List *list;    if (username == NULL)        return NULL;    if ((list = dict_get(users->names, username)) == NULL)         return NULL;    for (i = 0; i < list_len(users->list); ++i) {         u = list_get(users->list, i);         if (octstr_compare(u->username, username) == 0)	         return u;    }    return NULL;}static int password_matches(WAPPushUser *u, Octstr *password){    if (password == NULL)        return 0;        return octstr_compare(u->password, password) == 0;}static int wildcarded_ip_found(Octstr *ip, Octstr *needle, Octstr *ip_sep){    List *ip_fragments,         *needle_fragments;    long i;    Octstr *ip_fragment,           *needle_fragment;    ip_fragments = octstr_split(ip, ip_sep);    needle_fragments = octstr_split(needle, ip_sep);    gw_assert(list_len(ip_fragments) == list_len(needle_fragments));    for (i = 0; i < list_len(ip_fragments); ++i) {        ip_fragment = list_get(ip_fragments, i);        needle_fragment = list_get(needle_fragments, i);        if (octstr_compare(ip_fragment, needle_fragment) != 0 &&                 octstr_compare(ip_fragment, octstr_imm("*")) != 0) 	        goto not_found;    }    list_destroy(ip_fragments, octstr_destroy_item);    list_destroy(needle_fragments, octstr_destroy_item);       return 1;not_found:    list_destroy(ip_fragments, octstr_destroy_item);    list_destroy(needle_fragments, octstr_destroy_item);    return 0;}/* * Deny_ip = '*.*.*.*' is here taken literally: no ips allowed by this user  * (definitely strange, but not a fatal error).  */static int ip_allowed_by_user(WAPPushUser *u, Octstr *ip){    Octstr *copy,           *ip_copy;        if (u == NULL) {        warning(0, "user not found from the users list");        goto no_user;    }    copy = octstr_duplicate(u->username);    if (u->user_deny_ip == NULL && u->user_allow_ip == NULL)        goto allowed;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -