/[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 178 by torben, Fri Dec 12 12:13:05 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    #include "Exceptions.h"
17    #include <list>
18    #include <vector>
19    #include <algorithm>
20    
21    
22  using namespace std;  using namespace std;
# Line 274  namespace SmsPdu Line 279  namespace SmsPdu
279          }          }
280    
281    
282            std::list<SmsPart> partlist;
283            typedef std::list<SmsPart>::iterator iterator;
284            
285            SMS ConcatenateParts(SmsPart& part)
286            {
287                    SMS sms;
288                    if (part.group == -1)
289                    {
290                            sms.SetMessage(part.message);
291                            sms.SetSender(part.sender);
292                    }
293                    else
294                    {
295                            partlist.push_back(part);
296                            
297                            vector<SmsPart> vec;
298                            for (iterator it=partlist.begin(); it!=partlist.end(); ++it)
299                            {
300                                    SmsPart& current = *it;
301                                    if (current.sender == part.sender && current.group == part.group)
302                                            vec.push_back(current);
303                            }
304    
305                            if (vec.size() == (unsigned)part.count) //we have all parts
306                            {
307                                    sort(vec.begin(), vec.end());
308                                    string message;
309                                    for (unsigned i=0; i<vec.size(); i++)
310                                    {
311                                            partlist.remove( (vec[i]) );
312                                            message += vec[i].message;
313                                    }
314                                    sms.SetSender(part.sender);
315                                    sms.SetMessage(message);
316                            }
317                            else
318                            {
319                                    throw smsnotfoundexception(); // need more parts
320                            }
321    
322                    }
323    
324                    return sms;
325            }
326    
327    
328          SMS ParseSmsPdu(std::string pdu_str)          SMS ParseSmsPdu(std::string pdu_str)
329          {          {
330                    SmsPart part = ParseSmsPduWorker(pdu_str);
331    
332                    return ConcatenateParts(part);
333    
334            }
335    
336            void ParseUdh(vector<unsigned char>& udh, SmsPart& part)
337            {
338                    if (udh.size() == 0)
339                    {
340                            Logger::logMessage("ParseUdh(): empty udh");
341                            return;
342                    }
343            
344                    if (udh[0] != 0)
345                    {
346                            Logger::logMessage("unknown UDH type");
347                            return;
348                    }
349    
350                    if (udh.size() < 5)
351                    {
352                            Logger::logMessage("UDH to short to be multipart");
353                            return;
354                    }
355                    
356                    part.group = udh[2];
357                    part.count = udh[3];
358                    part.id = udh[4];
359            }
360    
361    
362            SmsPart ParseSmsPduWorker(std::string pdu_str)
363            {
364    
365                  vector<unsigned char> pdu = HexDecodeString(pdu_str);                  vector<unsigned char> pdu = HexDecodeString(pdu_str);
366    
# Line 305  namespace SmsPdu Line 390  namespace SmsPdu
390    
391                  unsigned char data_len = (*it++);                  unsigned char data_len = (*it++);
392    
393    
394                    SmsPart part;
395                    part.group = -1;
396    
397                  int shift_start = 0;                  int shift_start = 0;
398    
399                  if (UDHI)                  if (UDHI)
400                  {                  {
401                          int udh_len = (*it++);                          int udh_len = (*it++);
402                          it += udh_len; //just ignore the User Data Header  
403                            vector<unsigned char> udh;
404                            for (int i=0; i<udh_len; i++)
405                            {
406                                    udh.push_back (*it++);
407                            }
408                            ParseUdh(udh,part);
409    
410                          data_len -= udh_len;                          data_len -= udh_len;
411    
412                          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 419  namespace SmsPdu
419                  string message = Decode8to7bit(user_data, shift_start).substr(0,data_len);                  string message = Decode8to7bit(user_data, shift_start).substr(0,data_len);
420    
421                  message = Util::str_trim(message);                  message = Util::str_trim(message);
422    
423                                    
424                  SMS result;                  part.message = message;
425                  result.SetMessage(message);                  part.sender = sender;
                 result.SetSender(sender);  
426    
427                  return result;                  return part;
428          }          }
429    
430  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.20