This file is indexed.

/usr/lib/ruby/ignition/cmdtransport4.rb is in libignition-transport4-dev 4.0.0+dfsg-4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#!/usr/bin/ruby

# Copyright (C) 2014 Open Source Robotics Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# We use 'dl' for Ruby <= 1.9.x and 'fiddle' for Ruby >= 2.0.x
if RUBY_VERSION.split('.')[0] < '2'
  require 'dl'
  require 'dl/import'
  include DL
else
  require 'fiddle'
  require 'fiddle/import'
  include Fiddle
end

require 'optparse'

# Constants.
LIBRARY_NAME = '../../../lib/x86_64-linux-gnu/libignition-transport4.so'
LIBRARY_VERSION = '4.0.0'
COMMON_OPTIONS =
               "  -h [ --help ]              Print this help message.\n"\
               "                                                    \n"        +
               "  --force-version <VERSION>  Use a specific library version.\n"\
               "                                                    \n"        +
               '  --versions                 Show the available versions.'
COMMANDS = {  'topic' =>
                       "Print information about topics.\n\n"                   +
                       "  ign topic [options]\n\n"                             +
                       "Options:\n\n"                                          +
                       "  -i [ --info ]              Get info about a topic.\n"+
                       "                             Requires the -t option.\n"+
                       "                                                    \n"+
                       "  -l [ --list ]              List all topics.\n"       +
                       "                                                    \n"+
                       "  -t [ --topic ] arg         Name of a topic.\n"       +
                       "                             Required with -i, -p.\n"  +
                       "                                                    \n"+
                       "  -m [ --msgtype ] arg       Type of message to "      +
                       "publish.\n"                                            +
                       "                             Arg is a message type.\n" +
                       "                             Required with -p.\n"      +
                       "                                                    \n"+
                       "  -p [ --pub ] arg           Publish a message.\n"     +
                       "                             arg is the message data." +
                       " The format expected is\n                            " +
                       " the same used by Protobuf DebugString(). E.g.:\n\n"   +
                       "                               ign topic -t /foo -m "  +
                       "  ignition.msgs.StringMsg\n                          " +
                       "     -p \'data:\"Custom data\"\'\n\n"                  +
                       "                             Requires -t and -m.\n"    +
                       "                                                    \n"+
                       "  -e [ --echo ]              Output data to screen."   +
                       " E.g.:\n\n"                                            +
                       "                               ign topic -e -t /foo\n" +
                       "                                                    \n"+
                       "                             Requires -t.\n"           +
                       "                                                    \n"+
                       "  -d [--duration] arg        Duration (seconds) to run"+
                       ". Applicable with echo.\n"                             +
                       "                                                    \n"+
                       COMMON_OPTIONS,
              'service' =>
                       "Print information about services.\n\n"                 +
                       "  ign service [options]\n\n"                           +
                       "Options:\n\n"                                          +
                       "  -i [ --info ]              Get info about a service."+
                       "\n"                                                    +
                       "                             Requires the -s option.\n"+
                       "                                                    \n"+
                       "  -l [ --list ]              List all services.\n"     +
                       "                                                    \n"+
                       "  -s [ --service ] arg       Name of a service.\n"     +
                       "                             Arg is a service name.\n" +
                       "                             Required with -i, -r.\n"  +
                       "                                                    \n"+
                       "  -r [ --req ] arg           Request a service.\n"     +
                       "                             Arg is the input data."   +
                       " The format expected is\n                            " +
                       " the same used by Protobuf DebugString(). E.g.:\n\n"   +
                       "                               ign service -s /echo\n" +
                       "                               --reqtype ignition.msgs"+
                       ".StringMsg\n"                                          +
                       "                               --reptype ignition.msgs"+
                       ".StringMsg\n"                                          +
                       "                               --timeout 2000 --req \'"+
                       "data: \"Hello\"\n\n"                                   +
                       "                             Requires -s, --timeout,\n"+
                       "                             --reqtype, --reptype.\n"  +
                       "                                                    \n"+
                       "  --timeout arg              Timeout in milliseconds." +
                       "\n                             Arg is a timeout in "   +
                       "milliseconds.\n"                                       +
                       "                             Required with -r.\n"      +
                       "                                                    \n"+
                       "  --reqtype arg              Type of a request.\n"     +
                       "                             Arg is the request type." +
                       "                                                  \n\n"+
                       "  --reptype arg              Type of a response.\n"    +
                       "                             Arg is the response type."+
                       "                                                  \n\n"+
                       COMMON_OPTIONS
            }

