gnokii-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gn_sms_send failed to send sms ( lack of gn_data structure )


From: we axzz
Subject: gn_sms_send failed to send sms ( lack of gn_data structure )
Date: Fri, 18 Mar 2011 14:38:22 +0700

hi all,
i got an issue when im gonna sending sms with libgnokii :

my code : 
---------------------------------
address@hidden:/tmp# cat gnokii_send_sms.c 
/* 
 * File:   gnokii_send_sms.c
 * Author: xxx
 *
 * Created on March 18, 2011, 1:30 AM
 */

#include <stdio.h>
#include <stdlib.h>
#include <gnokii.h>
#include <signal.h>
/*
 * 
 */

#define _(x) x

struct gn_statemachine *state = NULL;

void busterminate(void) {
gn_lib_phone_close(state);
gn_lib_phoneprofile_free(&state);
gn_lib_library_free();
}

void businit(void) {
gn_error error;

atexit(busterminate);

error = gn_lib_phoneprofile_load(NULL, &state);
if (GN_ERR_NONE == error) {
error = gn_lib_phone_open(state);
}

if (GN_ERR_NONE != error) {
fprintf(stderr, "%s\n", gn_error_print(error));
exit(-1);
}
}

void signal_handler(int signal) {
(void)signal;
exit(-2);
}
gn_gsm_number_type get_number_type(const char *number)
{
gn_gsm_number_type type;

if (!number)
return GN_GSM_NUMBER_Unknown;
if (*number == '+') {
type = GN_GSM_NUMBER_International;
number++;
} else {
type = GN_GSM_NUMBER_Unknown;
}
while (*number) {
if (!isdigit(*number))
return GN_GSM_NUMBER_Alphanumeric;
number++;
}
return type;
}
int main(int argc, char *argv[]) {
gn_data data;
        gn_sms          sms;
gn_error error;


businit();

signal(SIGINT, signal_handler);

gn_data_clear(&data);
        char nomor[] = "+628571641111";
        snprintf(sms.remote.number,sizeof(sms.remote.number),"%s",nomor);
        sms.remote.type = get_number_type(nomor);
        if(sms.remote.type == GN_GSM_NUMBER_Alphanumeric)
        {
            printf("invalid phone number\n");
            return GN_ERR_WRONGDATAFORMAT;
        }

        snprintf(sms.user_data[0].u.text,sizeof(sms.user_data[0].u.text),"%s","tesss");

        data.message_center    = calloc(1, sizeof(gn_sms_message_center));
        data.message_center->id= 1;

    error = gn_sm_functions(GN_OP_GetSMSCenter, &data, state);
    if(error == GN_ERR_NONE)
    {
        snprintf(sms.smsc.number,sizeof(sms.smsc.number),"%s",data.message_center->smsc.number); // set to sms.smsc.number from data.sms.smsc.number
        sms.smsc.type = data.message_center->smsc.type;
        //g_slice_free(gn_sms_message_center,data->message_center); // free the ram
        free(data.message_center);
    }
    if(!sms.smsc.number[0])
    {
        printf("failed once getting sms center number\n");

    }
    if(!sms.smsc.type)
    {
        sms.smsc.type = GN_GSM_NUMBER_Unknown;
    }

     data.sms = &sms;

    //send the message
    error = gn_sms_send(&data,state);

    if(error == GN_ERR_NONE)
    {
        if(sms.parts > 1)
        {
            int j;
            printf("sms sent with : %d parts, and reference number is : ", sms.parts);

            for(j=0; j < sms.parts; j++)
            {
                printf("%d\n",sms.reference[j]);
            }
        }
        else
        {
            printf("one sms sent with reference number : %d\n",sms.reference[0]);
        }
    }
    else
    {
        printf("libgnokii error : %s\n",gn_error_print(error));
    }

    free(sms.reference);

    return 0;
}
address@hidden:/tmp# 


compiling and running : 
---------------------------------
address@hidden:/tmp# gcc -o gnokii_send_sms gnokii_send_sms.c `pkg-config --libs gnokii`
address@hidden:/tmp# gnokii --showsmsfolderstatus
GNOKII Version 0.6.29
No. Name                                         Id #Msg
========================================================
  0 Internal memory                              ME 4725
  1 SIM card                                     SM    8
address@hidden:/tmp# gdb -q ./gnokii_send_sms
Reading symbols from /tmp/gnokii_send_sms...(no debugging symbols found)...done.
(gdb) r
Starting program: /tmp/gnokii_send_sms 
[Thread debugging using libthread_db enabled]

Program received signal SIGSEGV, Segmentation fault.
0x0015321e in ?? () from /usr/lib/libgnokii.so.6
(gdb) bt
#0  0x0015321e in ?? () from /usr/lib/libgnokii.so.6
#1  0x00154fea in gn_sms_send () from /usr/lib/libgnokii.so.6
#2  0x08048bc0 in main ()
(gdb) 



and anyway, what are uninitialized var that need to be initialzed in 'gn_data structure', before gn_sms_send() function take 'gn_data structure' and spin ?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]