Beispiel #1
0
void sms_test2(int m)
{
    LOGR("sms_test2 %d\n", m);
    sms_hdr_t hdr ;
    sms_bdy_t bdy ;

#if 0
    // 204
    hdr.dstadr[0] = 0xCC ;
    hdr.dstadr[1] = 0x00 ;
    hdr.dstadr[2] = 0x00 ;
#endif
#if 1
    // all
    hdr.dstadr[0] = 0xFF ;
    hdr.dstadr[1] = 0xFF ;
    hdr.dstadr[2] = 0xFF ;
#endif

    hdr.flags = m ;

    wide_sprintf(bdy.txt,"md380tools rulez");

    sms_send( &hdr, &bdy );
}
Beispiel #2
0
void sms_test()
{
    sms_hdr_t hdr ;
    sms_bdy_t bdy ;

#if 0
    // 204
    hdr.dstadr[0] = 0xCC ;
    hdr.dstadr[1] = 0x00 ;
    hdr.dstadr[2] = 0x00 ;
#endif
#if 0
    // all
    hdr.dstadr[0] = 0xFF ;
    hdr.dstadr[1] = 0xFF ;
    hdr.dstadr[2] = 0xFF ;
#endif
#if 1
    // Null
    hdr.dstadr[0] = 0x0 ;
    hdr.dstadr[1] = 0x0 ;
    hdr.dstadr[2] = 0x0 ;
#endif

//    hdr.flags = SMS_TYPE_SINGLECAST ;
    hdr.flags = SMS_TYPE_MULTICAST ;

//    wide_sprintf(hdr.adr,"");

    wide_sprintf(bdy.txt,"md380tools rulez");

    sms_send( &hdr, &bdy );
}
Beispiel #3
0
uint8_t pdu_parser(uint8_t *pdu) 
{
    uint8_t i = 3;
    uint8_t ret_val = 1;
    int16_t write_len = 0;
    uint16_t reply_len = 0;

    SMS_DEBUG("pdu_parser called: %d\n", pdu[i]);
    if (pdu[i++] == '+') {
        SMS_DEBUG("pdu_parser called: %d\n", pdu[i]);
        if (!strncmp((char *) pdu + i, "CMGL", 4)) {    
            SMS_DEBUG("messages will be received\r\n");
            uint8_t smsc_len, sender_len;
            if (reply_len == 0) {
                while (pdu[++i] != '\n');
                i ++;
                /* get length of smsc number */
                sscanf((char *) pdu + i, "%02hhX", &smsc_len);
                /* we ignore some flags "0000" */
                i += (smsc_len * 2) + 4;
                /* get data length */
                sscanf((char *) pdu + i, "%02hhX", &sender_len);
                /* get number of message sender */
                strncpy(nummer, (char *) pdu + i, sender_len + 5);
                nummer[sender_len + 5] = '\0';
                i = i + sender_len + 5 + 18;
                read_sms((uint8_t *) pdu + i);
            }
            
            SMS_DEBUG("ecmd: %s\n", text);
            do {
                if (reply_len < (int16_t)sizeof(write_buffer)) {
                    write_len = ecmd_parse_command((char *) text, 
                                              write_buffer + reply_len, 
                                              sizeof(write_buffer) - reply_len - 1);
                    SMS_DEBUG("ret_len ecmd parser: %d\r\n", write_len);
                    if (is_ECMD_AGAIN(write_len)) {
                        reply_len += -(10 + write_len);
                        *(write_buffer + reply_len) = ' ';
                        reply_len++;
                    } 
                    else if (write_len > 0) {
                        SMS_DEBUG("finished: \"%s\"\n", write_buffer);
                        ret_val = 0;
                        reply_len += write_len;
                        break;
                    }
                    SMS_DEBUG("%s\n", write_buffer);
                }
                else {
                    break;
                }
            } while (write_len <= 0);
           
            write_buffer[reply_len] = '\0';
            sms_send((uint8_t *) nummer, (uint8_t *) write_buffer, NULL, 1);
        }
    }
    return ret_val;
}
Beispiel #4
0
int sms_notify(const char *proc, ACL_ARGV *rcpts,
	int pid, const char *info)
{
	ACL_ITER iter;
	ACL_VSTREAM *client;
	char  ip[64], *ptr;

	if (var_cfg_sms_addr == NULL || *var_cfg_sms_addr == 0) {
		acl_msg_info("%s(%d): var_cfg_sms_addr null",
			__FUNCTION__, __LINE__);
		return (0);
	}

	client = acl_vstream_connect(var_cfg_sms_addr, ACL_BLOCKING,
			30, 30, 4096);
	if (client == NULL) {
		acl_msg_error("%s(%d): connect %s error(%s)",
			__FUNCTION__, __LINE__,
			var_cfg_sms_addr, acl_last_serror());
		return (-1);
	}

	if (var_cfg_host_ip && *var_cfg_host_ip) {
		snprintf(ip, sizeof(ip), "%s", var_cfg_host_ip);
	} else if (acl_getsockname(ACL_VSTREAM_SOCK(client), ip, sizeof(ip)) < 0) {
		acl_msg_warn("%s(%d): get local ip error: %s",
			__FUNCTION__, __LINE__, acl_last_serror());
		snprintf(ip, sizeof(ip), "127.0.0.1");
	} else {
		ptr = strchr(ip, ':');
		if (ptr)
			*ptr = 0;
	}

	acl_foreach(iter, rcpts) {
		const char *phone = (const char*) iter.data;
		if (sms_send(client, phone, proc, pid, info, ip) < 0)
			break;
	}

	acl_vstream_close(client);
	return (0);
}
Beispiel #5
0
static void wrapper_sender(void *arg)
{
    Msg 	*msg;
    SMSCConn 	*conn = arg;
    SmscWrapper *wrap = conn->data;

    /* Make sure we log into our own log-file if defined */
    log_thread_to(conn->log_idx);

    /* send messages to SMSC until our outgoing_list is empty and
     * no producer anymore (we are set to shutdown) */
    while(conn->status != SMSCCONN_DEAD) {

	if ((msg = gwlist_consume(wrap->outgoing_queue)) == NULL)
            break;

        if (octstr_search_char(msg->sms.receiver, ' ', 0) != -1) {
            /*
             * multi-send: this should be implemented in corresponding
             *  SMSC protocol, but while we are waiting for that...
             */
            int i;
	    Msg *newmsg;
            /* split from spaces: in future, split with something more sensible,
             * this is dangerous... (as space is url-encoded as '+')
             */
            List *nlist = octstr_split_words(msg->sms.receiver);

	    debug("bb.sms", 0, "Handling multi-receiver message");

            for(i=0; i < gwlist_len(nlist); i++) {

		newmsg = msg_duplicate(msg);
                octstr_destroy(newmsg->sms.receiver);

                newmsg->sms.receiver = gwlist_get(nlist, i);
                sms_send(conn, newmsg);
            }
            gwlist_destroy(nlist, NULL);
            msg_destroy(msg);
        }
        else
	    sms_send(conn,msg);

    }
    /* cleanup, we are now dying */

    debug("bb.sms", 0, "SMSCConn %s sender died, waiting for receiver",
	  octstr_get_cstr(conn->name));
    
    conn->why_killed = SMSCCONN_KILLED_SHUTDOWN;

    if (conn->is_stopped) {
	gwlist_remove_producer(wrap->stopped);
	conn->is_stopped = 0;
    }

    gwthread_wakeup(wrap->receiver_thread);
    gwthread_join(wrap->receiver_thread);

    /* call 'failed' to all messages still in queue */
    
    mutex_lock(conn->flow_mutex);

    conn->status = SMSCCONN_DEAD;

    while((msg = gwlist_extract_first(wrap->outgoing_queue))!=NULL) {
	bb_smscconn_send_failed(conn, msg, SMSCCONN_FAILED_SHUTDOWN, NULL);
    }
    smscwrapper_destroy(wrap);
    conn->data = NULL;
    
    mutex_unlock(conn->flow_mutex);

    bb_smscconn_killed();
}