/[projects]/smsdaemon/SmsPdu.cpp
ViewVC logotype

Diff of /smsdaemon/SmsPdu.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 157 by torben, Mon Dec 8 21:28:40 2008 UTC revision 177 by torben, Fri Dec 12 10:58:11 2008 UTC
# Line 11  Line 11 
11  #include <stdlib.h>  #include <stdlib.h>
12    
13  #include "Logger.h"  #include "Logger.h"
14  #include "util.h"  #include "Util.h"
15    
16    
17  using namespace std;  using namespace std;
# Line 274  namespace SmsPdu Line 274  namespace SmsPdu
274          }          }
275    
276    
277    
278          SMS ParseSmsPdu(std::string pdu_str)          SMS ParseSmsPdu(std::string pdu_str)
279          {          {
280                    SmsPart part = ParseSmsPduWorker(pdu_str);
281    
282    
283                    SMS sms;
284                    sms.SetMessage(part.message);
285                    sms.SetSender(part.sender);
286                    return sms;
287            }
288    
289            void ParseUdh(vector<unsigned char>& udh, SmsPart& part)
290            {
291                    if (udh.size() == 0)
292                    {
293                            Logger::logMessage("ParseUdh(): empty udh");
294                            return;
295                    }
296            
297                    if (udh[0] != 0)
298                    {
299                            Logger::logMessage("unknown UDH type");
300                            return;
301                    }
302    
303                    if (udh.size() < 5)
304                    {
305                            Logger::logMessage("UDH to short to be multipart");
306                            return;
307                    }
308                    
309                    part.group = udh[2];
310                    part.count = udh[3];
311                    part.id = udh[4];
312            }
313    
314    
315            SmsPart ParseSmsPduWorker(std::string pdu_str)
316            {
317    
318                  vector<unsigned char> pdu = HexDecodeString(pdu_str);                  vector<unsigned char> pdu = HexDecodeString(pdu_str);
319    
# Line 305  namespace SmsPdu Line 343  namespace SmsPdu
343    
344                  unsigned char data_len = (*it++);                  unsigned char data_len = (*it++);
345    
346    
347                    SmsPart part;
348                    part.group = -1;
349    
350                  int shift_start = 0;                  int shift_start = 0;
351    
352                  if (UDHI)                  if (UDHI)
353                  {                  {
354                          int udh_len = (*it++);                          int udh_len = (*it++);
355                          it += udh_len; //just ignore the User Data Header  
356                            vector<unsigned char> udh;
357                            for (int i=0; i<udh_len; i++)
358                            {
359                                    udh.push_back (*it++);
360                            }
361                            ParseUdh(udh,part);
362    
363                          data_len -= udh_len;                          data_len -= udh_len;
364    
365                          shift_start = udh_len+1; //make the 8to7bit decode start with the right shift level                          shift_start = udh_len+1; //make the 8to7bit decode start with the right shift level
# Line 322  namespace SmsPdu Line 372  namespace SmsPdu
372                  string message = Decode8to7bit(user_data, shift_start).substr(0,data_len);                  string message = Decode8to7bit(user_data, shift_start).substr(0,data_len);
373    
374                  message = Util::str_trim(message);                  message = Util::str_trim(message);
375    
376                                    
377                  SMS result;                  part.message = message;
378                  result.SetMessage(message);                  part.sender = sender;
                 result.SetSender(sender);  
379    
380                  return result;                  return part;
381          }          }
382    
383  }  }

Legend:
Removed from v.157  
changed lines
  Added in v.177

  ViewVC Help
Powered by ViewVC 1.1.20