Kod źródłowy bazserwer.c
#include <stdio.h>
#include <stdlib.h>
#include "bazara.h"
void __RPC_FAR * __RPC_USER midl_user_allocate( size_t len ) {
return malloc(len);
}
void __RPC_USER midl_user_free( void __RPC_FAR *ptr ) {
free(ptr);
}
void shut_down(void) {
printf("Odebrano polecenie SHUTDOWN\n");
RpcMgmtStopServerListening(NULL);
RpcServerUnregisterIf(NULL, NULL, FALSE);
}
results find_min(params par, double precision) {
double f;
double min_f = 999999.0;
double cur_x, cur_y, min_x, min_y;
results res;
cur_y = par.y1;
while (cur_y < par.y2)
{
printf("Biezacy y: %f\r",cur_y);
cur_x = par.x1;
while (cur_x < par.x2)
{
f = (cur_x-2)*(cur_x-2)*(cur_x-2)*(cur_x-2) +
(cur_x - 2*cur_y)*(cur_x - 2*cur_y);
if (f < min_f)
{
min_x = cur_x;
min_y = cur_y;
min_f = f;
}
cur_x += precision;
}
cur_y += precision;
}
printf("Minimum w (%f,%f), f=%f\n",min_x,min_y,min_f);
res.x = min_x;
res.y = min_y;
res.f = min_f;
return res;
}
int main() {
if (RpcServerRegisterAuthInfo("localhost",RPC_C_AUTHN_WINNT,NULL,NULL) != RPC_S_OK) {
printf("Nie powiodlo sie ustalenie metody autoryzacji.\n");
return 0;
}
RpcServerUseProtseqEp("ncacn_ip_tcp", 20, "9000", NULL);
RpcServerRegisterIf(minbazara_v1_0_s_ifspec, NULL, NULL);
printf("Serwer zarejestrowany.\n");
RpcServerListen(1, 20, FALSE);
return 0;
}
Kod źródłowy bazklient.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bazara.h"
#include "auth.h"
void __RPC_FAR * __RPC_USER midl_user_allocate( size_t len ) {
return malloc(len);
}
void __RPC_USER midl_user_free( void __RPC_FAR *ptr ) {
free(ptr);
}
int main(int argc, char **argv) {
params par;
results res;
double precision;
unsigned char *binding;
unsigned char shutdown = 0;
SEC_WINNT_AUTH_IDENTITY AuthIdentity;
RPC_STATUS retval;
if (argc < 2)
{
printf("Sposob uzycia: bazclient nazwa_hosta [shutdown]\n");
return 1;
}
if (RpcStringBindingCompose(NULL,
"ncacn_ip_tcp",
argv[1],
"9000",
NULL,
&binding) != RPC_S_OK) {
printf("Utworzenie lancucha dowiazania nie powiodlo sie.\n");
return 0;
}
printf("Lancuch dowiazania: %s\n", binding);
if (RpcBindingFromStringBinding(binding,
&minbazara_IfHandle) != RPC_S_OK) {
printf("Utworzenie dowiazania z lancucha nie powiodlo sie.\n");
return 0;
}
/* Dane autoryzacji */
AuthIdentity.User = USER;
AuthIdentity.UserLength = (unsigned long) strlen(USER);
AuthIdentity.Domain = DOMAIN;
AuthIdentity.DomainLength = (unsigned long) strlen(DOMAIN);
AuthIdentity.Password = PASSWORD;
AuthIdentity.PasswordLength = (unsigned long) strlen(PASSWORD);
AuthIdentity.Flags = SEC_WINNT_AUTH_IDENTITY_ANSI;
/* Koniec danych autoryzacji */
if (
(retval=RpcBindingSetAuthInfo(minbazara_IfHandle,
"localhost",
RPC_C_AUTHN_LEVEL_DEFAULT,
RPC_C_AUTHN_WINNT,
&AuthIdentity,
RPC_C_AUTHN_WINNT)) != RPC_S_OK) {
printf("Nie powiodlo sie ustalenie metody autoryzacji.\n");
switch (retval) {
case RPC_S_INVALID_BINDING:
printf("Dowiazanie jest niepoprawne.\n");break;
case RPC_S_UNKNOWN_AUTHN_SERVICE:
printf("Nieznana usluga autoryzacji.\n");break;
case RPC_S_WRONG_KIND_OF_BINDING:
printf("Niewlasciwy typ dowiazania.\n");break;
default:
printf("Nieznany blad: 0x%04x.\n",retval);break;
}
return 0;
}
printf("Binding przeprowadzony.\n");
if (argc == 3)
{
shutdown = 1;
} else {
printf("x1: ");
scanf("%lf", &(par.x1));
printf("y1: ");
scanf("%lf", &(par.y1));
printf("x2: ");
scanf("%lf", &(par.x2));
printf("y2: ");
scanf("%lf", &(par.y2));
printf("krok (dokladnosc): ");
scanf("%lf",&precision);
}
if (shutdown)
{
shut_down();
printf("Polecenie SHUTDOWN wyslane.\n");
} else
{
res = find_min(par, precision);
printf("Znaleziono minimum w (%lf, %lf), wartosc funkcji: %lf\n",
res.x, res.y, res.f);
}
RpcStringFree(&binding);
RpcBindingFree(&minbazara_IfHandle);
return 0;
}
Plik bazara.idl
[
uuid("02DD0802-9988-4071-86AD-3AC3506CF575"),
version(1.0)
]
interface minbazara {
typedef struct params {
double x1;
double y1;
double x2;
double y2;
} params;
typedef struct results {
double x;
double y;
double f;
} results;
struct results find_min( [in] params par, [in] double precision );
void shut_down( void );
}
Plik bazara.acf
[
implicit_handle(handle_t minbazara_IfHandle)
]
interface minbazara {
}
2