| 1 |
/********************************************************************* |
| 2 |
* |
| 3 |
* Authors: Vincenzo Ciaschini - [email protected] |
| 4 |
* |
| 5 |
* Copyright (c) Members of the EGEE Collaboration. 2004-2010. |
| 6 |
* See http://www.eu-egee.org/partners/ for details on the copyright holders. |
| 7 |
* |
| 8 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 |
* you may not use this file except in compliance with the License. |
| 10 |
* You may obtain a copy of the License at |
| 11 |
* |
| 12 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 13 |
* |
| 14 |
* Unless required by applicable law or agreed to in writing, software |
| 15 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 |
* See the License for the specific language governing permissions and |
| 18 |
* limitations under the License. |
| 19 |
* |
| 20 |
* Parts of this code may be based upon or even include verbatim pieces, |
| 21 |
* originally written by other people, in which case the original header |
| 22 |
* follows. |
| 23 |
* |
| 24 |
*********************************************************************/ |
| 25 |
#include "config.h" |
| 26 |
|
| 27 |
#include <string.h> |
| 28 |
#include <stdlib.h> |
| 29 |
|
| 30 |
#include "doio.h" |
| 31 |
|
| 32 |
static char *change(const char *str, char *from, char *to) |
| 33 |
{ |
| 34 |
char *copy = strdup(str); |
| 35 |
|
| 36 |
if (!copy) |
| 37 |
return NULL; |
| 38 |
|
| 39 |
char *pos = strstr(copy, from); |
| 40 |
char *tmp = NULL; |
| 41 |
|
| 42 |
while (pos) { |
| 43 |
*pos = '\0'; |
| 44 |
tmp = snprintf_wrap("%s%s%s", copy, to, pos + strlen(from)); |
| 45 |
if (tmp) { |
| 46 |
free(copy); |
| 47 |
copy = tmp; |
| 48 |
} |
| 49 |
pos = strstr(copy + strlen(to), from); |
| 50 |
} |
| 51 |
|
| 52 |
return copy; |
| 53 |
} |
| 54 |
|
| 55 |
char *normalize(const char *str) |
| 56 |
{ |
| 57 |
char *tmp = NULL; |
| 58 |
char *tmp2 = NULL; |
| 59 |
|
| 60 |
tmp = change(str, "/USERID=", "/UID="); |
| 61 |
tmp2 = change(tmp, "/emailAddress=", "/Email="); |
| 62 |
free(tmp); |
| 63 |
tmp = change(tmp2, "/E=", "/Email="); |
| 64 |
free(tmp2); |
| 65 |
return tmp; |
| 66 |
} |
| 67 |
|
| 68 |
#if 0 |
| 69 |
int main(int argc, char *argv) |
| 70 |
{ |
| 71 |
char *str1="/prova/Email=frge/CN=op"; |
| 72 |
char *str2="/prova/E=boh/emailAddress=mah/E=op/CN=fr"; |
| 73 |
char *str3="/USERID=56/mah"; |
| 74 |
|
| 75 |
char *n1 = normalize(str1); |
| 76 |
char *n2 = normalize(str2); |
| 77 |
char *n3 = normalize(str3); |
| 78 |
|
| 79 |
printf("%s -> %s\n", str1, n1); |
| 80 |
free(n1); |
| 81 |
printf("%s -> %s\n", str2, n2); |
| 82 |
free(n2); |
| 83 |
printf("%s -> %s\n", str3, n3); |
| 84 |
free(n3); |
| 85 |
|
| 86 |
exit(0); |
| 87 |
} |
| 88 |
|
| 89 |
#endif |