vfs: check userland buffers before reading them.
[haiku.git] / src / servers / print / Transport.Scripting.cpp
blob04f1f447eb57c15a159090e2d76039fb5bda4795
1 /*
2 * Copyright 2008, Haiku. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Ithamar R. Adema
7 */
10 #include "Transport.h"
12 #include <AppDefs.h>
13 #include <Catalog.h>
14 #include <Locale.h>
15 #include <Message.h>
16 #include <Messenger.h>
17 #include <PropertyInfo.h>
20 #undef B_TRANSLATION_CONTEXT
21 #define B_TRANSLATION_CONTEXT "Transport Scripting"
24 static property_info prop_list[] = {
25 { "Name", { B_GET_PROPERTY }, { B_DIRECT_SPECIFIER },
26 B_TRANSLATE_MARK("Get name of transport") },
27 { "Ports", { B_GET_PROPERTY }, { B_DIRECT_SPECIFIER },
28 B_TRANSLATE_MARK("Get currently available ports/devices") },
30 { 0 } // terminate list
34 void
35 Transport::HandleScriptingCommand(BMessage* msg)
37 status_t rc = B_ERROR;
38 BString propName;
39 BString result;
40 BMessage spec;
41 int32 idx;
43 if ((rc=msg->GetCurrentSpecifier(&idx,&spec)) == B_OK
44 && (rc=spec.FindString("property",&propName)) == B_OK) {
45 switch(msg->what) {
46 case B_GET_PROPERTY:
47 if (propName == "Name")
48 result = Name();
49 else if (propName == "Ports") {
50 // Need to duplicate messaging code, as our result is a
51 // complex bmessage, not a string :(
52 BMessage reply(B_REPLY);
53 rc = ListAvailablePorts(&reply);
54 reply.AddInt32("error", rc);
55 msg->SendReply(&reply);
56 break;
57 } else {
58 // If unknown scripting request, let superclas handle it
59 Inherited::MessageReceived(msg);
60 break;
63 BMessage reply(B_REPLY);
64 reply.AddString("result", result);
65 reply.AddInt32("error", rc);
66 msg->SendReply(&reply);
67 break;
69 } else {
70 // If GetSpecifier failed
71 if (idx == -1) {
72 BMessage reply(B_REPLY);
73 reply.AddMessenger("result", BMessenger(this));
74 reply.AddInt32("error", B_OK);
75 msg->SendReply(&reply);
81 BHandler*
82 Transport::ResolveSpecifier(BMessage* msg, int32 index, BMessage* spec,
83 int32 form, const char* prop)
85 BPropertyInfo prop_info(prop_list);
86 BHandler* rc = this;
88 int32 idx;
89 switch (idx=prop_info.FindMatch(msg,0,spec,form,prop)) {
90 case B_ERROR:
91 rc = Inherited::ResolveSpecifier(msg,index,spec,form,prop);
92 break;
95 return rc;
99 status_t
100 Transport::GetSupportedSuites(BMessage* msg)
102 msg->AddString("suites", "application/x-vnd.OpenBeOS-transport");
104 static bool localized = false;
105 if (!localized) {
106 localized = true;
107 for (int i = 0; prop_list[i].name != NULL; i ++)
108 prop_list[i].usage = B_TRANSLATE_NOCOLLECT(prop_list[i].usage);
111 BPropertyInfo prop_info(prop_list);
112 msg->AddFlat("messages", &prop_info);
114 return Inherited::GetSupportedSuites(msg);