vfs: check userland buffers before reading them.
[haiku.git] / src / kits / translation / FuncTranslator.cpp
blob5f64bc6c14c304e4240979154930845e517382e1
1 /*
2 * Copyright 2002-2006, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Michael Wilber
7 * Axel Dörfler, axeld@pinc-software.de
8 */
10 /*!
11 This file contains the BTranslator based object for
12 function based translators, aka, the translators
13 that don't use the make_nth_translator() mechanism.
15 This class is used by the BTranslatorRoster class
16 so that function based translators, make_nth_translator()
17 translators and private BTranslator objects could be
18 accessed in the same way.
22 #include "FuncTranslator.h"
24 #include <string.h>
27 namespace BPrivate {
29 BFuncTranslator::BFuncTranslator(const translator_data& data)
31 fData = data;
35 BFuncTranslator::~BFuncTranslator()
40 const char *
41 BFuncTranslator::TranslatorName() const
43 return fData.name;
47 const char *
48 BFuncTranslator::TranslatorInfo() const
50 return fData.info;
54 int32
55 BFuncTranslator::TranslatorVersion() const
57 return fData.version;
61 const translation_format *
62 BFuncTranslator::InputFormats(int32* _count) const
64 if (_count == NULL || fData.input_formats == NULL)
65 return NULL;
67 int32 count = 0;
68 while (fData.input_formats[count].type) {
69 count++;
72 *_count = count;
73 return fData.input_formats;
77 const translation_format *
78 BFuncTranslator::OutputFormats(int32* _count) const
80 if (_count == NULL || fData.output_formats == NULL)
81 return NULL;
83 int32 count = 0;
84 while (fData.output_formats[count].type) {
85 count++;
88 *_count = count;
89 return fData.output_formats;
93 status_t
94 BFuncTranslator::Identify(BPositionIO* source, const translation_format* format,
95 BMessage* ioExtension, translator_info* info, uint32 type)
97 if (fData.identify_hook == NULL)
98 return B_ERROR;
100 return fData.identify_hook(source, format, ioExtension, info, type);
104 status_t
105 BFuncTranslator::Translate(BPositionIO* source, const translator_info *info,
106 BMessage* ioExtension, uint32 type, BPositionIO* destination)
108 if (fData.translate_hook == NULL)
109 return B_ERROR;
111 return fData.translate_hook(source, info, ioExtension, type, destination);
115 status_t
116 BFuncTranslator::MakeConfigurationView(BMessage* ioExtension,
117 BView** _view, BRect* _extent)
119 if (fData.make_config_hook == NULL)
120 return B_ERROR;
122 return fData.make_config_hook(ioExtension, _view, _extent);
126 status_t
127 BFuncTranslator::GetConfigurationMessage(BMessage* ioExtension)
129 if (fData.get_config_message_hook == NULL)
130 return B_ERROR;
132 return fData.get_config_message_hook(ioExtension);
135 } // namespace BPrivate