linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #06643
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 3209: Plugin API: conversion functions return the required buffer size
------------------------------------------------------------
revno: 3209
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Sun 2013-03-03 20:19:41 +0100
message:
Plugin API: conversion functions return the required buffer size
modified:
changelog.txt
dcpp/PluginApiImpl.cpp
dcpp/PluginDefs.h
--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk
Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'changelog.txt'
--- changelog.txt 2013-02-14 19:14:20 +0000
+++ changelog.txt 2013-03-03 19:19:41 +0000
@@ -3,6 +3,7 @@
* [ADC] Fix problems after marking oneself as a favorite user
* Display progress information when DC++ starts (poy)
* No GUI freeze when DC++ starts (poy)
+* Plugin API: conversion functions return the required buffer size
-- 0.810 2013-01-30 --
* Fix a race condition on file list download (thanks bigmuscle)
=== modified file 'dcpp/PluginApiImpl.cpp'
--- dcpp/PluginApiImpl.cpp 2013-01-29 18:08:36 +0000
+++ dcpp/PluginApiImpl.cpp 2013-03-03 19:19:41 +0000
@@ -459,38 +459,43 @@
// Functions for DCUtils
size_t PluginApiImpl::toUtf8(char* dst, const char* src, size_t n) {
- string sSrc(Text::toUtf8(src));
- n = (sSrc.size() < n) ? sSrc.size() : n;
- strncpy(dst, sSrc.c_str(), n);
- return n;
+ string str(Text::toUtf8(src));
+ if(n >= str.size()) {
+ strncpy(dst, str.c_str(), str.size());
+ }
+ return str.size();
}
size_t PluginApiImpl::fromUtf8(char* dst, const char* src, size_t n) {
- string sSrc(Text::fromUtf8(src));
- n = (sSrc.size() < n) ? sSrc.size() : n;
- strncpy(dst, sSrc.c_str(), n);
- return n;
+ string str(Text::fromUtf8(src));
+ if(n >= str.size()) {
+ strncpy(dst, str.c_str(), str.size());
+ }
+ return str.size();
}
size_t PluginApiImpl::Utf8toWide(wchar_t* dst, const char* src, size_t n) {
- wstring sSrc(Text::utf8ToWide(src));
- n = (sSrc.size() < n) ? sSrc.size() : n;
- wcsncpy(dst, sSrc.c_str(), n);
- return n;
+ wstring str(Text::utf8ToWide(src));
+ if(n >= str.size()) {
+ wcsncpy(dst, str.c_str(), str.size());
+ }
+ return str.size();
}
size_t PluginApiImpl::WidetoUtf8(char* dst, const wchar_t* src, size_t n) {
- string sSrc(Text::wideToUtf8(src));
- n = (sSrc.size() < n) ? sSrc.size() : n;
- strncpy(dst, sSrc.c_str(), n);
- return n;
+ string str(Text::wideToUtf8(src));
+ if(n >= str.size()) {
+ strncpy(dst, str.c_str(), str.size());
+ }
+ return str.size();
}
size_t PluginApiImpl::toBase32(char* dst, const uint8_t* src, size_t n) {
- string sSrc(Encoder::toBase32(src, n));
- n = (sSrc.size() < n) ? sSrc.size() : n;
- strncpy(dst, sSrc.c_str(), n);
- return n;
+ string str(Encoder::toBase32(src, n));
+ if(n >= str.size()) {
+ strncpy(dst, str.c_str(), str.size());
+ }
+ return str.size();
}
size_t PluginApiImpl::fromBase32(uint8_t* dst, const char* src, size_t n) {
=== modified file 'dcpp/PluginDefs.h'
--- dcpp/PluginDefs.h 2013-01-29 18:08:36 +0000
+++ dcpp/PluginDefs.h 2013-03-03 19:19:41 +0000
@@ -74,7 +74,7 @@
#define DCINTF_DCPP_QUEUE_VER 2
#define DCINTF_DCPP_UTILS "dcpp.utils.DCUtils" /* Utility and convenience functions */
-#define DCINTF_DCPP_UTILS_VER 1
+#define DCINTF_DCPP_UTILS_VER 2
#define DCINTF_DCPP_TAGGER "dcpp.xml.DCTagger" /* Manipulation of an XML tagger */
#define DCINTF_DCPP_TAGGER_VER 2
@@ -409,6 +409,8 @@
/* Utility API version */
uint32_t apiVersion;
+ /* These functions attempt a conversion; they return the required buffer size. */
+
size_t (DCAPI *to_utf8) (char* dst, const char* src, size_t n);
size_t (DCAPI *from_utf8) (char* dst, const char* src, size_t n);