1
/* Copyright (C) 2005 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
18
#include <mysql_com.h>
21
Parse user value to user name and host name parts.
24
user_id_str [IN] User value string (the source).
25
user_id_len [IN] Length of the user value.
26
user_name_str [OUT] Buffer to store user name part.
27
Must be not less than USERNAME_LENGTH + 1.
28
user_name_len [OUT] A place to store length of the user name part.
29
host_name_str [OUT] Buffer to store host name part.
30
Must be not less than HOSTNAME_LENGTH + 1.
31
host_name_len [OUT] A place to store length of the host name part.
34
void parse_user(const char *user_id_str, size_t user_id_len,
35
char *user_name_str, size_t *user_name_len,
36
char *host_name_str, size_t *host_name_len)
38
char *p= strrchr(user_id_str, '@');
47
*user_name_len= p - user_id_str;
48
*host_name_len= user_id_len - *user_name_len - 1;
50
if (*user_name_len > USERNAME_LENGTH)
51
*user_name_len= USERNAME_LENGTH;
53
if (*host_name_len > HOSTNAME_LENGTH)
54
*host_name_len= HOSTNAME_LENGTH;
56
memcpy(user_name_str, user_id_str, *user_name_len);
57
memcpy(host_name_str, p + 1, *host_name_len);
60
user_name_str[*user_name_len]= 0;
61
host_name_str[*host_name_len]= 0;