1
/* Copyright (c) 2008 PrimeBase Technologies GmbH, Germany
3
* PrimeBase Media Stream 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
19
* Original author: Paul McCullagh
20
* Continued development: Barry Leslie
30
/* I must do this in order to get the MS config.h, which
31
* will give us the correct value for VERSION!
44
#include "CSStrUtil.h"
46
#include "Engine_ms.h"
50
* A file name has the form:
51
* <text>-<number>[.<ext>]
52
* This function return the number part as a
55
uint32_t ms_file_to_table_id(const char *file_name, const char *name_part)
60
const char *num = file_name + strlen(file_name) - 1;
62
while (num >= file_name && *num != '-')
65
/* Check the name part of the file: */
66
int len = strlen(name_part);
68
if (len != num - file_name)
70
if (strncmp(file_name, name_part, len) != 0)
75
sscanf(num, "%"PRIu32"", &value);
80
uint32_t ms_file_to_table_id(const char *file_name)
82
return ms_file_to_table_id(file_name, NULL);
85
const char *ms_file_to_table_name(size_t size, char *tab_name, const char *file_name)
90
file_name = cs_last_name_of_path(file_name);
91
cptr = file_name + strlen(file_name) - 1;
92
while (cptr > file_name && *cptr != '.')
94
if (cptr > file_name && *cptr == '.') {
95
if (strncmp(cptr, ".bs", 2) == 0) {
97
while (cptr > file_name && isdigit(*cptr))
103
len = cptr - file_name;
107
memcpy(tab_name, file_name, len);
110
/* Return a pointer to what was removed! */
111
return file_name + len;
114
bool ms_parse_blob_url(MSBlobURLPtr blob, const char *url)
118
uint64_t blob_id = 0;
119
uint64_t blob_size = 0;
120
uint64_t blob_ref_id = 0;
121
uint32_t auth_code = 0;
122
uint32_t server_id = 0;
128
//If this changes do not forget to update couldBeURL in pbms.h.
129
scanned = sscanf(url, URL_FMT"%4s", &db_id, &type, &tab_id, &blob_id, &auth_code, &server_id, &blob_ref_id, &blob_size, junk);
130
if (scanned != 8) // If junk is found at the end this will also result in an invalid URL.
133
if (junk[0] || (type != MS_URL_TYPE_BLOB && type != MS_URL_TYPE_REPO))
136
blob->bu_type = type;
137
blob->bu_db_id = db_id;
138
blob->bu_tab_id = tab_id;
139
blob->bu_blob_id = blob_id;
140
blob->bu_auth_code = auth_code;
141
blob->bu_server_id = server_id;
142
blob->bu_blob_ref_id = blob_ref_id;
143
blob->bu_blob_size = blob_size;
144
return blob->bu_db_id && tab_id && blob_id;
147
void ms_build_blob_url(MSBlobURLPtr blob, char *url)
149
snprintf(url, PBMS_BLOB_URL_SIZE, URL_FMT, blob->bu_db_id,
155
blob->bu_blob_ref_id,
160
#define STR(x) _STR(x)
161
const char *ms_version()
163
return STR(PBMS_VERSION);