+ sms.UDHPresent = !DBL_safestrcasecmp(DBL_true, PQgetvalue (res1, i, DBLF_udhpresent));
+
+ if (!DBL_safestrcasecmp(DBL_true, PQgetvalue (res1, i, DBLF_hexencode))) {
+char *d_end = (char *)SMS_BlockFromHex(smsbuf/*d*/, smsbuf/*s*/, smsbuflen);
+
+ if (!d_end)
+ continue;
+ smsbuflen = d_end - smsbuf;
+ }
+
+ sendlogo=false;
+ if (!DBL_safestrcasecmp("ringtone" ,type)) {
+ SMS_SetupUDH(&sms, GSM_RingtoneUDH);
+ if (fromfile) {
+GSM_Ringtone ringtone;
+static char ringbuf[GSM_MAX_RINGTONE_PACKAGE_LENGTH];
+int ringbuflen=GSM_MAX_RINGTONE_PACKAGE_LENGTH;
+
+ if (GSM_ReadRingtoneFile(smsbuf, &ringtone))
+ continue; /* error */
+ GSM_PackRingtone(&ringtone, ringbuf, &ringbuflen);
+ smsbuf=ringbuf;
+ smsbuflen=ringbuflen;
+ }
+ }
+ else if (!DBL_safestrcasecmp("oplogo" ,type)) {
+ SMS_SetupUDH(&sms, GSM_OpLogo);
+ sendlogo=true;
+ }
+ else if (!DBL_safestrcasecmp("calleridlogo",type)) {
+ SMS_SetupUDH(&sms, GSM_CallerIDLogo);
+ sendlogo=true;
+ }
+ else { /* "text" */
+ if (fromfile) {
+static char textbuf[GSM_MAX_CONCATENATED_SMS_LENGTH];
+int textbuflen;
+int fd;
+
+ if (-1==(fd=open(smsbuf,O_RDONLY)))
+ continue; /* error */
+ if (-1==(textbuflen=read(fd,textbuf,sizeof(textbuf))))
+ continue; /* error */
+ close(fd);
+ smsbuf=textbuf;
+ smsbuflen=textbuflen;
+ }
+ if (sms.UDHPresent) {
+u8 len=1+(*(u8 *)smsbuf);
+
+ if (len>smsbuflen || len>sizeof(sms.UDH))
+ g_print ("%d: UDH too long: UDHlen=%d, smsbuflen=%d, sizeof(sms.UDH)=%d !!!\n", __LINE__,
+ len, smsbuflen,sizeof(sms.UDH));
+ else {
+ memcpy(sms.UDH,smsbuf,len);
+ memmove(smsbuf,smsbuf+len,smsbuflen-len);
+ smsbuflen-=len;
+ }
+ }
+ }
+
+ if (sendlogo) {
+GSM_Bitmap bitmap;
+static u8 bin[sizeof(bitmap.bitmap) +64/*headers safety*/];
+u8 *d;
+char *usernetcode=PQgetvalue (res1, i, DBLF_netcode);
+
+ if (GE_NONE!=GSM_ReadBitmapFile(smsbuf, &bitmap))
+ continue; /* error */
+
+ d=bin;
+ if (!DBL_safestrcasecmp("oplogo" ,type)) {
+ if (usernetcode) {
+ if (strlen(usernetcode)+1 > sizeof(bitmap.netcode))
+ continue; /* error */
+ strcpy(bitmap.netcode, usernetcode);
+ }
+ *d++ = ((bitmap.netcode[1] & 0x0f) << 4) | (bitmap.netcode[0] & 0xf);
+ *d++ = 0xf0 | (bitmap.netcode[2] & 0x0f);
+ *d++ = ((bitmap.netcode[5] & 0x0f) << 4) | (bitmap.netcode[4] & 0xf);
+ }
+ /* Set the logo size */
+ *d++ = 0x00; /* RFU by Nokia */
+ *d++ = bitmap.width;
+ *d++ = bitmap.height;
+ *d++ = 0x01; /* depth=number of grayscales */
+
+ memcpy(d,bitmap.bitmap,bitmap.size);
+ d+=bitmap.size;
+
+ smsbuf=bin;
+ smsbuflen=d-bin;
+ }
+
+ strncpy (sms.Destination, PQgetvalue (res1, i, DBLF_number), GSM_MAX_DESTINATION_LENGTH + 1);