#
# Class for the Ignition transport command line tools.
#
class Cmd
  #
  # Return a structure describing the options.
  #
  def parse(args)
    options = {}

    usage = COMMANDS[args[0]]

    # Read the command line arguments.
    opt_parser = OptionParser.new do |opts|
      opts.banner = usage

      opts.on('-h', '--help', 'Print this help message') do
        puts usage
        exit(0)
      end
      opts.on('-l', '--list', 'Print information about topics') do |l|
        options['list'] = l
      end

      opts.on('-t topic', '--topic', String,
              'Topic name') do |t|
        options['topic'] = t
      end

      opts.on('-s service', '--service', String,
              'Service name') do |t|
        options['service'] = t
      end

      opts.on('-m type', '--msgtype', String,
              'Message type') do |t|
        options['msgtype'] = t
      end

      opts.on('-p data', '--pub', String,
              'Publish a message') do |t|
        options['pub'] = t
      end

      opts.on('-i', '--info', String,
              'Print information about a topic') do |t|
        options['info'] = t
      end

      opts.on('-r data', '--req', String,
              'Request a data') do |t|
        options['req'] = t
      end

      opts.on('--timeout data', Integer,
              'Timeout') do |t|
        options['timeout'] = t
      end

      opts.on('--reqtype type', String,
              'Request type') do |t|
        options['reqtype'] = t
      end

      opts.on('--reptype type', String,
              'Response type') do |t|
        options['reptype'] = t
      end

      opts.on('-e', '--echo', String,
              'Output topic data to screen') do |e|
        options['echo'] = e
      end

      opts.on('-d secs', '--duration', Float,
              'Duration (seconds) to run') do |d|
        options['duration'] = d
      end

    end
    begin
      opt_parser.parse!(args)
    rescue
      puts usage
      exit(-1)
    end

    # Check that there is at least one command and there is a plugin that knows
    # how to handle it.
    if ARGV.empty? || !COMMANDS.key?(ARGV[0]) ||
       options.empty?
      puts usage
      exit(-1)
    end

    options['command'] = ARGV[0]

    options
  end  # parse()

  def execute(args)
    options = parse(args)

    # puts 'Parsed:'
    # puts options

    # Read the plugin that handles the command.
    # We're assuming that the library path is relative to the current
    # location of this script.
    plugin = File.expand_path(File.join(File.dirname(__FILE__), LIBRARY_NAME))
    conf_version = LIBRARY_VERSION

    begin
      Importer.dlload plugin
    rescue DLError
      puts "Library error: [#{plugin}] not found."
      exit(-1)
    end

    # Read the library version.
    Importer.extern 'char* ignitionVersion()'
    begin
      plugin_version = Importer.ignitionVersion.to_s
    rescue DLError
      puts "Library error: Problem running 'ignitionVersion()' from #{plugin}."
      exit(-1)
    end

    # Sanity check: Verify that the version of the yaml file matches the version
    # of the library that we are using.
    unless plugin_version.eql? conf_version
      puts "Error: Version mismatch. Your configuration file version is
            [#{conf_version}] but #{plugin} version is [#{plugin_version}]."
      exit(-1)
    end

    begin
      case options['command']
      when 'topic'
        if options.key?('list')
          Importer.extern 'void cmdTopicList()'
          Importer.cmdTopicList
        elsif options.key?('info')
          if not options.key?('topic')
            puts 'ign topic --info: missing topic name (-t <topic>)'
            puts 'Try ign topic --help'
          else
            Importer.extern 'void cmdTopicInfo(const char *)'
            Importer.cmdTopicInfo(options['topic'])
          end
        elsif options.key?('pub')
          if not options.key?('topic')
            puts 'ign topic --pub: missing topic name (-t <topic>)'
            puts 'Try ign topic --help'
          elsif not options.key?('msgtype')
            puts 'ign topic --pub: missing message type (--msgtype <type>)'
            puts 'Try ign topic --help'
          else
            Importer.extern 'void cmdTopicPub(const char *, const char *, const char *)'
            Importer.cmdTopicPub(options['topic'], options['msgtype'],
                                 options['pub'])
          end
        elsif options.key?('echo')
          if not options.key?('topic')
            puts 'ign topic --echo: missing topic name (-t <topic>)'
            puts 'Try ign topic --help'
          else
            duration = -1.0
            if options.key?('duration')
              duration = options['duration']
            end
            Importer.extern 'void cmdTopicEcho(const char*, double)'
            topic = options['topic']
            Importer.cmdTopicEcho(topic, duration.to_f)
          end
        else
          puts 'Command error: I do not have an implementation '\
               'for this command.'
        end
      when 'service'
        if options.key?('list')
          Importer.extern 'void cmdServiceList()'
          Importer.cmdServiceList
        elsif options.key?('info')
          if not options.key?('service')
            puts 'ign service --info: missing service name (-s <service>)'
            puts 'Try ign service --help'
          else
            Importer.extern 'void cmdServiceInfo(const char *)'
            Importer.cmdServiceInfo(options['service'])
          end
        elsif options.key?('req')
          if not options.key?('service')
            puts 'ign service --req: missing service name (-s <service>)'
            puts 'Try ign service --help'
          elsif not options.key?('reqtype')
            puts 'ign service --req: missing input type (--reqtype <type>)'
            puts 'Try ign service --help'
          elsif not options.key?('reptype')
            puts 'ign service --req: missing response type (--reptype <type>)'
            puts 'Try ign service --help'
          elsif not options.key?('timeout')
            puts 'ign service --req: missing timeout in ms (--timeout '\
                 '<timeout>)'
            puts 'Try ign service --help'
          else
            Importer.extern 'void cmdServiceReq(const char *, const char *,'\
                            'const char *, int, const char *)'
            Importer.cmdServiceReq(options['service'], options['reqtype'],
              options['reptype'], options['timeout'], options['req'])
          end
        else
          puts 'Command error: I do not have an implementation '\
               'for this command.'
        end
      else
        puts 'Command error: I do not have an implementation for '\
             "command [ign #{options['command']}]."
      end
    rescue
      puts "Library error: Problem running [#{options['command']}]() "\
           "from #{plugin}."
    end
  end
end