1
/* Copyright (c) 2007 SNAP Innovation GmbH
3
* BLOB Streaming for MySQL
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29
/* I must do this in order to get the BS config.h, which
30
* will give us the correct value for VERSION!
42
#include "CSStrUtil.h"
48
* A file name has the form:
49
* <text>-<number>[.<ext>]
50
* This function return the number part as a
53
u_int bs_file_to_table_id(const char *file_name, const char *name_part)
58
const char *num = file_name + strlen(file_name) - 1;
60
while (num >= file_name && *num != '-')
63
/* Check the name part of the file: */
64
int len = strlen(name_part);
66
if (len != num - file_name)
68
if (strncmp(file_name, name_part, len) != 0)
73
sscanf(num, "%lu", &value);
78
u_int bs_file_to_table_id(const char *file_name)
80
return bs_file_to_table_id(file_name, NULL);
83
const char *bs_file_to_table_name(size_t size, char *tab_name, const char *file_name)
88
file_name = cs_last_name_of_path(file_name);
89
cptr = file_name + strlen(file_name) - 1;
90
while (cptr > file_name && *cptr != '.')
92
if (cptr > file_name && *cptr == '.') {
93
if (strncmp(cptr, ".bs", 2) == 0) {
95
while (cptr > file_name && isdigit(*cptr))
101
len = cptr - file_name;
105
memcpy(tab_name, file_name, len);
108
/* Return a pointer to what was removed! */
109
return file_name + len;
112
bool bs_parse_blob_url(BSBlobURLPtr blob, const char *url, bool allow_old_urls)
114
const char *ptr = cs_last_name_of_path(url);
117
u_long auth_code = 0;
118
u_long server_id = 0;
124
if (strncmp(url, BS_URL_PREFIX, BS_URL_PREFIX_LEN) == 0) {
126
url += BS_URL_PREFIX_LEN;
130
else if (strncmp(url, BS_URL_NEW_PREFIX, BS_URL_PREFIX_LEN) == 0)
131
url += BS_URL_PREFIX_LEN;
132
else if (strncmp(url, BS_URL_ENC_PREFIX, BS_URL_ENC_PREFIX_LEN) == 0) {
134
url += BS_URL_ENC_PREFIX_LEN;
138
cs_strcpy(BS_DATABASE_NAME_SIZE, blob->bu_database, url, ptr - url - 1);
139
if (*ptr == '%' && *(ptr + 1) == '5' && *(ptr + 2) == 'E') {
141
sscanf(ptr, "%lu-%llu-%lx-%lu", &tab_id, &blob_id, &auth_code, &server_id);
142
type = BS_URL_NEW_TYPE_REPO;
144
else if (isdigit(*ptr)) {
145
sscanf(ptr, "%lu-%llu-%lx-%lu", &tab_id, &blob_id, &auth_code, &server_id);
146
type = BS_URL_NEW_TYPE_BLOB;
149
sscanf(ptr, "%c%lu-%llu-%lx-%lu", &type, &tab_id, &blob_id, &auth_code, &server_id);
151
case BS_URL_TYPE_BLOB:
152
type = BS_URL_NEW_TYPE_BLOB;
154
case BS_URL_TYPE_REPO:
155
type = BS_URL_NEW_TYPE_REPO;
157
case BS_URL_NEW_TYPE_BLOB:
158
case BS_URL_NEW_TYPE_REPO:
164
blob->bu_type = type;
165
blob->bu_tab_id = tab_id;
166
blob->bu_blob_id = blob_id;
167
blob->bu_auth_code = auth_code;
168
blob->bu_server_id = server_id;
169
return *blob->bu_database && tab_id && blob_id;
172
char buffer[CS_EXC_MESSAGE_SIZE];
174
cs_strcpy(CS_EXC_MESSAGE_SIZE, buffer, "Deprecated URL format: ");
175
cs_strcat(CS_EXC_MESSAGE_SIZE, buffer, url);
176
cs_strcat(CS_EXC_MESSAGE_SIZE, buffer, ", please update the URLs in this table using: UPDATE blob_table SET blob_col = REPLACE(REPLACE(blob_col, '~>', '~*'), '/:', '/~')");
177
CSException::throwException(CS_CONTEXT, BS_ERR_INCORRECT_URL, buffer);
180
const char *bs_version()