📄 dlr.c
字号:
* has been specified, warn the user anyway */ if (dlr_type == NULL) { dlr_type = octstr_imm("internal"); warning(0, "DLR: using default 'internal' for storage type."); } /* call the sub-init routine */ if (octstr_compare(dlr_type, octstr_imm("mysql")) == 0) { handles = dlr_init_mysql(cfg); } else if (octstr_compare(dlr_type, octstr_imm("sdb")) == 0) { handles = dlr_init_sdb(cfg); } else if (octstr_compare(dlr_type, octstr_imm("oracle")) == 0) { handles = dlr_init_oracle(cfg); } else if (octstr_compare(dlr_type, octstr_imm("internal")) == 0) { handles = dlr_init_mem(cfg); } else if (octstr_compare(dlr_type, octstr_imm("pgsql")) == 0) { handles = dlr_init_pgsql(cfg); } /* * add aditional types here */ if (handles == NULL) { panic(0, "DLR: storage type '%s' is not supported!", octstr_get_cstr(dlr_type)); } /* check needed function pointers */ if (handles->dlr_add == NULL || handles->dlr_get == NULL || handles->dlr_remove == NULL) panic(0, "DLR: storage type '%s' don't implement needed functions", octstr_get_cstr(dlr_type)); /* get info from storage */ info(0, "DLR using storage type: %s", handles->type); /* cleanup */ octstr_destroy(dlr_type);}/* * Shutdown dlr storage */void dlr_shutdown(){ if (handles != NULL && handles->dlr_shutdown != NULL) handles->dlr_shutdown();}/* * Return count waiting delivery entries or -1 if error occurs */long dlr_messages(void){ if (handles != NULL && handles->dlr_messages != NULL) return handles->dlr_messages(); return -1;}/* * Return type of used dlr storage */const char* dlr_type(void){ if (handles != NULL && handles->type != NULL) return handles->type; return "unknown";} /* * Add new dlr entry into dlr storage */void dlr_add(const Octstr *smsc, const Octstr *ts, const Msg *msg){ struct dlr_entry *dlr = NULL; if(octstr_len(smsc) == 0) { warning(0, "DLR[%s]: Can't add a dlr without smsc-id", dlr_type()); return; } /* sanity check */ if (handles == NULL || handles->dlr_add == NULL || msg == NULL) return; /* check if delivery receipt requested */ if (!DLR_IS_ENABLED(msg->sms.dlr_mask)) return; /* allocate new struct dlr_entry struct */ dlr = dlr_entry_create(); gw_assert(dlr != NULL); /* now copy all values, we are interested in */ dlr->smsc = (smsc ? octstr_duplicate(smsc) : octstr_create("")); dlr->timestamp = (ts ? octstr_duplicate(ts) : octstr_create("")); dlr->source = (msg->sms.sender ? octstr_duplicate(msg->sms.sender) : octstr_create("")); dlr->destination = (msg->sms.receiver ? octstr_duplicate(msg->sms.receiver) : octstr_create("")); dlr->service = (msg->sms.service ? octstr_duplicate(msg->sms.service) : octstr_create("")); dlr->url = (msg->sms.dlr_url ? octstr_duplicate(msg->sms.dlr_url) : octstr_create("")); dlr->boxc_id = (msg->sms.boxc_id ? octstr_duplicate(msg->sms.boxc_id) : octstr_create("")); dlr->mask = msg->sms.dlr_mask; debug("dlr.dlr", 0, "DLR[%s]: Adding DLR smsc=%s, ts=%s, src=%s, dst=%s, mask=%d, boxc=%s", dlr_type(), octstr_get_cstr(dlr->smsc), octstr_get_cstr(dlr->timestamp), octstr_get_cstr(dlr->source), octstr_get_cstr(dlr->destination), dlr->mask, octstr_get_cstr(dlr->boxc_id)); /* call registered function */ handles->dlr_add(dlr);}/* * Return Msg* if dlr entry found in DB, otherwise NULL. * NOTE: If typ is end status (e.g. DELIVERED) then dlr entry * will be removed from DB. */Msg *dlr_find(const Octstr *smsc, const Octstr *ts, const Octstr *dst, int typ){ Msg *msg = NULL; struct dlr_entry *dlr = NULL; if(octstr_len(smsc) == 0) { warning(0, "DLR[%s]: Can't find a dlr without smsc-id", dlr_type()); return NULL; } /* check if we have handler registered */ if (handles == NULL || handles->dlr_get == NULL) return NULL; debug("dlr.dlr", 0, "DLR[%s]: Looking for DLR smsc=%s, ts=%s, dst=%s, type=%d", dlr_type(), octstr_get_cstr(smsc), octstr_get_cstr(ts), octstr_get_cstr(dst), typ); dlr = handles->dlr_get(smsc, ts, dst); if (dlr == NULL) { warning(0, "DLR[%s]: DLR for DST<%s> not found.", dlr_type(), octstr_get_cstr(dst)); return NULL; }#define O_SET(x, val) if (octstr_len(val) > 0) { x = val; val = NULL; } if ((typ & dlr->mask) > 0) { /* its an entry we are interested in */ msg = msg_create(sms); msg->sms.sms_type = report_mo; msg->sms.dlr_mask = typ; O_SET(msg->sms.service, dlr->service); O_SET(msg->sms.smsc_id, dlr->smsc); O_SET(msg->sms.receiver, dlr->destination); O_SET(msg->sms.sender, dlr->source); /* if dlr_url was present, recode it here again */ O_SET(msg->sms.dlr_url, dlr->url); /* * insert original message to the data segment * later in the smsc module */ msg->sms.msgdata = NULL; /* * If a boxc_id is available, then instruct bearerbox to * route this msg back to originating smsbox */ O_SET(msg->sms.boxc_id, dlr->boxc_id); time(&msg->sms.time); debug("dlr.dlr", 0, "DLR[%s]: created DLR message for URL <%s>", dlr_type(), (msg->sms.dlr_url?octstr_get_cstr(msg->sms.dlr_url):"")); } else { debug("dlr.dlr", 0, "DLR[%s]: Ignoring DLR message because of mask type=%d dlr->mask=%d", dlr_type(), typ, dlr->mask); /* ok that was a status report but we where not interested in having it */ msg = NULL; }#undef O_SET /* check for end status and if so remove from storage */ if ((typ & DLR_BUFFERED) && ((dlr->mask & DLR_SUCCESS) || (dlr->mask & DLR_FAIL))) { info(0, "DLR[%s]: DLR not destroyed, still waiting for other delivery report", dlr_type()); /* update dlr entry status if function defined */ if (handles != NULL && handles->dlr_update != NULL) handles->dlr_update(smsc, ts, dst, typ); } else { if (handles != NULL && handles->dlr_remove != NULL) { /* it's not good for internal storage, but better for all others */ handles->dlr_remove(smsc, ts, dst); } else { warning(0, "DLR[%s]: Storage don't have remove operation defined", dlr_type()); } } /* destroy struct dlr_entry */ dlr_entry_destroy(dlr); return msg;} void dlr_flush(void){ info(0, "Flushing all %ld queued DLR messages in %s storage", dlr_messages(), dlr_type()); if (handles != NULL && handles->dlr_flush != NULL) handles->dlr_flush();}Msg* create_dlr_from_msg(const Octstr *smsc, const Msg *msg, const Octstr *reply, long stat){ Msg *dlrmsg; if (msg == NULL) return NULL; /* generate DLR */ debug("dlr.dlr", 0,"SMSC[%s]: creating DLR message", (smsc ? octstr_get_cstr(smsc) : "UNKNOWN")); dlrmsg = msg_create(sms); gw_assert(dlrmsg != NULL); dlrmsg->sms.service = octstr_duplicate(msg->sms.service); dlrmsg->sms.dlr_mask = stat; dlrmsg->sms.sms_type = report_mo; dlrmsg->sms.smsc_id = octstr_duplicate(smsc ? smsc : msg->sms.smsc_id); dlrmsg->sms.sender = octstr_duplicate(msg->sms.sender); dlrmsg->sms.receiver = octstr_duplicate(msg->sms.receiver); dlrmsg->sms.dlr_url = octstr_duplicate(msg->sms.dlr_url); dlrmsg->sms.msgdata = octstr_duplicate(reply); dlrmsg->sms.boxc_id = octstr_duplicate(msg->sms.boxc_id); time(&dlrmsg->sms.time); debug("dlr.dlr", 0,"SMSC[%s]: DLR = %s", (smsc ? octstr_get_cstr(smsc) : "UNKNOWN"), (dlrmsg->sms.dlr_url ? octstr_get_cstr(dlrmsg->sms.dlr_url) : "")); return dlrmsg;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -