~ubuntu-branches/ubuntu/saucy/gnash/saucy-proposed

« back to all changes in this revision

Viewing changes to cygnal/libnet/rtmp.cpp

  • Committer: Package Import Robot
  • Author(s): Micah Gersten
  • Date: 2012-03-04 03:19:06 UTC
  • mfrom: (1.1.18) (3.1.24 sid)
  • Revision ID: package-import@ubuntu.com-20120304031906-p6q5rnb0xhgpof7o
Tags: 0.8.10-3ubuntu1
* Merge from Debian testing (FFe: LP: #940876), remaining changes:
  - Use mozilla-flashplugin as the alternative for now
  - Change xulrunner-dev build dep to firefox-dev
* Drop the plugin API porting patch, this has been fixed upstream
  - drop debian/patches*
* Drop the following change as we want Adobe's player to take priority
  if it's installed
  - Set alternative priority to 50 so that it matches Adobe Flash's priority

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// rtmp.cpp:  Adobe/Macromedia Real Time Message Protocol handler, for Gnash.
2
2
// 
3
 
//   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
4
 
//   2011 Free Software Foundation, Inc
 
3
//   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
 
4
//   Free Software Foundation, Inc
5
5
// 
6
6
// This program is free software; you can redistribute it and/or modify
7
7
// it under the terms of the GNU General Public License as published by
280
280
    // Make sure the header size is in range, it has to be between
281
281
    // 1-12 bytes.
282
282
    if (head->head_size > RTMP_MAX_HEADER_SIZE) {
283
 
        log_error("RTMP Header size can't be more then %d bytes!!",
 
283
        log_error(_("RTMP Header size can't be more then %d bytes!!"),
284
284
                  RTMP_MAX_HEADER_SIZE);
285
285
        head.reset();
286
286
        return head;
287
287
    } else if (head->head_size == 0) {
288
 
        log_error("RTMP Header size can't be zero!");
 
288
        log_error(_("RTMP Header size can't be zero!"));
289
289
        head.reset();
290
290
        return head;
291
291
    }
312
312
        // reuse the previous body size.
313
313
        head->bodysize = _bodysize[head->channel];
314
314
        if (head->bodysize) {
315
 
            log_network("Using previous body size of %d for channel %d",
 
315
            log_network(_("Using previous body size of %d for channel %d"),
316
316
                        head->bodysize, head->channel);
317
317
        } else {
318
 
            log_error("Previous body size for channel %d is zero!", head->channel);
 
318
            log_error(_("Previous body size for channel %d is zero!"),
 
319
                        head->channel);
319
320
            head.reset();
320
321
            return head;
321
322
        }
324
325
    // the bodysize is limited to two bytes, so if we think we have
325
326
    // more than that, something probably screwed up.
326
327
    if (head->bodysize > 65535) {
327
 
        log_error("Suspicious large RTMP packet body size! %d", head->bodysize);
 
328
        log_error(_("Suspicious large RTMP packet body size! %d"),
 
329
                  head->bodysize);
328
330
        head.reset();
329
331
        return head;
330
332
    }
343
345
#endif
344
346
    } else {
345
347
        if (_type[head->channel] <= RTMP::FLV_DATA) {
346
 
            log_network("Using previous type of %d for channel %d",
 
348
            log_network(_("Using previous type of %d for channel %d"),
347
349
                        head->type, head->channel);
348
350
            head->type = _type[head->channel];
349
351
        }
355
357
//         log_network(_("The source/destination is: %x"), head->src_dest);
356
358
    }
357
359
 
358
 
    log_network("RTMP %s: channel: %d, head size %d, body size: %d",
 
360
    log_network(_("RTMP %s: channel: %d, head size %d, body size: %d"),
359
361
              ((head->head_size == 1) ? "same" : content_str[head->type]),
360
362
              head->channel,
361
363
              head->head_size,
477
479
    
478
480
    amf_index = *ptr & RTMP_INDEX_MASK;
479
481
    headersize = headerSize(*buf.reference());
480
 
    log_network (_("The Header size is: %d"), headersize);
481
 
    log_network (_("The AMF index is: 0x%x"), amf_index);
 
482
    log_network(_("The Header size is: %d"), headersize);
 
483
    log_network(_("The AMF index is: 0x%x"), amf_index);
482
484
 
483
485
     if (headersize > 1) {
484
486
         RTMP::rtmp_head_t *rthead = decodeHeader(ptr);
494
496
    boost::uint8_t *end = buf.remove(0xc3);
495
497
#else
496
498
    boost::uint8_t *end = buf.find(0xc3);
497
 
    log_network("END is %x", (void *)end);
 
499
    log_network(_("END is %x"), (void *)end);
498
500
    *end = '*';
499
501
#endif
500
502
    
505
507
//    el->dump();
506
508
    el = amf.extractAMF(ptr, tooFar); // @@strk@@ : what's the +1 for ?
507
509
//    el->dump();
508
 
    log_network (_("Reading AMF packets till we're done..."));
 
510
    log_network(_("Reading AMF packets till we're done..."));
509
511
//    buf->dump();
510
512
    while (ptr < end) {
511
513
        boost::shared_ptr<cygnal::Element> el = amf.extractProperty(ptr, tooFar);
514
516
    }
515
517
    ptr += 1;
516
518
    size_t actual_size = static_cast<size_t>(_header.bodysize - AMF_HEADER_SIZE);
517
 
    log_network("Total size in header is %d, buffer size is: %d", _header.bodysize, buf.size());
 
519
    log_network(_("Total size in header is %d, buffer size is: %d"),
 
520
                _header.bodysize, buf.size());
518
521
//    buf->dump();
519
522
    if (buf.size() < actual_size) {
520
 
        log_network("FIXME: MERGING");
 
523
        log_network(_("FIXME: MERGING"));
521
524
//      buf = _handler->merge(buf); FIXME needs to use shared_ptr
522
525
    }
523
526
    while ((ptr - buf.begin()) < static_cast<int>(actual_size)) {
533
536
    boost::shared_ptr<cygnal::Element> app = getProperty("app");
534
537
    
535
538
    if (file) {
536
 
        log_network("SWF file %s", file->to_string());
 
539
        log_network(_("SWF file %s"), file->to_string());
537
540
    }
538
541
    if (url) {
539
 
        log_network("is Loading video %s", url->to_string());
 
542
        log_network(_("is Loading video %s"), url->to_string());
540
543
    }
541
544
    if (app) {
542
 
        log_network("is file name is %s", app->to_string());
 
545
        log_network(_("is file name is %s"), app->to_string());
543
546
    }
544
547
    
545
548
    return true;
668
671
      case STREAM_PONG:
669
672
          break;
670
673
      default:
671
 
          log_unimpl("Unknown User Control message %d!", 1);
 
674
          log_unimpl(_("Unknown User Control message %d!"), 1);
672
675
          break;
673
676
    };
674
677
 
740
743
    if (name) {
741
744
        ptr += name->getDataSize() + cygnal::AMF_HEADER_SIZE; // skip the length bytes too
742
745
    } else {
743
 
        log_error("Name field of RTMP Message corrupted!");
 
746
        log_error(_("Name field of RTMP Message corrupted!"));
744
747
        msg.reset();
745
748
        return msg;
746
749
    }
756
759
            ptr += cygnal::AMF0_NUMBER_SIZE + 1;
757
760
        }
758
761
    } else {
759
 
        log_error("Stream ID field of RTMP Message corrupted!");
 
762
        log_error(_("Stream ID field of RTMP Message corrupted!"));
760
763
        msg.reset();
761
764
        return msg;
762
765
    }
985
988
#if 0
986
989
    // We got some bogus parameters
987
990
    if (total_size || size 0) {
988
 
        log_error("Bogus size parameter in %s!", __PRETTY_FUNCTION__);
 
991
        log_error(_("Bogus size parameter in %s!"), __PRETTY_FUNCTION__);
989
992
        return false;
990
993
    }
991
994
#endif
1022
1025
#if 0
1023
1026
    ret = writeNet(fd, head->reference(), head->size());
1024
1027
    if (ret == -1) {
1025
 
        log_error("Couldn't write the full 12 byte RTMP header!");
 
1028
        log_error(_("Couldn't write the full 12 byte RTMP header!"));
1026
1029
        return false;
1027
1030
    } else {
1028
 
        log_network("Wrote the full 12 byte RTMP header.");
 
1031
        log_network(_("Wrote the full 12 byte RTMP header."));
1029
1032
    }
1030
1033
#else
1031
1034
    *bigbuf = head;
1045
1048
#if 0
1046
1049
            ret = writeNet(fd, *cont_head);
1047
1050
            if (ret == -1) {
1048
 
                log_error("Couldn't write the full 1 byte RTMP continuation header!");
 
1051
                log_error(_("Couldn't write the full 1 byte RTMP continuation header!"));
1049
1052
                return false;
1050
1053
            } else {
1051
 
                log_network("Wrote the full 1 byte RTMP continuation header");
 
1054
                log_network(_("Wrote the full 1 byte RTMP continuation header"));
1052
1055
            }
1053
1056
#else
1054
1057
            *bigbuf += cont_head;
1060
1063
#if 0
1061
1064
        ret = writeNet(fd, data + nbytes, partial);
1062
1065
        if (ret == -1) {
1063
 
            log_error("Couldn't write the RTMP body!");
 
1066
            log_error(_("Couldn't write the RTMP body!"));
1064
1067
            return false;
1065
1068
        } else {
1066
 
            log_network("Wrote %d bytes of the RTMP body, %d bytes left.",
 
1069
            log_network(_("Wrote %d bytes of the RTMP body, %d bytes left."),
1067
1070
                        ret, size-nbytes);
1068
1071
        }
1069
1072
#else
1080
1083
    
1081
1084
    ret = writeNet(fd, *bigbuf);
1082
1085
    if (ret == -1) {
1083
 
        log_error("Couldn't write the RTMP packet!");
 
1086
        log_error(_("Couldn't write the RTMP packet!"));
1084
1087
        return false;
1085
1088
    } else {
1086
 
        log_network("Wrote the RTMP packet.");
 
1089
        log_network(_("Wrote the RTMP packet."));
1087
1090
    }
1088
1091
#endif
1089
1092
 
1129
1132
        
1130
1133
        if (rthead) {
1131
1134
            if (rthead->head_size == 1) {
1132
 
                log_network("Response header: %s", hexify(ptr, 7, false));
 
1135
                log_network(_("Response header: %s"), hexify(ptr, 7, false));
1133
1136
            } else {
1134
 
                log_network("Response header: %s", hexify(ptr, rthead->head_size, false));
 
1137
                log_network(_("Response header: %s"),
 
1138
                            hexify(ptr, rthead->head_size, false));
1135
1139
            }
1136
1140
            if (rthead->type <= RTMP::FLV_DATA) {
1137
 
                log_error("Processing message of type %s!", content_str[rthead->type]);
 
1141
                log_error(_("Processing message of type %s!"),
 
1142
                          content_str[rthead->type]);
1138
1143
            }
1139
1144
            
1140
1145
            switch (rthead->type) {
1141
1146
              case CHUNK_SIZE:
1142
 
                  log_network("Got CHUNK_SIZE packet!!!");
 
1147
                  log_networ(_("Got CHUNK_SIZE packet!!!"));
1143
1148
                  _chunksize[rthead->channel] = ntohl(*reinterpret_cast<boost::uint32_t *>(ptr + rthead->head_size));
1144
 
                  log_network("Setting packet chunk size to %d.", _chunksize);
 
1149
                  log_network(_("Setting packet chunk size to %d."), _chunksize);
1145
1150
//                decodeChunkSize();
1146
1151
                  break;
1147
1152
              case BYTES_READ:
1151
1156
              case PING:
1152
1157
              {
1153
1158
                  RTMP::rtmp_ping_t *ping = decodePing(ptr);
1154
 
                  log_network("FIXME: Ping type is: %d, ignored for now", ping->type);
 
1159
                  log_network(_("FIXME: Ping type is: %d, ignored for now"),
 
1160
                      ping->type);
1155
1161
                  switch (ping->type) {
1156
1162
                    case PING_CLEAR:
1157
1163
                        break;
1172
1178
              }
1173
1179
              case SERVER:
1174
1180
              {
1175
 
                  log_network("Got SERVER packet!!!");
 
1181
                  log_network(_("Got SERVER packet!!!"));
1176
1182
                  Buffer server_data(rthead->bodysize);
1177
1183
                  server_data.copy(ptr + rthead->head_size, rthead->bodysize);
1178
1184
//                decodeServer();
1180
1186
              }
1181
1187
              case CLIENT:
1182
1188
              {
1183
 
                  log_network("Got CLIENT packet!!!");
 
1189
                  log_network(_("Got CLIENT packet!!!"));
1184
1190
                  Buffer client_data(rthead->bodysize);
1185
1191
                  client_data.copy(ptr + rthead->head_size, rthead->bodysize);
1186
1192
//                decodeClient();
1188
1194
              }
1189
1195
              case VIDEO_DATA:
1190
1196
              {
1191
 
                  log_network("Got VIDEO packets!!!");
 
1197
                  log_network(_("Got VIDEO packets!!!"));
1192
1198
                  boost::shared_ptr<cygnal::Buffer> frame;
1193
1199
                  do {
1194
1200
                      frame = recvMsg(1);       // use a 1 second timeout
1204
1210
//                decodeNotify();
1205
1211
                  break;
1206
1212
              case SHARED_OBJ:
1207
 
                  log_network("Got Shared Object packet!!!");
 
1213
                  log_network(_("Got Shared Object packet!!!"));
1208
1214
//                decodeSharedObj();
1209
1215
                  break;
1210
1216
              case INVOKE:
1211
1217
                  msg = decodeMsgBody(ptr + rthead->head_size, rthead->bodysize);
1212
1218
//                msg->dump();
1213
1219
                  if (msg) {
1214
 
                      log_network("%s: Msg status is: %d: %s, name is %s, size is %d", __FUNCTION__,
 
1220
                      log_network(_("%s: Msg status is: %d: %s, name is %s, size is %d"), __FUNCTION__,
1215
1221
                                msg->getStatus(), status_str[msg->getStatus()],
1216
1222
                                msg->getMethodName(), msg->size());
1217
1223
                      if (msg->getMethodName() == "onBWDone") { 
1218
 
                          log_network("Got onBWDone packet!!!");
 
1224
                          log_network(_("Got onBWDone packet!!!"));
1219
1225
                          continue;
1220
1226
                      }
1221
1227
                      return msg;
1222
1228
                  } else {
1223
 
                      log_error("Couldn't decode message body for type %s!",
 
1229
                      log_error(_("Couldn't decode message body for type %s!"),
1224
1230
                                content_str[rthead->type]);
1225
1231
                  }
1226
1232
//                decodeInvoke();
1274
1280
        }
1275
1281
        // the read timed out as there was no data, but the socket is still open.
1276
1282
        if (ret == 0) {
1277
 
            log_network("no data for fd #%d, done reading this packet, read %d bytes...", fd,
 
1283
            log_network(_("no data for fd #%d, done reading this packet, read %d bytes..."), fd,
1278
1284
                        buf->allocated());
1279
1285
            buf.reset();
1280
1286
            break;
1281
1287
        }
1282
1288
        if ((ret == 1) && (*(buf->reference()) == 0xff)) {
1283
 
            log_network("Got an empty packet from the server at line %d", __LINE__);
 
1289
            log_network(_("Got an empty packet from the server at line %d"),
 
1290
                        __LINE__);
1284
1291
            ret = 0;
1285
1292
            buf->clear();
1286
1293
            continue;
1288
1295
        // ret is "no position" when the socket is closed from the other end of the connection,
1289
1296
        // so we're done.
1290
1297
        if ((ret == static_cast<int>(std::string::npos)) || (ret == -1)) {
1291
 
            log_network("socket for fd #%d was closed...", fd);
 
1298
            log_network(_("socket for fd #%d was closed..."), fd);
1292
1299
            buf.reset();
1293
1300
            break;
1294
1301
        }
1319
1326
//    GNASH_REPORT_FUNCTION;
1320
1327
 
1321
1328
    if (data == 0) {
1322
 
        log_error("Buffer pointer is invalid.");
 
1329
        log_error(_("Buffer pointer is invalid."));
1323
1330
    }
1324
1331
 
1325
1332
    boost::shared_ptr<RTMP::queues_t> channels(new RTMP::queues_t);
1345
1352
        // System channel messages are always on channel 2, and get
1346
1353
        // processed differently later on.
1347
1354
        if (rthead->channel == RTMP_SYSTEM_CHANNEL) {
1348
 
            log_network("Got a message on the system channel!", __FUNCTION__);
 
1355
            log_network(_("Got a message on the system channel!"), __FUNCTION__);
1349
1356
        }
1350
1357
        // If the header size is 4 bytes or less, then reuse the body size
1351
1358
        // of the last message for this channel.
1449
1456
                    // FIXME: why is this off by 1 byte ?
1450
1457
                    ptr += pktsize - 1;
1451
1458
                } else {
1452
 
                    log_error("Packet size out of range! %d, %d", rthead->bodysize, pktsize);
 
1459
                    log_error(_("Packet size out of range! %d, %d"),
 
1460
                              rthead->bodysize, pktsize);
1453
1461
                }
1454
1462
                // add this packet to the list of active channels if we've gotten
1455
1463
                // all the data.
1459
1467
                channels->push_back(&_queues[rthead->channel]);
1460
1468
//              }
1461
1469
            } else {
1462
 
                log_error("RTMP packet size is out of range! %d, %d", rthead->bodysize, pktsize);
 
1470
                log_error(_("RTMP packet size is out of range! %d, %d"),
 
1471
                          rthead->bodysize, pktsize);
1463
1472
                break;
1464
1473
            }
1465
1474
        } else {
1466
 
            log_error("RTMP header size is out of range! %d", rthead->head_size);
 
1475
            log_error(_("RTMP header size is out of range! %d"),
 
1476
                      rthead->head_size);
1467
1477
            break;
1468
1478
        }
1469
1479
    }
1477
1487
 
1478
1488
// local Variables:
1479
1489
// mode: C++
1480
 
// indent-tabs-mode: t
 
1490
// indent-tabs-mode: nil
1481
1491
// End: