Changeset 11546


Ignore:
Timestamp:
Aug 30, 2019, 8:47:21 PM (3 weeks ago)
Author:
nautilus7
Message:

[gbox] Cosmetics

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/module-gbox-sms.c

    r11545 r11546  
    1313#include "oscam-lock.h"
    1414
    15 static int32_t poll_gsms_data (uint16_t *boxid, uint8_t *num, char *text)
     15static int32_t poll_gsms_data(uint16_t *boxid, uint8_t *num, char *text)
    1616{
    1717    char *fext= FILE_GSMS_TXT;
    1818    char *fname = get_gbox_tmp_fname(fext);
     19
    1920    FILE *fhandle = fopen(fname, "r");
    2021    if(!fhandle)
     
    3031
    3132    memset(buffer, 0, sizeof(buffer));
    32     fseek(fhandle, 0L, SEEK_END);
     33    fseek(fhandle, 0, SEEK_END);
    3334    length1 = ftell(fhandle);
    34     fseek(fhandle, 0L, SEEK_SET);
     35    fseek(fhandle, 0, SEEK_SET);
    3536
    3637    if(length1 < 13)
     
    4445    if(fgets(buffer, 140, fhandle) != NULL)
    4546    {
    46         *boxid = strtol (buffer, &tail, 16);
    47         *num = atoi (tail);
     47        *boxid = strtol(buffer, &tail, 16);
     48        *num = atoi(tail);
    4849    }
    4950
     
    5152    unlink(fname);
    5253
    53     if (length1 > (127 + 7))
     54    if(length1 > 127 + 7)
    5455    {
    5556        length = 127 + 7;
     
    6061    }
    6162
    62     cs_log_dbg(D_READER, "total msg length taken from %s = %d, limitted to %d", fname, length1, length);
     63    cs_log_dbg(D_READER, "total msg length taken from %s = %d, limited to %d", fname, length1, length);
    6364    cs_strncpy(text, buffer + 7, sizeof(buffer));
    6465
    6566    return 0;
    6667}
     68
    6769static void write_gsms_to_osd_file(struct s_client *cli, uint8_t *gsms)
    6870{
     
    7981        {
    8082            if(!isalnum(gsms[i]) && gsms[i] != ' ')
    81                 { gsms[i] = '_'; }
     83            {
     84                gsms[i] = '_';
     85            }
    8286        }
    8387
     
    8892        char *cmd = gsms_buf;
    8993        FILE *p;
    90         if ((p = popen(cmd, "w")) == NULL)
    91         {
    92             cs_log("Error %s",fname);
     94        if((p = popen(cmd, "w")) == NULL)
     95        {
     96            cs_log("Error %s", fname);
    9397            return;
    9498        }
     99
    95100        pclose(p);
    96101    }
    97     return;
    98 }
    99 
    100 void write_gsms_ack (struct s_client *cli)
     102
     103    return;
     104}
     105
     106void write_gsms_ack(struct s_client *cli)
    101107{
    102108    char tsbuf[28];
     
    106112    char *fext = FILE_GSMS_ACK;
    107113    char *fname = get_gbox_tmp_fname(fext);
     114
    108115    FILE *fhandle = fopen(fname, "a+");
    109116    if(!fhandle)
     
    112119        return;
    113120    }
    114     fprintf(fhandle, "Peer %04X (%s) confirmed receipt of GSMS on %s",peer->gbox.id, cli->reader->device, tsbuf);
     121
     122    fprintf(fhandle, "Peer %04X (%s) confirmed receipt of GSMS on %s", peer->gbox.id, cli->reader->device, tsbuf);
    115123    fclose(fhandle);
    116124    return;
    117125}
    118126
    119 static void write_gsms_nack (struct s_client *cl, uint8_t inf)
     127static void write_gsms_nack(struct s_client *cl, uint8_t inf)
    120128{
    121129    char tsbuf[28];
     
    148156}
    149157
    150 void write_gsms_msg (struct s_client *cli, uint8_t *gsms, uint16_t type, uint16_t UNUSED(msglen))
     158void write_gsms_msg(struct s_client *cli, uint8_t *gsms, uint16_t type, uint16_t UNUSED(msglen))
    151159{
    152160    char tsbuf[28];
     
    167175    if(type == 0x30)
    168176    {
    169         fprintf(fhandle, "Normal message received from %04X %s on %s%s\n\n",
    170             peer->gbox.id, cli->reader->device, tsbuf, gsms);
     177        fprintf(fhandle, "Normal message received from %04X %s on %s%s\n\n", peer->gbox.id, cli->reader->device, tsbuf, gsms);
    171178        rdr->gbox_gsms_peer = peer->gbox.id;
    172179        snprintf(rdr->last_gsms, sizeof(rdr->last_gsms), "%s %s", gsms, tsbuf); // for easy handling of gsms by webif
     
    174181    else if(type == 0x31)
    175182    {
    176         fprintf(fhandle, "OSD message received from %04X %s on %s%s\n\n",
    177             peer->gbox.id, cli->reader->device, tsbuf, gsms);
     183        fprintf(fhandle, "OSD message received from %04X %s on %s%s\n\n", peer->gbox.id, cli->reader->device, tsbuf, gsms);
    178184        write_gsms_to_osd_file(cli, gsms);
    179185        rdr->gbox_gsms_peer = peer->gbox.id;
     
    182188    else
    183189    {
    184         fprintf(fhandle, "Corrupted message received from %04X %s on %s%s\n\n",
    185             peer->gbox.id, cli->reader->device, tsbuf, gsms);
     190        fprintf(fhandle, "Corrupted message received from %04X %s on %s%s\n\n", peer->gbox.id, cli->reader->device, tsbuf, gsms);
    186191    }
    187192
     
    204209
    205210    gbox_message_header(outbuf, MSG_GSMS, peer->gbox.password, local_gbox_pw);
     211
    206212    outbuf[10] = (peer->gbox.id >> 8) & 0xff;
    207213    outbuf[11] = peer->gbox.id & 0xff;
     
    210216    outbuf[14] = msg_type;
    211217    outbuf[15] = gsms_len;
    212     memcpy(&outbuf[16], gsms,gsms_len);
     218    memcpy(outbuf + 16, gsms, gsms_len);
    213219    outbuf[16 + gsms_len] = 0;
     220
    214221    cs_log("<-[gbx] send GSMS to %s:%d id: %04X", rdr->device, rdr->r_port, peer->gbox.id);
    215222    gbox_send(cl, outbuf, gsms_len + 17);
     
    240247        cs_log("GBOX message is too long so it will be truncated to max. [%d]", GBOX_MAX_MSG_TXT);
    241248    }
     249
    242250    cs_strncpy(text, gsms, sizeof(text));
    243251
     
    271279    cs_readlock(__func__, &clientlist_lock);
    272280
    273     for (cl = first_client; cl; cl = cl->next)
     281    for(cl = first_client; cl; cl = cl->next)
    274282    {
    275283        peer_found=0;
     
    277285        {
    278286            struct gbox_peer *peer = cl->gbox;
    279             if (peer->online && boxid == 0xFFFF) // send gsms to all peers online
     287            if(peer->online && boxid == 0xFFFF) // send gsms to all peers online
    280288            {
    281289                gbox_send_gsms2peer(cl, text, msg_type, gsms_len);
     
    283291            }
    284292
    285             if (!peer->online && boxid == 0xFFFF)
     293            if(!peer->online && boxid == 0xFFFF)
    286294            {
    287295                cs_log("GBOX Info: peer %04X is OFFLINE", peer->gbox.id);
     
    289297            }
    290298
    291             if (peer->online && boxid == peer->gbox.id)
     299            if(peer->online && boxid == peer->gbox.id)
    292300            {
    293301                gbox_send_gsms2peer(cl, text, msg_type, gsms_len);
     
    295303            }
    296304
    297             if (!peer->online && boxid == peer->gbox.id)
     305            if(!peer->online && boxid == peer->gbox.id)
    298306            {
    299307                cs_log("GBOX WARNING: send GSMS failed - peer %04X is OFFLINE", peer->gbox.id);
     
    302310        }
    303311    }
     312
    304313    cs_readunlock(__func__, &clientlist_lock);
    305314    return peer_found;
     
    313322    for(i = 0; i < GBOX_MAX_DEST_PEERS; i++)
    314323    {
    315         cfg.gbox_dest_peers[i]='\0';
    316     }
     324        cfg.gbox_dest_peers[i] = '\0';
     325    }
     326
    317327    cfg.gbox_dest_peers_num = 0;
    318328    cs_readlock(__func__, &clientlist_lock);
     
    320330    for(cl = first_client; cl; cl = cl->next)
    321331    {
    322         if((cl->gbox && cl->typ == 'p') && (n < GBOX_MAX_DEST_PEERS))
     332        if(cl->gbox && cl->typ == 'p' && n < GBOX_MAX_DEST_PEERS)
    323333        {
    324334            struct gbox_peer *peer = cl->gbox;
    325             if (peer->online) // peer is online
    326             {
    327                 cfg.gbox_dest_peers[n++] = (peer->gbox.id);
     335            if(peer->online) // peer is online
     336            {
     337                cfg.gbox_dest_peers[n++] = peer->gbox.id;
    328338            }
    329339        }
     
    357367    {
    358368        if(poll_result != -2)
    359             { cs_log("ERROR polling file %s", fname); }
    360     return;
     369        {
     370            cs_log("ERROR polling file %s", fname);
     371        }
     372
     373        return;
    361374    }
    362375
    363376    int8_t gsms_len = strlen(text);
    364     cs_log_dbg(D_READER,"got from %s: box_ID = %04X num = %d gsms_length = %d txt = %s",
    365         fname, boxid, num, gsms_len, text);
     377    cs_log_dbg(D_READER,"got from %s: box_ID = %04X num = %d gsms_length = %d txt = %s", fname, boxid, num, gsms_len, text);
    366378
    367379    switch(num)
     
    390402    }
    391403
    392     cs_log_dbg(D_READER,"init gsms to boxid= %04X length= %d msg_type= %02X ",
    393         boxid, gsms_len, msg_type);
     404    cs_log_dbg(D_READER,"init gsms to boxid= %04X length= %d msg_type= %02X ", boxid, gsms_len, msg_type);
    394405
    395406    uint8_t id_valid = 0;
     
    430441        }
    431442    }
     443
    432444    cs_readunlock(__func__, &clientlist_lock);
    433445
     
    436448        cs_log("WARNING: send GSMS failed - peer_id unknown");
    437449    }
     450
    438451    return;
    439452}
     
    447460    struct s_reader *rdr = cli->reader;
    448461
    449     if (peer->online)
     462    if(peer->online)
    450463    {
    451464        gbox_message_header(outbuf, MSG_GSMS_ACK, peer->gbox.password, local_gbox_pw);
     465
    452466        outbuf[10] = 0;
    453467        outbuf[11] = 0;
     
    456470        outbuf[14] = 0x1;
    457471        outbuf[15] = 0;
    458         cs_log_dbg(D_READER,"<-[gbx] send GSMS_ACK to %s:%d id: %04X",
    459             rdr->device, rdr->r_port, peer->gbox.id);
     472
     473        cs_log_dbg(D_READER,"<-[gbx] send GSMS_ACK to %s:%d id: %04X", rdr->device, rdr->r_port, peer->gbox.id);
    460474        gbox_send(cli, outbuf, 16);
    461475    }
     
    486500    while(sms_sender_active)
    487501    {
    488         if (file_exists(fname))
     502        if(file_exists(fname))
    489503        {
    490504            gbox_init_send_gsms();
     
    493507        sleepms_on_cond(__func__, &sleep_cond_mutex, &sleep_cond, 1000);
    494508    }
     509
    495510    pthread_exit(NULL);
    496511}
  • trunk/module-gbox-sms.h

    r11473 r11546  
    1111
    1212void gbox_init_send_gsms(void);
    13 void write_gsms_msg (struct s_client *cli, uint8_t *gsms, uint16_t type, uint16_t UNUSED(msglen));
     13void write_gsms_msg(struct s_client *cli, uint8_t *gsms, uint16_t type, uint16_t UNUSED(msglen));
    1414void gbox_send_gsms_ack(struct s_client *cli);
    1515int  gbox_direct_send_gsms(uint16_t boxid, uint8_t num, char *gsms);
    1616void gbox_get_online_peers(void);
    17 void write_gsms_ack (struct s_client *cli);
     17void write_gsms_ack(struct s_client *cli);
    1818void gsms_unavail(void);
    1919void start_sms_sender(void);
Note: See TracChangeset for help on using the changeset viewer.